Browse Source

implemented merge

Andrea Gussoni 8 years ago
parent
commit
37a4c559a9
3 changed files with 21 additions and 0 deletions
  1. 1 0
      acse/Acse.lex
  2. 11 0
      acse/Acse.y
  3. 9 0
      tests/merge/merge.src

+ 1 - 0
acse/Acse.lex

@@ -98,6 +98,7 @@ ID       [a-zA-Z_][a-zA-Z0-9_]*
 "return"          { return RETURN; }
 "read"            { return READ; }
 "write"           { return WRITE; }
+"merge"           { return MERGE; }
 
 {ID}              { yylval.svalue=strdup(yytext); return IDENTIFIER; }
 {DIGIT}+          { yylval.intval = atoi( yytext );

+ 11 - 0
acse/Acse.y

@@ -121,6 +121,7 @@ t_io_infos *file_infos;    /* input and output files used by the compiler */
 %token RETURN
 %token READ
 %token WRITE
+%token MERGE
 
 %token <label> DO
 %token <while_stmt> WHILE
@@ -141,6 +142,7 @@ t_io_infos *file_infos;    /* input and output files used by the compiler */
 
 %left COMMA
 %left ASSIGN
+%left MERGE
 %left OROR
 %left ANDAND
 %left OR_OP
@@ -565,6 +567,15 @@ exp: NUMBER      { $$ = create_expression ($1, IMMEDIATE); }
                                  (program, exp_r0, $2, SUB);
                         }
                      }
+   | MERGE exp COMMA exp COMMA exp
+    {
+        t_axe_expression tmp = handle_bin_numeric_op(program, $2, $6, MUL);
+        t_axe_expression zero = create_expression(0, IMMEDIATE);
+        t_axe_expression inv = handle_binary_comparison(program, $6, zero, 
+                                                        _EQ_);
+        t_axe_expression tmp2 = handle_bin_numeric_op(program, $4, inv, MUL);
+        $$ = handle_bin_numeric_op(program, tmp, tmp2, ORB);                                
+    }
 ;
 
 %%

+ 9 - 0
tests/merge/merge.src

@@ -0,0 +1,9 @@
+int a, b, c;
+a = 7;
+b = 2;
+
+c = merge a, b, a > b;
+write(c);
+
+c = merge 2, 3, 0;
+write(c);