Advertisement
SauriVeg

analizador.flex

Oct 30th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 2.21 KB | None | 0 0
  1. package compilador;
  2. import static compilador.Token.*;
  3. %%
  4. %class Lexer
  5. %type Token
  6. F = [int main()]
  7. L = [a-zA-Z][a-zA-Z0-9_]*
  8. D = [0-9]{1,9}
  9. E = ""
  10. COMENTARIO_multiLINEA=\"\"\"(\\.|[^\"\\])*\"\"\"
  11. COMENTARIO_LINEA="#".*
  12. NOMBRE_FUNCION="def ".*
  13. NOMBRE_CLASE="class ".*
  14. WHITE =[ \t\r\n]
  15. %{
  16. public String lexeme;
  17. %}
  18. %%
  19.  
  20. {WHITE} {/*Ignore*/}
  21. "+"|"-"|"*"|"/"|"**"|"//"|"%" {lexeme=yytext(); return OPERADOR_ARITMETICO;}
  22. "False"|"class"|"finally"|"is"|"return"|"None"|"continue"|"for"|"lambda"|"try"|"True"|"def"|"from"|"nonlocal"|"while"|"del"|"global"|"with"|"as"|"elif"|"if"|"yield"|"assert"|"else"|"import"|"pass"|"break"|"except"|"in"|"raise" {lexeme=yytext(); return PALABRA_RESERVADA;}
  23. "abs"|"delattr"|"hash"|"memoryview"|"set"|"all"|"dict"|"help"|"min"|"setattr"|"any"|"dir"|"hex"|"next"|"slice"|"ascii"|"divmod"|"id"|"object"|"sorted"|"bin"|"enumerate"|"input"|"oct"|"staticmethod"|"bool"|"eval"|"int"|"open"|"str"|"breakpoint"|"exec"|"isinstance"|"ord"|"sum"|"bytearray"|"filter"|"issubclass"|"pow"|"super"|"bytes"|"float"|"iter"|"print"|"tuple"|"callable"|"format"|"len"|"property"|"type"|"chr"|"frozenset"|"list"|"range"|"vars"|"classmethod"|"getattr"|"locals"|"repr"|"zip"|"compile"|"globals"|"map"|"reversed"|"__import__"|"complex"|"hasattr"|"max"|"round" {lexeme=yytext(); return FUNCION;}
  24. "&"|"|"|"^"|"~"|"<<"|">>" {lexeme=yytext(); return OPERADOR_BINARIO;}
  25. "<"|">"|"<="|">="|"=="|"!="|"<>" {lexeme=yytext(); return OPERADOR_RELACIONAL;}
  26. "and"|"or"|"not" {lexeme=yytext(); return OPERADOR_LOGICO;}
  27. {NOMBRE_FUNCION} {lexeme=yytext(); return DECLARACION_FUNCION;}
  28. {NOMBRE_CLASE} {lexeme=yytext(); return DECLARACION_CLASE;}
  29. "="|"+="|"-="|"*="|"/="|"**="|"**=" {lexeme=yytext(); return OPERADOR_ASIGNACION;}
  30. "(" {lexeme=yytext(); return ABRE_PARENTESIS;}
  31. \"(\\.|[^\"\\])*\" {lexeme=yytext(); return CADENA;}
  32. {COMENTARIO_multiLINEA}|{COMENTARIO_LINEA} {lexeme=yytext(); return COMENTARIO;}
  33. {L} {lexeme=yytext(); return VARIABLE;}
  34. {D} {lexeme=yytext(); return NUMERO_ENTERO;}
  35. {D}+"."{D} {lexeme=yytext(); return NUMERO_REAL;}
  36. ")" {lexeme=yytext(); return CIERRA_PARENTESIS;}
  37. "{" {lexeme=yytext(); return ABRE_LLAVES;}
  38. "}" {lexeme=yytext(); return CIERRA_LLAVES;}
  39. ";" {lexeme=yytext(); return FIN;}
  40. . {return ERROR;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement