123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- %{
- #include "asm_instructions.h"
- #include "symbol_table.h"
- #include "as.tab.h"
- #include "yacc_util.h"
- %}
-
- D [0-9]
-
- %%
-
- {D}+(e{D}+)? {
- yylval.nombre = atoi(yytext);
- return tNB;
- }
-
- "+" {
- yylval.instruction = ADD;
- return tADD;
- }
- "-" {
- yylval.instruction = SOU;
- return tSUB;
- }
- "*" {
- yylval.instruction = MUL;
- return tMUL;
- }
- "/" {
- yylval.instruction = DIV;
- return tDIV;
- }
- "=" { return tEQ; }
- "(" { return tPO; }
- ")" { return tPF; }
- ";" { return tPV; }
- "," { return tVIRG; }
- "{" { return tAO; }
- "}" { return tAF; }
- "==" {
- struct Condition* c = malloc(sizeof(struct Condition));
- c->instruction = EQU;
- c->not = 0;
- yylval.condition = c;
- return tEQ2;
- }
- "!=" {
- struct Condition* c = malloc(sizeof(struct Condition));
- c->instruction = EQU;
- c->not = 1;
- yylval.condition = c;
- return tNOTEQ;
- }
- "<" {
- struct Condition* c = malloc(sizeof(struct Condition));
- c->instruction = INF;
- c->not = 0;
- yylval.condition = c;
- return tINF;
- }
- "<=" {
- struct Condition* c = malloc(sizeof(struct Condition));
- c->instruction = SUP;
- c->not = 1;
- yylval.condition = c;
- return tINFEQ;
- }
- ">" {
- struct Condition* c = malloc(sizeof(struct Condition));
- c->instruction = SUP;
- c->not = 0;
- yylval.condition = c;
- return tSUP;
- }
- ">=" {
- struct Condition* c = malloc(sizeof(struct Condition));
- c->instruction = INF;
- c->not = 1;
- yylval.condition = c;
- return tSUPEQ;
- }
- "!" { return tNOT; }
- "&&" { return tAND; }
- "||" { return tOR; }
- [ \t\n]+ { }
-
- "int" { return tINT; }
- "const" { return tCONST; }
- "main" { return tMAIN; }
- "if" { return tIF; }
- "else" { return tELSE; }
- "elsif" { return tELSIF; }
- "while" { return tWHILE; }
- "printf" { return tPRINTF; }
- [a-zA-Z][a-zA-Z0-9_]* {
- yylval.symbol_name = malloc(sizeof(yytext));
- strcpy(yylval.symbol_name, yytext);
- return tID;
- }
-
- %%
-
- int yywrap() {
- return 1;
- }
- // int main () {
- // yylex();
- // return 1;
- // }
|