Anda di halaman 1dari 17

/*--------------- 1ra Area: Codigo de Usuario -----------------------*/

//-------> importaciones, paquetes

package Models;

import java_cup.runtime.Symbol;

//------> Codigo para el parser,variables, metodos

parser code

{:

public String result="";

String temporal = "" ;

String temporal2="";

String temporal3="";

String temporalvalor="";

String envget="false";

String enviaset="false";

String hereda="";

String guardo="";

String consulta="";

String valorsigno="";

String valoracceder="";

String valoraccederid="";

String serialcondicion="";

String insertarvalores="";

//Metodo al que se llama automaticamente ante algun error sintactico

public void syntax_error(Symbol s)

String lexema = s.value.toString();


int fila = s.right;

int columna = s.left;

result +="\n!!!!!!! Error Sintactico Recuperado !!!!!!!\t\tLexema: "+lexema+"\t\tFila:


"+fila+"\t\tColumna: "+columna;

System.out.println("!!!!!!! Error Sintactico Recuperado !!!!!!!");

System.out.println("\t\tLexema: "+lexema);

System.out.println("\t\tFila: "+fila);

System.out.println("\t\tColumna: "+columna);

//Metodo al que se llama en el momento en que ya no es posible una recuperacion de errores

public void unrecovered_syntax_error(Symbol s) throws java.lang.Exception

String lexema = s.value.toString();

int fila = s.right;

int columna = s.left;

result +="\n!!!!!!! Error Sintactico, Panic Mode !!!!!!!\t\tLexema: "+lexema+"\t\tFila:


"+fila+"\t\tColumna: "+columna;

System.out.println("!!!!!!! Error Sintactico, Panic Mode !!!!!!! ");

System.out.println("\t\tLexema: "+lexema);

System.out.println("\t\tFila: "+fila);

System.out.println("\t\tColumna: "+columna);

:}

//------> Codigo para las acciones gramaticales


action code

{:

:}

/*--------------- 2da Area: Declaraciones -----------------------*/

//------> declaracion de terminales

terminal function, procedure, boolean_type , int_type , float_type , char_type , string_type ;

terminal parametro_entrada , parametro_salida , parametro_entada_salida , ciclo_for ,


ciclo_while , ciclo_repeat , condicional_if ;

terminal condicional_switch , condicional_until , then , else , end_if , end_case ;

terminal suma , resta , multiplicacion , division , potencia , menor , mayor , comparacion ,


menor_igual ;

terminal mayor_igual , modulo , diferente , or , and , not , asignacion , parentesis_abierto ;

terminal parentesis_cerrado , llave_abierta , llave_cerrada , corchete_abierto , corchete_cerrado ,


coma , hasta , hacer ;

terminal down_to , digito , letra , entero , numero , id , comilla_abierta , comilla_cerrada,


end_for, case ;

terminal dos_puntos, end_while ;

//------> declaracion de no terminales

non terminal S , INICIO, ARGUMENTOS , DEFVARIABLES , CUERPITO , REFERENCIA , TIPODATO ,


VECTOR , OPERADOR_LOGICO ;

non terminal ELEMENTOS , MATRIZ ,CICLOS, CONDICIONALES , INSTRUCCIONES , FOR , WHILE ,


REPEAT , IF , SWITCH , OPERADOR_RELACIONAL ;
non terminal EXPRESION_REG , ASIGNACIONES , OPERACIONES ,OPERADOR_MATEMATICO ,
CONTADOR , ACUMULADOR , MATEMATICAS, CONDICION ;

start with S;

/*--------------- 3ra Area: Reglas Semanticas -----------------------*/

S ::= INICIO | INICIO S;

INICIO ::= procedure id parentesis_abierto ARGUMENTOS parentesis_cerrado DEFVARIABLES


llave_abierta CUERPITO llave_cerrada

| function id parentesis_abierto ARGUMENTOS parentesis_cerrado DEFVARIABLES


llave_abierta CUERPITO llave_cerrada

| procedure id parentesis_abierto parentesis_cerrado DEFVARIABLES llave_abierta


CUERPITO llave_cerrada

| function id parentesis_abierto parentesis_cerrado DEFVARIABLES llave_abierta CUERPITO


llave_cerrada

| procedure id parentesis_abierto ARGUMENTOS parentesis_cerrado llave_abierta


CUERPITO llave_cerrada

| function id parentesis_abierto ARGUMENTOS parentesis_cerrado llave_abierta CUERPITO


llave_cerrada

| procedure id parentesis_abierto parentesis_cerrado llave_abierta CUERPITO


llave_cerrada

| function id parentesis_abierto parentesis_cerrado llave_abierta CUERPITO llave_cerrada


;

/*---------------

| procedure id parentesis_abierto ARGUMENTOS parentesis_cerrado DEFVARIABLES


llave_abierta CUERPITO llave_cerrada

| function id parentesis_abierto ARGUMENTOS parentesis_cerrado DEFVARIABLES


llave_abierta CUERPITO llave_cerrada INICIO

| procedure id parentesis_abierto parentesis_cerrado DEFVARIABLES llave_abierta


CUERPITO llave_cerrada INICIO

| function id parentesis_abierto parentesis_cerrado DEFVARIABLES llave_abierta CUERPITO


llave_cerrada INICIO
| procedure id parentesis_abierto ARGUMENTOS parentesis_cerrado llave_abierta
CUERPITO llave_cerrada INICIO

| function id parentesis_abierto ARGUMENTOS parentesis_cerrado llave_abierta CUERPITO


llave_cerrada INICIO

| procedure id parentesis_abierto parentesis_cerrado llave_abierta CUERPITO


llave_cerrada INICIO

| function id parentesis_abierto parentesis_cerrado llave_abierta CUERPITO llave_cerrada


INICIO ;

-----------------------*/

ARGUMENTOS ::= REFERENCIA TIPODATO id coma ARGUMENTOS

| REFERENCIA TIPODATO id ;

REFERENCIA ::= parametro_entrada | parametro_salida | parametro_entada_salida ;

TIPODATO ::= int_type | char_type | float_type | boolean_type | string_type ;

ELEMENTOS ::= entero coma ELEMENTOS | entero | comilla_abierta id comilla_cerrada |


comilla_abierta id comilla_cerrada coma ELEMENTOS | id coma ELEMENTOS ;

VECTOR ::= TIPODATO id corchete_abierto corchete_cerrado

| TIPODATO id corchete_abierto entero corchete_cerrado

| TIPODATO id corchete_abierto id corchete_cerrado

| TIPODATO id corchete_abierto corchete_cerrado asignacion llave_abierta ELEMENTOS


llave_cerrada

| TIPODATO id corchete_abierto corchete_cerrado VECTOR

| TIPODATO id corchete_abierto entero corchete_cerrado VECTOR

| TIPODATO id corchete_abierto id corchete_cerrado VECTOR

| TIPODATO id corchete_abierto corchete_cerrado asignacion llave_abierta ELEMENTOS


llave_cerrada VECTOR ;
MATRIZ ::= TIPODATO id corchete_abierto corchete_cerrado corchete_abierto
corchete_cerrado MATRIZ

| TIPODATO id corchete_abierto entero corchete_cerrado corchete_abierto entero


corchete_cerrado MATRIZ

| TIPODATO id corchete_abierto id corchete_cerrado corchete_abierto id


corchete_cerrado MATRIZ

| TIPODATO id corchete_abierto entero corchete_cerrado corchete_abierto id


corchete_cerrado MATRIZ

| TIPODATO id corchete_abierto id corchete_cerrado corchete_abierto entero


corchete_cerrado MATRIZ

| TIPODATO id corchete_abierto corchete_cerrado corchete_abierto corchete_cerrado

| TIPODATO id corchete_abierto entero corchete_cerrado corchete_abierto entero


corchete_cerrado

| TIPODATO id corchete_abierto id corchete_cerrado corchete_abierto id


corchete_cerrado

| TIPODATO id corchete_abierto entero corchete_cerrado corchete_abierto id


corchete_cerrado

| TIPODATO id corchete_abierto id corchete_cerrado corchete_abierto entero


corchete_cerrado ;

//------> OJO CON VECTOR Y MATRIZ

//------> TIPODATO ::= int_type | char_type | float_type | boolean_type | string_type | VECTOR


|MATRIZ ;

DEFVARIABLES ::= ASIGNACIONES ;

EXPRESION_REG ::= digito | numero | entero | id | letra ;

OPERADOR_MATEMATICO ::= suma | resta | multiplicacion | division | potencia | modulo ;


OPERADOR_LOGICO ::= menor | mayor | comparacion | menor_igual |mayor_igual | diferente |
not ;

OPERADOR_RELACIONAL ::= and | or ;

CONTADOR ::= id suma suma | id resta resta ;

CUERPITO ::= CICLOS | CONDICIONALES | INSTRUCCIONES| ;

CICLOS ::= FOR | WHILE | REPEAT | FOR CICLOS | WHILE CICLOS | REPEAT CICLOS ;

FOR ::= ciclo_for id asignacion entero hasta EXPRESION_REG hacer CUERPITO end_for |

ciclo_for id asignacion id hasta EXPRESION_REG hacer CUERPITO end_for |

ciclo_for id asignacion entero down_to EXPRESION_REG hacer CUERPITO end_for ;

WHILE ::= ciclo_while parentesis_abierto CONDICION parentesis_cerrado hacer CUERPITO


end_while ;

REPEAT ::= ciclo_repeat CUERPITO condicional_until parentesis_abierto CONDICION


parentesis_cerrado ;

CONDICIONALES ::= IF | SWITCH | IF CONDICIONALES | SWITCH CONDICIONALES ;

IF ::= condicional_if parentesis_abierto CONDICION parentesis_cerrado then CUERPITO end_if

| condicional_if parentesis_abierto CONDICION parentesis_cerrado then CUERPITO else


CUERPITO end_if ;

SWITCH ::= condicional_switch id case id dos_puntos CUERPITO end_case


| condicional_switch id case id dos_puntos CUERPITO SWITCH end_case

| case id CUERPITO ;

CONDICION ::= parentesis_abierto EXPRESION_REG OPERADOR_LOGICO EXPRESION_REG


parentesis_cerrado

| parentesis_abierto EXPRESION_REG OPERADOR_LOGICO EXPRESION_REG


parentesis_cerrado

| parentesis_abierto EXPRESION_REG OPERADOR_LOGICO EXPRESION_REG


parentesis_cerrado OPERADOR_RELACIONAL CONDICION ;

INSTRUCCIONES ::= ASIGNACIONES | OPERACIONES | ASIGNACIONES INSTRUCCIONES


|OPERACIONES INSTRUCCIONES ;

ASIGNACIONES ::=TIPODATO id asignacion EXPRESION_REG

| TIPODATO id asignacion EXPRESION_REG ASIGNACIONES | TIPODATO ;

OPERACIONES ::= CONTADOR | ACUMULADOR | MATEMATICAS ;

ACUMULADOR ::= id asignacion id suma id | id asignacion id resta id ;


MATEMATICAS ::= id asignacion id OPERADOR_MATEMATICO id

| id asignacion id OPERADOR_MATEMATICO id MATEMATICAS ;

/*-------------Codigo de Usuario---------------*/

//-------> Paquetes, importaciones:

package Models;

import java_cup.runtime.*;

import java.io.BufferedWriter;

import java.io.FileWriter;

import java.io.IOException;

import java.util.ArrayList;

/*-------------Opciones y Declaraciones-------------*/

%%

%{

//-----> Codigo de usuario en sintaxis java

public String showResult = "";

%}

//-----> Directivas

%public

%class LexicalAnalyzer

%cupsym Symbols

%cup

%char

%column
%full

%ignorecase

%line

%unicode

///-----> Expresiones Regulares

digito = [0-9]

letra = [A-Za-z]

entero = {digito} {digito}*

decimal = {digito}+"."{digito}+

identificador = {letra}({letra}|{digito})*

%%

/*-------------Reglas Lexicas---------------*/

//-----------------> Simbolos

<YYINITIAL> "FUNCTION" { System.out.println("Token correcto: "+yytext()+" function");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.function, yycolumn, yyline, yytext()); }

<YYINITIAL> "PROCEDURE" { System.out.println("Token correcto: "+yytext()+" procedure");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.procedure, yycolumn, yyline, yytext()); }

<YYINITIAL> "BOOLEAN" { System.out.println("Token correcto: "+yytext()+" boolean_type");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.boolean_type, yycolumn, yyline, yytext()); }

<YYINITIAL> "INT" { System.out.println("Token correcto: "+yytext()+" int"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.int_type, yycolumn, yyline, yytext()); }
<YYINITIAL> "FLOAT" { System.out.println("Token correcto: "+yytext()+" float"); showResult +=
"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.float_type, yycolumn, yyline, yytext()); }

<YYINITIAL> "CHAR" { System.out.println("Token correcto: "+yytext()+" char"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.char_type, yycolumn, yyline, yytext()); }

<YYINITIAL> "STRING" { System.out.println("Token correcto: "+yytext()+" string"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.string_type, yycolumn, yyline, yytext()); }

//-----> <YYINITIAL> "RETURN" { System.out.println("Token correcto: "+yytext()+" retorno");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.retorno, yycolumn, yyline, yytext()); }

//-----> <YYINITIAL> "TRUE" { System.out.println("Token correcto: "+yytext()+" verdadero");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.verdadero , yycolumn, yyline, yytext()); }

//-----> <YYINITIAL> "FALSE" { System.out.println("Token correcto: "+yytext()+" falso");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.falso, yycolumn, yyline, yytext()); }

<YYINITIAL> "I" { System.out.println("Token correcto: "+yytext()+" parametro_entrada");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.parametro_entrada, yycolumn, yyline, yytext()); }

<YYINITIAL> "O" { System.out.println("Token correcto: "+yytext()+" parametro_salida");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.parametro_salida, yycolumn, yyline, yytext()); }

<YYINITIAL> "IO" { System.out.println("Token correcto: "+yytext()+"


parametro_entada_salida"); showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + "
columna: "+ (yycolumn+1) + " \n"; return new Symbol(Symbols.parametro_entada_salida,
yycolumn, yyline, yytext()); }

<YYINITIAL> "FOR" { System.out.println("Token correcto: "+yytext()+" ciclo_for"); showResult


+= "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.ciclo_for, yycolumn, yyline, yytext()); }

<YYINITIAL> "WHILE" { System.out.println("Token correcto: "+yytext()+" ciclo_while");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.ciclo_while, yycolumn, yyline, yytext()); }

<YYINITIAL> "REPEAT" { System.out.println("Token correcto: "+yytext()+" ciclo_repeat");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.ciclo_repeat, yycolumn, yyline, yytext()); }
<YYINITIAL> "IF" { System.out.println("Token correcto: "+yytext()+" condicional_if");
showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.condicional_if, yycolumn, yyline, yytext()); }

<YYINITIAL> "SWITCH" { System.out.println("Token correcto: "+yytext()+" condicional_switch");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.condicional_switch, yycolumn, yyline, yytext()); }

<YYINITIAL> "UNTIL" { System.out.println("Token correcto: "+yytext()+" condicional_until");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.condicional_until, yycolumn, yyline, yytext()); }

<YYINITIAL> "THEN" { System.out.println("Token correcto: "+yytext()+" then"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.then, yycolumn, yyline, yytext()); }

<YYINITIAL> "ELSE" { System.out.println("Token correcto: "+yytext()+" else"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.else, yycolumn, yyline, yytext()); }

<YYINITIAL> "END IF" { System.out.println("Token correcto: "+yytext()+" end if"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.end_if, yycolumn, yyline, yytext()); }

//-----> <YYINITIAL> "CASE" { System.out.println("Token correcto: "+yytext()+" case of");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.case_of, yycolumn, yyline, yytext()); }

<YYINITIAL> "END CASE" { System.out.println("Token correcto: "+yytext()+" end case");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.end_case, yycolumn, yyline, yytext()); }

//-----> <YYINITIAL> "ARRAY" { System.out.println("Token correcto: "+yytext()+" array");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.array , yycolumn, yyline, yytext()); }

//-----> <YYINITIAL> "LIST" { System.out.println("Token correcto: "+yytext()+" list"); showResult


+= "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.list, yycolumn, yyline, yytext()); }

//-----> <YYINITIAL> "STACK" { System.out.println("Token correcto: "+yytext()+" stack");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.stack, yycolumn, yyline, yytext()); }

//-----> <YYINITIAL> "QUEVE" { System.out.println("Token correcto: "+yytext()+" queve");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.queve, yycolumn, yyline, yytext()); }
//-----> <YYINITIAL> "TREE" { System.out.println("Token correcto: "+yytext()+" tree");
showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.tree, yycolumn, yyline, yytext()); }

//-----> <YYINITIAL> "GRAPH" { System.out.println("Token correcto: "+yytext()+" graph");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.graph, yycolumn, yyline, yytext()); }

//-----> <YYINITIAL> "SET" { System.out.println("Token correcto: "+yytext()+" set"); showResult


+= "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.set, yycolumn, yyline, yytext()); }

<YYINITIAL> "+" { System.out.println("Token correcto: "+yytext()+" suma"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.suma, yycolumn, yyline, yytext()); }

<YYINITIAL> "-" { System.out.println("Token correcto: "+yytext()+" resta"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.resta, yycolumn, yyline, yytext()); }

<YYINITIAL> "*" { System.out.println("Token correcto: "+yytext()+" multiplicacion");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.multiplicacion, yycolumn, yyline, yytext()); }

<YYINITIAL> "/" { System.out.println("Token correcto: "+yytext()+" division"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.division, yycolumn, yyline, yytext()); }

<YYINITIAL> "^" { System.out.println("Token correcto: "+yytext()+" potencia"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.potencia, yycolumn, yyline, yytext()); }

<YYINITIAL> "<" { System.out.println("Token correcto: "+yytext()+" menor"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.menor, yycolumn, yyline, yytext()); }

<YYINITIAL> ">" { System.out.println("Token correcto: "+yytext()+" mayor"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.mayor, yycolumn, yyline, yytext()); }

<YYINITIAL> "==" { System.out.println("Token correcto: "+yytext()+" comparacion");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.comparacion, yycolumn, yyline, yytext()); }

<YYINITIAL> "<=" { System.out.println("Token correcto: "+yytext()+" menor igual"); showResult


+= "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.menor_igual, yycolumn, yyline, yytext()); }
<YYINITIAL> ">=" { System.out.println("Token correcto: "+yytext()+" mayor igual"); showResult
+= "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.mayor_igual, yycolumn, yyline, yytext()); }

//-----> <YYINITIAL> "DIV" { System.out.println("Token correcto: "+yytext()+" division entera");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.division, yycolumn, yyline, yytext()); }

<YYINITIAL> "MOD" { System.out.println("Token correcto: "+yytext()+" modulo"); showResult


+= "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.modulo, yycolumn, yyline, yytext()); }

<YYINITIAL> "<>" { System.out.println("Token correcto: "+yytext()+" diferente"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.diferente, yycolumn, yyline, yytext()); }

<YYINITIAL> "OR" { System.out.println("Token correcto: "+yytext()+" o logico"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.or, yycolumn, yyline, yytext()); }

<YYINITIAL> "AND" { System.out.println("Token correcto: "+yytext()+" y logico"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.and, yycolumn, yyline, yytext()); }

<YYINITIAL> "NOT" { System.out.println("Token correcto: "+yytext()+" no logico"); showResult


+= "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.not, yycolumn, yyline, yytext()); }

//-----> <YYINITIAL> "%" { System.out.println("Token correcto: "+yytext()+" comentario");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.comentario, yycolumn, yyline, yytext()); }

<YYINITIAL> "<-" { System.out.println("Token correcto: "+yytext()+" asignacion"); showResult


+= "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.asignacion, yycolumn, yyline, yytext()); }

<YYINITIAL> "(" { System.out.println("Token correcto: "+yytext()+" parentesisabre");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.parentesis_abierto, yycolumn, yyline, yytext()); }

<YYINITIAL> ")" { System.out.println("Token correcto: "+yytext()+" parentesiscierra");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.parentesis_cerrado, yycolumn, yyline, yytext()); }

<YYINITIAL> "{" { System.out.println("Token correcto: "+yytext()+" llaveabre"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.llave_abierta, yycolumn, yyline, yytext()); }
<YYINITIAL> "}" { System.out.println("Token correcto: "+yytext()+" llavecierra"); showResult +=
"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.llave_cerrada, yycolumn, yyline, yytext()); }

<YYINITIAL> "[" { System.out.println("Token correcto: "+yytext()+" corcheteabre"); showResult


+= "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.corchete_abierto, yycolumn, yyline, yytext()); }

<YYINITIAL> "]" { System.out.println("Token correcto: "+yytext()+" corchetecierra");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.corchete_cerrado, yycolumn, yyline, yytext()); }

<YYINITIAL> "," { System.out.println("Token correcto: "+yytext()+" coma"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.coma, yycolumn, yyline, yytext()); }

<YYINITIAL> "TO" { System.out.println("Token correcto: "+yytext()+" hasta"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.hasta, yycolumn, yyline, yytext()); }

<YYINITIAL> "DO" { System.out.println("Token correcto: "+yytext()+" hacer"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.hacer, yycolumn, yyline, yytext()); }

//-----> <YYINITIAL> "INC" { System.out.println("Token correcto: "+yytext()+" incremento");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.incremento, yycolumn, yyline, yytext()); }

//-----> <YYINITIAL> "DEC" { System.out.println("Token correcto: "+yytext()+" decremento");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.decremento, yycolumn, yyline, yytext()); }

//-----> <YYINITIAL> "DOWNTO" { System.out.println("Token correcto: "+yytext()+" descenso");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.down_to, yycolumn, yyline, yytext()); }

<YYINITIAL> "PRINT" { System.out.println("Token correcto: "+yytext()+" imprimir"); showResult


+= "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.imprimir, yycolumn, yyline, yytext()); }

<YYINITIAL> "<<" { System.out.println("Token correcto: "+yytext()+" comilla_abierta");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.comilla, yycolumn, yyline, yytext()); }

<YYINITIAL> ">>" { System.out.println("Token correcto: "+yytext()+" comilla_cerrada");


showResult += "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + "
\n"; return new Symbol(Symbols.cerrada, yycolumn, yyline, yytext()); }
<YYINITIAL> "END FOR" { System.out.println("Token correcto: "+yytext()+" end for"); showResult
+= "Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.end_for, yycolumn, yyline, yytext()); }

<YYINITIAL> "CASE" { System.out.println("Token correcto: "+yytext()+"case"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.case, yycolumn, yyline, yytext()); }

<YYINITIAL> ":" { System.out.println("Token correcto: "+yytext()+"puntos"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.dos_puntos, yycolumn, yyline, yytext()); }

//-----------------> Simbolos ER

<YYINITIAL> {digito} { System.out.println("Token "+yytext()+" digito"); showResult += "Token


correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return new
Symbol(Symbols.digito, yycolumn, yyline, yytext()); }

<YYINITIAL> {letra} { System.out.println("Token "+yytext()+" letra"); showResult += "Token


correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return new
Symbol(Symbols.letra, yycolumn, yyline, yytext()); }

<YYINITIAL> {entero} { System.out.println("Token "+yytext()+" enero"); showResult += "Token


correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return new
Symbol(Symbols.entero, yycolumn, yyline, yytext()); }

<YYINITIAL> {decimal} { System.out.println("Token "+yytext()+" numero"); showResult +=


"Token correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return
new Symbol(Symbols.numero, yycolumn, yyline, yytext()); }

<YYINITIAL> {identificador} { System.out.println("Token "+yytext()+" id"); showResult += "Token


correcto: " +yytext()+" Linea: " + (yyline+1) + " columna: "+ (yycolumn+1) + " \n"; return new
Symbol(Symbols.id, yycolumn, yyline, yytext()); }

//------> Espacios

[ \t\r\n\f] {/* Espacios en blanco, se ignoran */}


//------> Errores Lexicos

. { System.out.println("\nError Lexico: "+yytext()+" Linea: "+yyline+" Columna:


"+yycolumn); showResult += "\n Error Lexico: " + yytext() + " Linea: " + (yyline+1) + " Columna: " +
(yycolumn+1) + "\n";}

Anda mungkin juga menyukai