summary refs log tree commit diff
path: root/source/mod_student/parser.mly
diff options
context:
space:
mode:
authorPaweł Dybiec <pdybiec@stud.cs.uni.wroc.pl>2018-11-04 13:21:36 +0100
committerPaweł Dybiec <pdybiec@stud.cs.uni.wroc.pl>2018-11-04 13:21:36 +0100
commit86d0833fb238bcb63968e677d645f896da74fbc5 (patch)
tree083ce1d6c43260250b92ca11938077de99578930 /source/mod_student/parser.mly
parentAdd basic tokens + parse function name (diff)
parse function arguments
Diffstat (limited to 'source/mod_student/parser.mly')
-rw-r--r--source/mod_student/parser.mly22
1 files changed, 19 insertions, 3 deletions
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 <string>IDENTIFIER
 %token <char>CHAR
 %token <bool>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 }
 
 (*