1 /* This file contains the description of the 'as_table' parser.
2 * It transforms every entry into a C-funtion, for example :
4 * and dst:REG, src:EADDR ==> @text1( 0x23);
5 * mod_RM( dst->reg, src).
7 * ... dst:ACCU, src:DATA ==> @text1( 0x25);
11 * Will be transformed into :
13 * and_instr( dst, src)
14 * struct t_operand *dst, *src;
16 * if ( REG( dst) && EADDR( src)) {
18 * fprint( outfile, "text1( 0x23)");
19 * fprint( outfile, ";");
20 * mod_RM( dst->reg, src);
22 * else if ( ACCU( dst) && DATA( src)) {
24 * fprint( outfile, "text1( 0x25)");
25 * fprint( outfile, ";");
27 * fprint( outfile, "text2( ");
29 * fprint( outfile, ")");
30 * fprint( outfile, ";");
33 * error( "No match for and");
36 * At the end of the table a list is generated enumerating all the assembler
37 * mnemonics and their corresponding function names.
43 extern int lineno, yyleng;
52 %token IDENTIFIER, CALL, CONDITION, IF, ELSIF, ELSE, FI, ARROW, MORE;
54 %lexical lex_analyzer ;
57 table : { init_table();}
58 instruction* { end_table();}
61 instruction : { clean();}
65 ]* { pr_warning(); out( "}\n\n");}
68 first_row : mnemonic { save_instr( yytext, yyleng);}
70 ARROW { pr_header(); pr_restriction();}
76 ARROW { out( "else "); pr_restriction();}
83 decl_list : { clear_restriction();}
88 declaration : IDENTIFIER { save_name( yytext, yyleng);}
90 IDENTIFIER { save_type( yytext, yyleng);}
94 action_list : { out( "{\n");}
95 [ action [ ';' action]* ]? '.' { out( "}\n");}
103 /* A function call is just an identifier followed by an expression surrounded
104 * by '(' and ')'. CONDITION is a token that matches this construct;
108 { char *s; } : IDENTIFIER { s = Salloc(yytext, yyleng+1); }
109 CONDITION { s = Realloc(s, strlen(s)+yyleng+1);
118 IDENTIFIER { s = Salloc(yytext, yyleng+1); }
119 CONDITION { s = Realloc(s, strlen(s)+yyleng+1);
127 CONDITION { pr_question( yytext);}
128 action_list { pr_end();}
130 CONDITION { pr_question( yytext);}
131 action_list { pr_end();}
134 action_list { pr_end();}
142 static int saved = 0, token;
145 LLmessage( inserted_token)
149 if ( inserted_token == 0) {
150 fprint( STDERR, "Sytax error in line %d, ", lineno);
151 print_token( LLsymb);
152 fprint( STDERR, " will be deleted!!\n");
154 else if ( inserted_token < 0) {
155 fprint( STDERR, "Garbage at end, line %d!!\n",
159 fprint( STDERR, "Sytax error in line %d, ", lineno);
160 print_token( inserted_token);
161 fprint( STDERR, " will be inserted!!\n");
171 case IDENTIFIER : fprint( STDERR, "IDENTIFIER %s", yytext);
173 case CALL : fprint( STDERR, "CALL %s", yytext);
175 case CONDITION: fprint( STDERR, "CONDITION %s", yytext);
177 case IF : fprint( STDERR, "@if ");
179 case ELSIF : fprint( STDERR, "@elsif ");
181 case ELSE : fprint( STDERR, "@else ");
183 case FI : fprint( STDERR, "@fi ");
185 case ARROW : fprint( STDERR, "==> ");
187 case MORE : fprint( STDERR, "... ");
189 default : fprint( STDERR, "%c ", token);
204 yytext[yyleng] = '\0'; /* strings must end with '\0' */