Ver Fonte

soft mul operator

Andrea Gussoni há 8 anos atrás
pai
commit
4ab1b105f8
3 ficheiros alterados com 10 adições e 2 exclusões
  1. 1 0
      acse/Acse.lex
  2. 5 2
      acse/Acse.y
  3. 4 0
      tests/test/test.src

+ 1 - 0
acse/Acse.lex

@@ -88,6 +88,7 @@ ID       [a-zA-Z_][a-zA-Z0-9_]*
 "&&"              { return ANDAND; }
 "||"              { return OROR; }
 ","               { return COMMA; }
+"[ * ]"           { return SOFT_MUL; }
 
 "do"              { return DO; }
 "else"            { return ELSE; }

+ 5 - 2
acse/Acse.y

@@ -112,7 +112,7 @@ t_io_infos *file_infos;    /* input and output files used by the compiler */
 %start program
 
 %token LBRACE RBRACE LPAR RPAR LSQUARE RSQUARE
-%token SEMI COLON PLUS MINUS MUL_OP DIV_OP MOD_OP
+%token SEMI COLON PLUS MINUS MUL_OP DIV_OP MOD_OP SOFT_MUL
 %token AND_OP OR_OP NOT_OP
 %token ASSIGN LT GT SHL_OP SHR_OP EQ NOTEQ LTEQ GTEQ
 %token ANDAND OROR
@@ -149,7 +149,7 @@ t_io_infos *file_infos;    /* input and output files used by the compiler */
 %left LT GT LTEQ GTEQ
 %left SHL_OP SHR_OP
 %left MINUS PLUS
-%left MUL_OP DIV_OP
+%left MUL_OP DIV_OP SOFT_MUL
 %right NOT
 
 /*=========================================================================
@@ -521,6 +521,9 @@ exp: NUMBER      { $$ = create_expression ($1, IMMEDIATE); }
    | exp MUL_OP exp     {
                            $$ = handle_bin_numeric_op(program, $1, $3, MUL);
    }
+   | exp SOFT_MUL exp   {
+                           $$ = create_expression(0, IMMEDIATE);
+   }
    | exp DIV_OP exp     {
                            $$ = handle_bin_numeric_op(program, $1, $3, DIV);
    }

+ 4 - 0
tests/test/test.src

@@ -0,0 +1,4 @@
+int a =1;
+int b =1;
+
+write(a [ * ] b);