Está en la página 1de 3

package lexico;

import java.io.*;
import java_cup.runtime.*;

parser code
{:
public static void main(String args[]) throws Exception{
//new parser(new Yylex(new FileInputStream(args[0]))).parse();
new parser(new Yylex(System.in)).parse();
}
public void syntax_error(Symbol s){
String resultado="Error de sintaxis. Linea: " + (s.right + 1) +
" Columna: " + s.left + ". Texto: \"" + s.value + "\"";
report_error("Error de sintaxis. Linea: " + (s.right + 1) +
" Columna: " + s.left + ". Texto: \"" + s.value + "\"", null);
}
:}

terminal String DIFERENTE, MAYORIGUAL, MENORIGUAL, MENOSNUM, MENOSUNO;


terminal String MASNUM, MASUNO, IGUAL, MAYOR, MENOR, PYCOMA, IF, ELSE, SCANF,
INCLUDE, MAIN, PTE;
terminal String COMA, PARIZQ, PARDER, LLAVEIZQ, LLAVEDER, FOR, INT, ID, PRINTF,
COMI, VOID, PORCE, AMPER;
terminal integer NUMERO;

non terminal Programa, Libreria, SalidaT, EscanV, Contenido, Sentelib,


Instrucciones, Para, Si, Mensaje, Escaneo, Inicializacion, Incremento, Inc, E1, E2,
E3, Condifor, Comp, Condicion2;

Programa ::= Libreria Contenido;

Libreria ::= Libreria Sentlib


|Sentelib
;

Instrucciones ::= Para


|Si
|SalidaT
|EscanV
;
Sentelib ::= INCLUDE MENOR ID PTE ID MAYOR {: System.out.println("Sentencia
analizada correctamente. Sin errores); :}
|INCLUDE COMI ID PTE ID COMI {: System.out.println("Sentencia
analizada correctamente. Sin errores); :}
| error {: System.out.println("Error sintactico en la
sentencia"); :}
;

Contenido ::= INT MAIN PARIZQ PARDER LLAVEIZQ Instrucciones LLAVEDER{:


System.out.println("Sentencia analizada correctamente. Sin errores); :}
| error {: System.out.println("Error sintactico en la
sentencia"); :}
;

Si ::= IF PARIZQ Condicion PARDER LLAVEIZQ Instrucciones LLAVEDER{:


System.out.println("Sentencia analizada correctamente. Sin errores); :}
| IF PARIZQ Condicion PARDER LLAVEIZQ Instrucciones LLAVEDER ELSE
LLAVEIZQ Instrucciones LLAVEDER{: System.out.println("Sentencia analizada
correctamente. Sin errores); :}
;

Condicion ::= ID IGUAL ID


| ID MENOR ID
;

SalidaT ::= SalidaT Mensaje


| Mensaje
;

Mensaje ::= PRINTF PARIZQ COMI ID COMI PARDER PYCOMA{:


System.out.println("Sentencia analizada correctamente. Sin errores); :}
;

EscanV ::= EscanV Escaneo


| Escaneo
;

Escaneo ::= SCANF PARIZQ COMI PORCE ID COMI COMA AMPER ID PARDER PYCOMA{:
System.out.println("Sentencia analizada correctamente. Sin errores); :}
;

Para ::= FOR PARIZQ Condifor PARDER LLAVEIZQ Instrucciones LLAVEDER{:


System.out.println("Sentencia analizada correctamente. Sin errores); :}
;

Condifor ::= E1 PYCOMA E2 PYCOMA E3


;

E1 ::= Inicializacion
|
;
E2 ::= Condicion2
|
;
E3 ::= Incremento
|
;
Inicializacion ::= Inicializacion COMA INT ID IGUAL NUMERO
| INT ID IGUAL NUMERO
;
Condicion2 ::= Condicion2 COMA ID Comp NUMERO
| ID Comp NUMERO
;
Comp ::= DIFERENTE
| MAYORIGUAL
| MENORIGUAL
| MAYOR
| MENOR
| IGUAL
;
Incremento ::= Incremento COMA ID Inc
| ID Inc
;
Inc ::= MENOSNUM NUMERO
| MENOSUNO
| MASNUM NUMERO
| MASUNO
;

También podría gustarte