adding optional else to executable semantics (#295)

* adding comments and some newlines

* added optonal else
This commit is contained in:
Jeremy G. Siek
2021-02-25 18:07:50 -05:00
committed by GitHub
parent a93ec369cb
commit 3ea84c9276
8 changed files with 584 additions and 2 deletions
+8 -2
View File
@@ -57,6 +57,7 @@ void yyerror(char* error) {
%type <function_definition> function_definition
%type <declaration_list> declaration_list
%type <statement> statement
%type <statement> optional_else
%type <statement_list> statement_list
%type <expression> expression
%type <expression> pattern
@@ -228,8 +229,8 @@ statement:
{ $$ = Carbon::MakeVarDef(yylineno, $2, $4); }
| expression ';'
{ $$ = Carbon::MakeExpStmt(yylineno, $1); }
| IF '(' expression ')' statement ELSE statement
{ $$ = Carbon::MakeIf(yylineno, $3, $5, $7); }
| IF '(' expression ')' statement optional_else
{ $$ = Carbon::MakeIf(yylineno, $3, $5, $6); }
| WHILE '(' expression ')' statement
{ $$ = Carbon::MakeWhile(yylineno, $3, $5); }
| BREAK ';'
@@ -243,6 +244,11 @@ statement:
| MATCH '(' expression ')' '{' clause_list '}'
{ $$ = Carbon::MakeMatch(yylineno, $3, $6); }
;
optional_else:
// Empty
{ $$ = 0; }
| ELSE statement { $$ = $2; }
;
statement_list:
// Empty
{ $$ = 0; }