109 lines
2.5 KiB
Text
109 lines
2.5 KiB
Text
%{
|
|
#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;
|
|
// }
|