Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. diff -Naur acse_1.1.1/acse/Acse.lex acse_cond_if/acse/Acse.lex
  2. --- acse_1.1.1/acse/Acse.lex 2016-02-02 23:05:13.000000000 +0100
  3. +++ acse_cond_if/acse/Acse.lex 2016-07-11 17:53:02.337505972 +0200
  4. @@ -93,6 +93,7 @@
  5. "else" { return ELSE; }
  6. "for" { return FOR; }
  7. "if" { return IF; }
  8. +"iif" { return IIF; }
  9. "int" { yylval.intval = INTEGER_TYPE; return TYPE; }
  10. "while" { return WHILE; }
  11. "return" { return RETURN; }
  12. diff -Naur acse_1.1.1/acse/Acse.y acse_cond_if/acse/Acse.y
  13. --- acse_1.1.1/acse/Acse.y 2016-02-02 23:05:13.000000000 +0100
  14. +++ acse_cond_if/acse/Acse.y 2016-07-11 17:54:24.987502323 +0200
  15. @@ -91,7 +91,7 @@
  16.  
  17. %}
  18.  
  19. -%expect 1
  20. +%expect 2
  21.  
  22. /*=========================================================================
  23. SEMANTIC RECORDS
  24. @@ -124,7 +124,7 @@
  25.  
  26. %token <label> DO
  27. %token <while_stmt> WHILE
  28. -%token <label> IF
  29. +%token <label> IF IIF
  30. %token <label> ELSE
  31. %token <intval> TYPE
  32. %token <svalue> IDENTIFIER
  33. @@ -134,6 +134,7 @@
  34. %type <decl> declaration
  35. %type <list> declaration_list
  36. %type <label> if_stmt
  37. +%type <label> init_if_stmt
  38.  
  39. /*=========================================================================
  40. OPERATOR PRECEDENCES
  41. @@ -247,6 +248,7 @@
  42. ;
  43.  
  44. control_statement : if_statement { /* does nothing */ }
  45. + | init_if_statement { }
  46. | while_statement { /* does nothing */ }
  47. | do_while_statement SEMI { /* does nothing */ }
  48. | return_statement SEMI { /* does nothing */ }
  49. @@ -303,7 +305,31 @@
  50. free($1);
  51. }
  52. ;
  53. -
  54. +
  55. +init_if_statement : init_if_stmt
  56. + {
  57. + /* fix the `label_else' */
  58. + assignLabel(program, $1);
  59. + }
  60. + | init_if_stmt ELSE
  61. + {
  62. + /* reserve a new label that points to the address where to jump if
  63. + * `exp' is verified */
  64. + $2 = newLabel(program);
  65. +
  66. + /* exit from the if-else */
  67. + gen_bt_instruction (program, $2, 0);
  68. +
  69. + /* fix the `label_else' */
  70. + assignLabel(program, $1);
  71. + }
  72. + code_block
  73. + {
  74. + /* fix the `label_else' */
  75. + assignLabel(program, $2);
  76. + }
  77. +
  78. +
  79. if_statement : if_stmt
  80. {
  81. /* fix the `label_else' */
  82. @@ -348,6 +374,22 @@
  83. code_block { $$ = $1; }
  84. ;
  85.  
  86. +init_if_stmt : IIF LPAR assign_statement SEMI exp RPAR
  87. + {
  88. + if ($5.expression_type == IMMEDIATE)
  89. + gen_load_immediate(program, $5.value);
  90. + else
  91. + gen_andb_instruction(program, $5.value,
  92. + $5.value, $5.value, CG_DIRECT_ALL);
  93. +
  94. + $1 = newLabel(program);
  95. + /* if `exp' returns FALSE, jump to the label $1 */
  96. + gen_beq_instruction (program, $1, 0);
  97. + }
  98. + code_block { $$ = $1; }
  99. +;
  100. +
  101. +
  102. while_statement : WHILE
  103. {
  104. /* initialize the value of the non-terminal */
  105. diff -Naur acse_1.1.1/tests/iif_statement/test.axe acse_cond_if/tests/iif_statement/test.axe
  106. --- acse_1.1.1/tests/iif_statement/test.axe 1970-01-01 01:00:00.000000000 +0100
  107. +++ acse_cond_if/tests/iif_statement/test.axe 2016-07-11 17:57:31.985494065 +0200
  108. @@ -0,0 +1,7 @@
  109. +int i,j;
  110. +i=5;
  111. +j=7;
  112. +iif (i=i+2; j==i){
  113. + j = i;
  114. + write(i);
  115. +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement