diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/mod_student/parser.mly | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/source/mod_student/parser.mly b/source/mod_student/parser.mly index 2665861..4d1a142 100644 --- a/source/mod_student/parser.mly +++ b/source/mod_student/parser.mly @@ -195,11 +195,25 @@ statement: {STMT_VarDecl { var=var;init=init } } | WHILE cond=expression body=statement { STMT_While {loc=mkLocation $startpos;cond=cond;body=body } } - | IF cond=expression then_branch=statement else_branch=option(preceded(ELSE,statement)) (*Menhir attempts to mimic ocamlyacc’s specification, that is, to resolve shift/reduce conflicts in favor of shifting*) + | IF cond=expression then_branch=statement2 else_branch=option(preceded(ELSE,statement)) (*Menhir attempts to mimic ocamlyacc’s specification, that is, to resolve shift/reduce conflicts in favor of shifting*) { STMT_If {loc=mkLocation $startpos;cond=cond;then_branch=then_branch; else_branch=else_branch } } | head=option_var_decl COMMA tail=separated_nonempty_list(COMMA, option_var_decl) ASSIGN call=call { STMT_MultiVarDecl {loc=mkLocation $startpos; vars= head::tail; init=call } } +statement2: + | left=lvalue ASSIGN right=expression { STMT_Assign {loc=mkLocation $startpos; + lhs=left;rhs=right} } + | block=statement_block {STMT_Block block } + | call=call {STMT_Call call } + | var=var_decl init=option(preceded(ASSIGN,expression)) + {STMT_VarDecl { var=var;init=init } } + | WHILE cond=expression body=statement2 + { STMT_While {loc=mkLocation $startpos;cond=cond;body=body } } + | IF cond=expression then_branch=statement2 ELSE else_branch=statement2 + { STMT_If {loc=mkLocation $startpos;cond=cond;then_branch=then_branch; + else_branch=Some else_branch } } + | head=option_var_decl COMMA tail=separated_nonempty_list(COMMA, option_var_decl) ASSIGN call=call + { STMT_MultiVarDecl {loc=mkLocation $startpos; vars= head::tail; init=call } } return_stmt: | RETURN values=separated_list(COMMA,expression) { [STMT_Return { loc=mkLocation $startpos; values=values }] } |