12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- %{
- #include <stdio.h>
- #include "cross_instructions.h"
- int yylex();
- void yyerror(char*);
- int yydebug = 1;
- extern int yylineno;
-
- reg_instructions reg_array;
- %}
-
- /* Union for yylval */
- %union {
- int nb;
- }
-
- %token tADD tMUL tSOU tDIV tCOP tAFC
- %token <nb> tNB
-
- %%
-
- %start File;
-
- File:
- Instructions;
-
- Instructions:
- /* epsilon */
- | Instructions Instruction
- ;
-
- Instruction:
- tADD tNB tNB tNB
- {
- add_reg_oriented_instructions(®_array,LOAD, 1, $3, 0);
- add_reg_oriented_instructions(®_array,LOAD, 2, $4, 0);
- add_reg_oriented_instructions(®_array,ADD, 3, 1, 2);
- add_reg_oriented_instructions(®_array,STORE, $2, 3, 0);
- }
- | tMUL tNB tNB tNB
- {
- add_reg_oriented_instructions(®_array,LOAD, 1, $3, 0);
- add_reg_oriented_instructions(®_array,LOAD, 2, $4, 0);
- add_reg_oriented_instructions(®_array,MUL, 3, 1, 2);
- add_reg_oriented_instructions(®_array,STORE, $2, 3, 0);
- }
- | tSOU tNB tNB tNB
- {
- add_reg_oriented_instructions(®_array,LOAD, 1, $3, 0);
- add_reg_oriented_instructions(®_array,LOAD, 2, $4, 0);
- add_reg_oriented_instructions(®_array,SOU, 3, 1, 2);
- add_reg_oriented_instructions(®_array,STORE, $2, 3, 0);
- }
- | tDIV tNB tNB tNB
- {
- add_reg_oriented_instructions(®_array,LOAD, 1, $3, 0);
- add_reg_oriented_instructions(®_array,LOAD, 2, $4, 0);
- add_reg_oriented_instructions(®_array,DIV, 3, 1, 2);
- add_reg_oriented_instructions(®_array,STORE, $2, 3, 0);
- }
- | tCOP tNB tNB
- {
- add_reg_oriented_instructions(®_array,LOAD, 1, $3, 0);
- add_reg_oriented_instructions(®_array,STORE, $2, 1, 0);
- }
- | tAFC tNB tNB
- {
- add_reg_oriented_instructions(®_array,AFC, 1, $3, 0);
- add_reg_oriented_instructions(®_array,STORE, $2, 1, 0);
- }
- ;
-
-
- %%
-
- void yyerror(char* str) {
- extern int yylineno;
- fprintf(stderr, "ERROR yyparse : Line %d: %s\n", yylineno, str);
- }
-
- int main(int argc, char *argv[]) {
- init_reg_oriented_instructions(®_array);
- yyparse();
- printf("INFO yyparse : Parsing End\n");
- output_reg_oriented_instructions(®_array);
- return 0;
- }
|