7 #include "symbol_table.h"
9 /*extern char *yytext;*/
12 static void yyerror (/*YYLTYPE *locp, */const char *msg
);
13 /*int yylex (YYSTYPE *yylval_param, YYLTYPE *yylloc_param);*/
21 /*%parse-param {ValaParser *parser}
22 %lex-param {ValaParser *parser}*/
30 struct AstNode
*astnode
;
75 %token
<type
> TYPE_IDENTIFIER
76 %token
<lexeme
> IDENTIFIER
77 %token
<integer
> INT_LITERAL
78 %token
<boolean
> BOOL_LITERAL
79 %token
<character
> CHAR_LITERAL
81 %type
<astnode
> Program
82 %type
<astnode
> VarDeclList
83 %type
<astnode
> VarDecl
84 %type
<astnode
> ProcFuncList
85 %type
<astnode
> MainCodeBlock
86 %type
<astnode
> CodeBlock
88 %type
<astnode
> Assignment
89 %type
<astnode
> Identifier
90 %type
<astnode
> SimpleType
91 %type
<astnode
> Literal
97 VarDeclList ProcFuncList MainCodeBlock
99 struct AstNode
*ast_node
;
100 ast_node
= ast_node_new
("Program", -1, -1,
101 yylloc.last_line
, NULL
);
102 ast_node
->children
[0] = $1;
103 ast_node
->children
[1] = $2;
104 ast_node
->children
[2] = $3;
107 //ast_node_print(ast_node);
108 //symbol_table_dump(sym_table);
109 //ast_node_print_graph(ast_node);
114 /* empty */ { $$
= NULL
; }
115 | VarDeclList VarDecl
117 ((struct AstNode
*) $2)->next
= (struct AstNode
*) $1;
123 T_VAR Identifier T_COLON SimpleType T_SEMICOLON
125 struct AstNode
*ast_node
;
126 ast_node
= ast_node_new
("VarDecl", -1, -1,
127 yylloc.last_line
, NULL
);
128 ast_node
->children
[0] = $2;
129 //ast_node->children[1] = $4;
135 /* empty */ { $$
= NULL
; }
139 /* empty */ { $$
= NULL
; }
140 | CodeBlock T_DOT
{ $$
= $1; }
144 T_BEGIN Assignment T_END
151 Identifier T_ASSIGNMENT Literal T_SEMICOLON
153 struct AstNode
*ast_node
;
154 ast_node
= ast_node_new
("Assignment", -1, -1,
155 yylloc.last_line
, NULL
);
156 ast_node
->children
[0] = $1;
157 ast_node
->children
[1] = $3;
166 struct AstNode
*ast_node
;
167 ast_node
= ast_node_new
("SimpleType", -1, -1,
168 yylloc.last_line
, NULL
);
169 //ast_node->children[0] = $2;
170 //ast_node->children[1] = $4;
179 struct AstNode
*ast_node
;
181 sym_table
= symbol_insert
(sym_table
, $1);
184 ast_node
= ast_node_new
("Identifier", -1, -1,
185 yylloc.last_line
, NULL
);
193 struct AstNode
*ast_node
;
194 ast_node
= ast_node_new
("Literal", INT_LITERAL
, INTEGER
,
195 yylloc.last_line
, NULL
);
196 value_set_from_int
(&ast_node
->value
, $1);
201 struct AstNode
*ast_node
;
202 ast_node
= ast_node_new
("Literal", BOOL_LITERAL
, BOOLEAN
,
203 yylloc.last_line
, NULL
);
204 value_set_from_int
(&ast_node
->value
, $1);
209 struct AstNode
*ast_node
;
210 ast_node
= ast_node_new
("Literal", CHAR_LITERAL
, CHAR
,
211 yylloc.last_line
, NULL
);
212 value_set_from_int
(&ast_node
->value
, $1);
220 yyerror (/*YYLTYPE *locp,*/ const char *msg
)
222 fprintf
(stderr
,"error: %s\n", msg
);
226 main
(int argc
, char **argv
)
229 yyin
= fopen
(argv
[1], "r");
233 /*yylloc.first_line = yylloc.last_line = 1;
234 yylloc.first_column = yylloc.last_column = 0;*/