Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -Naur acse_1.1.1/acse/Acse.lex acse_cond_if/acse/Acse.lex
- --- acse_1.1.1/acse/Acse.lex 2016-02-02 23:05:13.000000000 +0100
- +++ acse_cond_if/acse/Acse.lex 2016-07-11 17:53:02.337505972 +0200
- @@ -93,6 +93,7 @@
- "else" { return ELSE; }
- "for" { return FOR; }
- "if" { return IF; }
- +"iif" { return IIF; }
- "int" { yylval.intval = INTEGER_TYPE; return TYPE; }
- "while" { return WHILE; }
- "return" { return RETURN; }
- diff -Naur acse_1.1.1/acse/Acse.y acse_cond_if/acse/Acse.y
- --- acse_1.1.1/acse/Acse.y 2016-02-02 23:05:13.000000000 +0100
- +++ acse_cond_if/acse/Acse.y 2016-07-11 17:54:24.987502323 +0200
- @@ -91,7 +91,7 @@
- %}
- -%expect 1
- +%expect 2
- /*=========================================================================
- SEMANTIC RECORDS
- @@ -124,7 +124,7 @@
- %token <label> DO
- %token <while_stmt> WHILE
- -%token <label> IF
- +%token <label> IF IIF
- %token <label> ELSE
- %token <intval> TYPE
- %token <svalue> IDENTIFIER
- @@ -134,6 +134,7 @@
- %type <decl> declaration
- %type <list> declaration_list
- %type <label> if_stmt
- +%type <label> init_if_stmt
- /*=========================================================================
- OPERATOR PRECEDENCES
- @@ -247,6 +248,7 @@
- ;
- control_statement : if_statement { /* does nothing */ }
- + | init_if_statement { }
- | while_statement { /* does nothing */ }
- | do_while_statement SEMI { /* does nothing */ }
- | return_statement SEMI { /* does nothing */ }
- @@ -303,7 +305,31 @@
- free($1);
- }
- ;
- -
- +
- +init_if_statement : init_if_stmt
- + {
- + /* fix the `label_else' */
- + assignLabel(program, $1);
- + }
- + | init_if_stmt ELSE
- + {
- + /* reserve a new label that points to the address where to jump if
- + * `exp' is verified */
- + $2 = newLabel(program);
- +
- + /* exit from the if-else */
- + gen_bt_instruction (program, $2, 0);
- +
- + /* fix the `label_else' */
- + assignLabel(program, $1);
- + }
- + code_block
- + {
- + /* fix the `label_else' */
- + assignLabel(program, $2);
- + }
- +
- +
- if_statement : if_stmt
- {
- /* fix the `label_else' */
- @@ -348,6 +374,22 @@
- code_block { $$ = $1; }
- ;
- +init_if_stmt : IIF LPAR assign_statement SEMI exp RPAR
- + {
- + if ($5.expression_type == IMMEDIATE)
- + gen_load_immediate(program, $5.value);
- + else
- + gen_andb_instruction(program, $5.value,
- + $5.value, $5.value, CG_DIRECT_ALL);
- +
- + $1 = newLabel(program);
- + /* if `exp' returns FALSE, jump to the label $1 */
- + gen_beq_instruction (program, $1, 0);
- + }
- + code_block { $$ = $1; }
- +;
- +
- +
- while_statement : WHILE
- {
- /* initialize the value of the non-terminal */
- diff -Naur acse_1.1.1/tests/iif_statement/test.axe acse_cond_if/tests/iif_statement/test.axe
- --- acse_1.1.1/tests/iif_statement/test.axe 1970-01-01 01:00:00.000000000 +0100
- +++ acse_cond_if/tests/iif_statement/test.axe 2016-07-11 17:57:31.985494065 +0200
- @@ -0,0 +1,7 @@
- +int i,j;
- +i=5;
- +j=7;
- +iif (i=i+2; j==i){
- + j = i;
- + write(i);
- +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement