From d8b0263cf9fc8819c2c016879ba23c0939b41201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Dybiec?= Date: Sun, 4 Nov 2018 15:07:47 +0100 Subject: Parse array dimensions --- source/mod_student/parser.mly | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/source/mod_student/parser.mly b/source/mod_student/parser.mly index 0fb4ee0..c031383 100644 --- a/source/mod_student/parser.mly +++ b/source/mod_student/parser.mly @@ -82,20 +82,22 @@ file: func: | id=identifier LPAREN parameters=list(argument) RPAREN - { GDECL_Function { loc=Location( {line=0;column=0;file=""}); + { GDECL_Function { loc=mkLocation $startpos; id=id;formal_parameters=parameters; return_types=[];body=None} } argument: | id = identifier COLON t=typ { VarDecl {loc=mkLocation $startpos;id=id;tp=t} } typ: | t=base_type { t } - | t=typ LSBRACKET option(INT) RSBRACKET + | t=typ LSBRACKET dim=option(expression) RSBRACKET { TEXPR_Array { loc=mkLocation $startpos; - sub=t;dim=None } } + sub=t;dim=dim } } base_type: | T_INT {TEXPR_Int {loc=mkLocation $startpos}} | T_BOOL {TEXPR_Bool {loc=mkLocation $startpos}} - +expression: + | value=INT { EXPR_Int {tag= mkTag ();loc=mkLocation $startpos; + value=Int32.of_int value} } identifier: | IDENTIFIER { Identifier $1 } -- cgit v1.2.3