le compilateur super performant
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

al.lex 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. %{
  2. #include "asm_instructions.h"
  3. #include "symbol_table.h"
  4. #include "as.tab.h"
  5. #include "yacc_util.h"
  6. %}
  7. D [0-9]
  8. %%
  9. {D}+(e{D}+)? {
  10. yylval.nombre = atoi(yytext);
  11. return tNB;
  12. }
  13. "+" {
  14. yylval.instruction = ADD;
  15. return tADD;
  16. }
  17. "-" {
  18. yylval.instruction = SOU;
  19. return tSUB;
  20. }
  21. "*" {
  22. yylval.instruction = MUL;
  23. return tMUL;
  24. }
  25. "/" {
  26. yylval.instruction = DIV;
  27. return tDIV;
  28. }
  29. "=" { return tEQ; }
  30. "(" { return tPO; }
  31. ")" { return tPF; }
  32. ";" { return tPV; }
  33. "," { return tVIRG; }
  34. "{" { return tAO; }
  35. "}" { return tAF; }
  36. "==" {
  37. struct Condition* c = malloc(sizeof(struct Condition));
  38. c->instruction = EQU;
  39. c->not = 0;
  40. yylval.condition = c;
  41. return tEQ2;
  42. }
  43. "!=" {
  44. struct Condition* c = malloc(sizeof(struct Condition));
  45. c->instruction = EQU;
  46. c->not = 1;
  47. yylval.condition = c;
  48. return tNOTEQ;
  49. }
  50. "<" {
  51. struct Condition* c = malloc(sizeof(struct Condition));
  52. c->instruction = INF;
  53. c->not = 0;
  54. yylval.condition = c;
  55. return tINF;
  56. }
  57. "<=" {
  58. struct Condition* c = malloc(sizeof(struct Condition));
  59. c->instruction = SUP;
  60. c->not = 1;
  61. yylval.condition = c;
  62. return tINFEQ;
  63. }
  64. ">" {
  65. struct Condition* c = malloc(sizeof(struct Condition));
  66. c->instruction = SUP;
  67. c->not = 0;
  68. yylval.condition = c;
  69. return tSUP;
  70. }
  71. ">=" {
  72. struct Condition* c = malloc(sizeof(struct Condition));
  73. c->instruction = INF;
  74. c->not = 1;
  75. yylval.condition = c;
  76. return tSUPEQ;
  77. }
  78. "!" { return tNOT; }
  79. "&&" { return tAND; }
  80. "||" { return tOR; }
  81. [ \t\n]+ { }
  82. "int" { return tINT; }
  83. "const" { return tCONST; }
  84. "main" { return tMAIN; }
  85. "if" { return tIF; }
  86. "else" { return tELSE; }
  87. "elsif" { return tELSIF; }
  88. "while" { return tWHILE; }
  89. "printf" { return tPRINTF; }
  90. [a-zA-Z][a-zA-Z0-9_]* {
  91. yylval.symbol_name = malloc(sizeof(yytext));
  92. strcpy(yylval.symbol_name, yytext);
  93. return tID;
  94. }
  95. %%
  96. int yywrap() {
  97. return 1;
  98. }
  99. // int main () {
  100. // yylex();
  101. // return 1;
  102. // }