9
9
node *node;
10
10
}
11
11
12
- %type <val> value_literal object_literal array_literal
12
+ %type <val> value_literal object_literal array_literal type_specifier
13
13
%type <node> script statements statement scope
14
14
if_statement for_statement jump_statement while_statement do_while_statement expression_statement
15
15
expression primary_expression assignment_expression conditional_expression postfix_expression
@@ -138,7 +138,7 @@ object_key
138
138
;
139
139
140
140
primary_expression
141
- : IDENTIFIER { $$ = identifier_node($1); }
141
+ : IDENTIFIER { $$ = identifier_node($1, 1 ); }
142
142
| value_literal { $$ = literal_node($1); }
143
143
| array_literal { $$ = literal_node($1); }
144
144
| object_literal { $$ = literal_node($1); }
@@ -239,7 +239,7 @@ statement
239
239
| switch_statement
240
240
| jump_statement
241
241
| declaration
242
- | STRICT_MODE { debug("strict mode enabled", ""); }
242
+ | STRICT_MODE { strict_mode = 1; debug("strict mode enabled", ""); }
243
243
;
244
244
245
245
expression_statement
@@ -303,18 +303,18 @@ declaration
303
303
;
304
304
305
305
variable_declaration
306
- : type_specifier IDENTIFIER { $$ = identifier_node($2); debug("variable declaration", $2); }
306
+ : type_specifier IDENTIFIER { $$ = identifier_node($2, !strcmp($1, "const") ); debug("variable declaration", $2); }
307
307
| type_specifier IDENTIFIER ASSIGN expression {
308
- $$ = identifier_node($2);
308
+ $$ = identifier_node($2, strcmp($1, "const") );
309
309
debug("variable declaration with value", $2);
310
310
$$->child = $4;
311
311
}
312
312
;
313
313
314
314
type_specifier
315
- : VAR
316
- | LET
317
- | CONST
315
+ : VAR { $$ = strdup("var"); }
316
+ | LET { $$ = strdup("let"); }
317
+ | CONST { $$ = strdup("const"); }
318
318
;
319
319
320
320
assignment_operator
@@ -328,9 +328,9 @@ assignment_operator
328
328
329
329
parameters
330
330
: /* None */ { $$ = NULL; debug("empty function parameter", ""); }
331
- | IDENTIFIER { $$ = identifier_node($1); debug("function parameter", $1); }
331
+ | IDENTIFIER { $$ = identifier_node($1, 1 ); debug("function parameter", $1); }
332
332
| parameters IDENTIFIER {
333
- $$ = sibling_node($1, identifier_node($2));
333
+ $$ = sibling_node($1, identifier_node($2, 1 ));
334
334
}
335
335
;
336
336
0 commit comments