Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package compilador;
- import static compilador.Token.*;
- %%
- %class Lexer
- %type Token
- F = [int main()]
- L = [a-zA-Z][a-zA-Z0-9_]*
- D = [0-9]{1,9}
- E = ""
- COMENTARIO_multiLINEA=\"\"\"(\\.|[^\"\\])*\"\"\"
- COMENTARIO_LINEA="#".*
- NOMBRE_FUNCION="def ".*
- NOMBRE_CLASE="class ".*
- WHITE =[ \t\r\n]
- %{
- public String lexeme;
- %}
- %%
- {WHITE} {/*Ignore*/}
- "+"|"-"|"*"|"/"|"**"|"//"|"%" {lexeme=yytext(); return OPERADOR_ARITMETICO;}
- "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;}
- "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;}
- "&"|"|"|"^"|"~"|"<<"|">>" {lexeme=yytext(); return OPERADOR_BINARIO;}
- "<"|">"|"<="|">="|"=="|"!="|"<>" {lexeme=yytext(); return OPERADOR_RELACIONAL;}
- "and"|"or"|"not" {lexeme=yytext(); return OPERADOR_LOGICO;}
- {NOMBRE_FUNCION} {lexeme=yytext(); return DECLARACION_FUNCION;}
- {NOMBRE_CLASE} {lexeme=yytext(); return DECLARACION_CLASE;}
- "="|"+="|"-="|"*="|"/="|"**="|"**=" {lexeme=yytext(); return OPERADOR_ASIGNACION;}
- "(" {lexeme=yytext(); return ABRE_PARENTESIS;}
- \"(\\.|[^\"\\])*\" {lexeme=yytext(); return CADENA;}
- {COMENTARIO_multiLINEA}|{COMENTARIO_LINEA} {lexeme=yytext(); return COMENTARIO;}
- {L} {lexeme=yytext(); return VARIABLE;}
- {D} {lexeme=yytext(); return NUMERO_ENTERO;}
- {D}+"."{D} {lexeme=yytext(); return NUMERO_REAL;}
- ")" {lexeme=yytext(); return CIERRA_PARENTESIS;}
- "{" {lexeme=yytext(); return ABRE_LLAVES;}
- "}" {lexeme=yytext(); return CIERRA_LLAVES;}
- ";" {lexeme=yytext(); return FIN;}
- . {return ERROR;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement