1. Paweł Wieczorek
  2. Opifex

Commits

Paweł Wieczorek  committed dcd2125

Added routine calling in aexprs in while, also fixed parser

  • Participants
  • Parent commits 75823de
  • Branches very_simple_while_compiler

Comments (0)

Files changed (1)

File source/Lang/While/Parser.mly

View file
     { Variable $1 }
     ;
 
+routine_call
+    : identifier LPARENT RPARENT
+    { ($1, [] ) }
+
+    | identifier LPARENT argument_list RPARENT
+    { ($1, $3 ) }
+    ;
+
 arithmetic_expression_basic
     : INT
     { AE_Constant $1 }
     | variable
     { AE_Variable $1 }
 
+    | routine_call
+    { AE_Call (fst $1, snd $1) }
+
     | LPARENT arithmetic_expression RPARENT
     { $2 }
     ;
     | FALSE
     { BE_Constant false }
 
-    | RPARENT boolean_expression LPARENT
+    | LPARENT boolean_expression RPARENT
     { $2 }
     ;
 
-arithmetic_expression
+multiplicative_arithmetic_expression
     : arithmetic_expression_basic
     { $1 }
 
-    | arithmetic_expression arithmetic_binary_operator arithmetic_expression_basic
+    | multiplicative_arithmetic_expression multiplicative_arithmetic_binary_operator arithmetic_expression_basic
     { AE_BinaryOperator ($2, $1, $3) }
     ;
 
+additive_arithmetic_expression
+    : multiplicative_arithmetic_expression 
+    { $1 }
+
+
+    | additive_arithmetic_expression additive_arithmetic_binary_operator multiplicative_arithmetic_expression
+    { AE_BinaryOperator ($2, $1, $3) }
+    ;
+
+arithmetic_expression
+    : additive_arithmetic_expression {$1}
+    ;
 
 boolean_expression
     : boolean_expression_basic
     { BE_ArithmeticBinaryOperator ($2, $1, $3) }
     ;
 
-arithmetic_binary_operator
+additive_arithmetic_binary_operator
     : OP_ADD
     { AOP_ADD }
 
     | OP_SUB
     { AOP_SUB }
+    ;
 
-    | OP_MUL
+multiplicative_arithmetic_binary_operator
+    : OP_MUL
     { AOP_MUL }
 
     | OP_DIV 
     { BOP_OR }
     ;
 
-/*
+
 boolean_unary_operator
     : OP_NOT
     { BOP_NOT }
     ;
-*/
+
 
 boolean_arithmetic_binary_operator
     : OP_LT
     | THROW identifier
     { CMD_Throw $2 }
 
-    | identifier LPARENT argument_list RPARENT
-    { CMD_Call ($1, $3) }
-
-    | identifier LPARENT RPARENT
-    { CMD_Call ($1, []) }
+    | routine_call
+    { CMD_Call (fst $1, snd $1) }
 
     | RETURN arithmetic_expression
     { CMD_Return $2 }
     ;
 
-
 guarded_commands
     : LPARENT boolean_expression RPARENT
         commands
     { ($2, $4) }
     ;
 
-/*
-if_sequence
-    : IF guarded_commands
-      elif_sequence
-      ELSE commands 
-    { compute_ifs $5 ($2 :: $3) }
-    ;
+
+command_control
+    : command_basic
+    { $1 }
 
     | IF guarded_commands
-      elif_sequence
-    { compute_ifs CMD_Skip ($2 :: $3) }
-    ;
-
-elif_sequence
-    : ELIF guarded_commands
-      elif_sequence
-    { $2 :: $3 }
-
-    |
-    { [] }
-
-*/
-
-command_control
-    : IF guarded_commands
     {  let (cond, then_cmds) = $2
     in CMD_If (cond, then_cmds, CMD_Skip) }
 
     {  let (cond, then_cmds) = $2
     in CMD_If (cond, then_cmds, $4) }
 
-    | command_basic
-    { $1 }
 
     | WHILE LPARENT boolean_expression RPARENT
         commands
     { CMD_While ($3, $5) }
-    ;
 
     | TRY commands CATCH identifier commands
     { CMD_Try ($2, $4, $5) }
+    ;
 
 
 declaration
     : PROCEDURE identifier LPARENT RPARENT
         commands 
-    { DECL_Procedure ($2, $5) }
+    { DECL_Procedure ($2, $5) } 
 
 declarations
     : declaration 
     : declarations 
     { PROGRAM $1 }
 
+
 parse
     : program EOF
-    { $1 }
-
+    { raise Exit }
 %%