comparison Bison-Flex/Compiler-StackBase/UTF8/script-parser.yy @ 5:caede627f691

chage encoding
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 17 May 2011 12:45:07 +0900
parents 805d39d28230
children 86c0a38332fe
comparison
equal deleted inserted replaced
4:805d39d28230 5:caede627f691
12 class compiler; 12 class compiler;
13 %} 13 %}
14 %parse-param { compiler& driver } 14 %parse-param { compiler& driver }
15 %lex-param { compiler& driver } 15 %lex-param { compiler& driver }
16 %locations 16 %locations
17 %expect 1 /* if文で衝突が発生するので、1つの衝突は無視 */ 17 %expect 1 /* ifц腦榊с鐚ゃ茵腦∴ */
18 %initial-action 18 %initial-action
19 { 19 {
20 // ロケーション初期化 20 // 宴若激с喝
21 @$.begin.filename = @$.end.filename = &driver.get_filename(); 21 @$.begin.filename = @$.end.filename = &driver.get_filename();
22 } ; 22 } ;
23 // %debug 23 // %debug
24 %error-verbose 24 %error-verbose
25 // Symbols. 25 // Symbols.
73 %token TK_BREAK "break" 73 %token TK_BREAK "break"
74 %token TK_RETURN "return" 74 %token TK_RETURN "return"
75 %token TK_INTEGER "int" 75 %token TK_INTEGER "int"
76 %token TK_STRING "string" 76 %token TK_STRING "string"
77 %token TK_VOID "void" 77 %token TK_VOID "void"
78 %token TK_CODE "__code"
78 79
79 %type <expr> expr 80 %type <expr> expr
80 %type <value> value 81 %type <value> value
81 %type <assign> assign 82 %type <assign> assign
82 %type <value_list> value_list 83 %type <value_list> value_list
127 declaration : type value_list ';' { driver.DefineValue(@2, $1, $2); } 128 declaration : type value_list ';' { driver.DefineValue(@2, $1, $2); }
128 | type "identifier" '(' ')' ';' { driver.DefineFunction(@2, $1, $2, NULL); } 129 | type "identifier" '(' ')' ';' { driver.DefineFunction(@2, $1, $2, NULL); }
129 | type "identifier" '(' arglist ')' ';' { driver.DefineFunction(@2, $1, $2, $4); } 130 | type "identifier" '(' arglist ')' ';' { driver.DefineFunction(@2, $1, $2, $4); }
130 | "void" "identifier" '(' ')' ';' { driver.DefineFunction(@2, TYPE_VOID, $2, NULL); } 131 | "void" "identifier" '(' ')' ';' { driver.DefineFunction(@2, TYPE_VOID, $2, NULL); }
131 | "void" "identifier" '(' arglist ')' ';' { driver.DefineFunction(@2, TYPE_VOID, $2, $4); } 132 | "void" "identifier" '(' arglist ')' ';' { driver.DefineFunction(@2, TYPE_VOID, $2, $4); }
133 | "__code" "identifier" '(' ')' ';' { driver.DefineFunction(@2, TYPE_CODE, $2, NULL); }
134 | "__code" "identifier" '(' arglist ')' ';' { driver.DefineFunction(@2, TYPE_CODE, $2, $4); }
132 ; 135 ;
133 136
134 value_list : value { $$ = new CValueList($1); } 137 value_list : value { $$ = new CValueList($1); }
135 | value_list ',' value { $$ = $1->Add($3); } 138 | value_list ',' value { $$ = $1->Add($3); }
136 ; 139 ;
149 152
150 function : type "identifier" '(' ')' block { driver.AddFunction(@1, $1, $2, NULL, $5); } 153 function : type "identifier" '(' ')' block { driver.AddFunction(@1, $1, $2, NULL, $5); }
151 | type "identifier" '(' arglist ')' block { driver.AddFunction(@1, $1, $2, $4, $6); } 154 | type "identifier" '(' arglist ')' block { driver.AddFunction(@1, $1, $2, $4, $6); }
152 | "void" "identifier" '(' ')' block { driver.AddFunction(@1, TYPE_VOID, $2, NULL, $5); } 155 | "void" "identifier" '(' ')' block { driver.AddFunction(@1, TYPE_VOID, $2, NULL, $5); }
153 | "void" "identifier" '(' arglist ')' block { driver.AddFunction(@1, TYPE_VOID, $2, $4, $6); } 156 | "void" "identifier" '(' arglist ')' block { driver.AddFunction(@1, TYPE_VOID, $2, $4, $6); }
157 | "__code" "identifier" '(' ')' block { driver.AddGotoFunction(@1, TYPE_CODE, $2, NULL, $5); }
158 | "__code" "identifier" '(' arglist ')' block { driver.AddGotoFunction(@1, TYPE_CODE, $2, $4, $6); }
154 ; 159 ;
155 160
156 type : "int" { $$ = TYPE_INTEGER; } 161 type : "int" { $$ = TYPE_INTEGER; }
157 | "string" { $$ = TYPE_STRING; } 162 | "string" { $$ = TYPE_STRING; }
158 ; 163 ;