From 86d0833fb238bcb63968e677d645f896da74fbc5 Mon Sep 17 00:00:00 2001 From: Paweł Dybiec Date: Sun, 4 Nov 2018 13:21:36 +0100 Subject: parse function arguments --- source/mod_student/parser.mly | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'source/mod_student/parser.mly') diff --git a/source/mod_student/parser.mly b/source/mod_student/parser.mly index 4889d11..0fb4ee0 100644 --- a/source/mod_student/parser.mly +++ b/source/mod_student/parser.mly @@ -34,6 +34,8 @@ let mkTag = %token RPAREN %token LBRACKET %token RBRACKET +%token LSBRACKET +%token RSBRACKET %token COLON %token OP_PLUS %token OP_MINUS @@ -58,6 +60,8 @@ let mkTag = %token IDENTIFIER %token CHAR %token BOOL +%token T_BOOL +%token T_INT (* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ----------------------------------------------------------------------------- *) @@ -77,11 +81,23 @@ file: { ModuleDefinition {global_declarations=[] } } func: - | id=identifier LPAREN RPAREN + | id=identifier LPAREN parameters=list(argument) RPAREN { GDECL_Function { loc=Location( {line=0;column=0;file=""}); - id=id;formal_parameters=[]; return_types=[];body=None} } + 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 + { TEXPR_Array { loc=mkLocation $startpos; + sub=t;dim=None } } +base_type: + | T_INT {TEXPR_Int {loc=mkLocation $startpos}} + | T_BOOL {TEXPR_Bool {loc=mkLocation $startpos}} + identifier: - | IDENTIFIER + | IDENTIFIER { Identifier $1 } (* -- cgit 1.4.1