Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %{
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include "y.tab.h"
- int yystopparser=0;
- FILE *yyin;
- %}
- %token PROGRAM
- %token DEFINE
- %token ENDDEFINE
- %token CONST_STR
- %token REAL
- %token CONST_INT
- %token INTEGER
- %token STRING
- %token IF DO ELSE ENDIF
- %token WHILE ENDWHILE
- %token ENDPROGRAM
- %token CONST
- %token ENDCONST
- %token OPERADOR_NEGACION
- %token OPERADOR_LOGICO
- %token OPERADOR_ASIGNACION
- %token OPERADOR_MAYOR
- %token OPERADOR_MENOR
- %token OPERADOR_IGUAL
- %token OPERADOR_MENORIGUAL
- %token OPERADOR_MAYORIGUAL
- %token OPERADOR_DISTINTO
- %token OPERADOR_SUMA
- %token OPERADOR_RESTA
- %token OPERADOR_MULTIPLICACION
- %token OPERADOR_DIVISION
- %token SEPARADOR_DECIMALES
- %token SEPARADOR_IDENTIFICADORES
- %token SEPARADOR_SENTENCIA
- %token PARENTESIS_ABRE PARENTESIS_CIERRA
- %token APERTURA_COMENTARIO CIERRE_COMENTARIO
- %token DOSPUNTOS
- %token DISPLAY
- %token COMILLA
- %token ID
- %%
- START:
- PROGRAM ID SEPARADOR_SENTENCIA zona_declaracion_constantes zona_declaracion_variables bloque ENDPROGRAM
- ;
- zona_declaracion_variables:
- DEFINE conjunto_definiciones ENDDEFINE
- ;
- zona_declaracion_constantes:
- CONST constantes ENDCONST
- ;
- constantes:
- constantes SEPARADOR_SENTENCIA const
- | const SEPARADOR_SENTENCIA
- ;
- const:
- declaracion_const_reales
- | declaracion_const_int
- | declaracion_const_str
- ;
- declaracion_const_str:
- STRING ID OPERADOR_ASIGNACION literal_string
- ;
- declaracion_const_reales:
- REAL ID OPERADOR_ASIGNACION literal_real
- ;
- declaracion_const_int:
- INTEGER ID OPERADOR_ASIGNACION literal_entero
- ;
- conjunto_definiciones:
- conjunto_definiciones definiciones
- | definiciones
- ;
- seleccion:
- IF condicion DO bloque ELSE bloque ENDIF
- ;
- condicion:
- comparacion OPERADOR_LOGICO comparacion
- | OPERADOR_NEGACION comparacion
- | comparacion
- | comparacion OPERADOR_LOGICO OPERADOR_NEGACION comparacion
- ;
- comparacion:
- expresion OPERADOR_MAYOR expresion
- | expresion OPERADOR_MENOR expresion
- | expresion OPERADOR_MAYORIGUAL expresion
- | expresion OPERADOR_MENORIGUAL expresion
- | expresion OPERADOR_DISTINTO expresion
- | expresion OPERADOR_IGUAL expresion
- ;
- expresion:
- expresion OPERADOR_SUMA termino
- | expresion OPERADOR_RESTA termino
- | termino
- ;
- termino:
- termino OPERADOR_MULTIPLICACION factor
- | termino OPERADOR_DIVISION factor
- | factor
- ;
- factor:
- ID
- | literal_entero
- | literal_real
- | PARENTESIS_ABRE expresion PARENTESIS_CIERRA
- ;
- iteracion_condicional:
- WHILE condicion DO bloque ENDWHILE
- ;
- bloque:
- sentencia SEPARADOR_SENTENCIA
- | bloque sentencia SEPARADOR_SENTENCIA
- ;
- sentencia:
- asignacion
- | estructura_control
- | salida
- | comentario
- ;
- comentario:
- APERTURA_COMENTARIO literal_string CIERRE_COMENTARIO
- ;
- estructura_control:
- seleccion
- | iteracion_condicional
- ;
- asignacion:
- ID OPERADOR_ASIGNACION concatenacion
- | ID OPERADOR_ASIGNACION expresion
- | ID OPERADOR_ASIGNACION literal_string
- ;
- concatenacion:
- ID OPERADOR_SUMA ID
- | ID OPERADOR_SUMA literal_string
- | literal_string OPERADOR_SUMA ID
- | literal_string OPERADOR_SUMA literal_string
- ;
- literal_string:
- COMILLA CONST_STR COMILLA
- ;
- literal_real:
- signo numero_int SEPARADOR_DECIMALES numero_int
- | numero_int SEPARADOR_DECIMALES numero_int
- | signo SEPARADOR_DECIMALES numero_int
- | SEPARADOR_DECIMALES numero_int
- | signo numero_int SEPARADOR_DECIMALES
- | numero_int SEPARADOR_DECIMALES
- ;
- literal_entero:
- signo numero_int
- | numero_int
- ;
- numero_int:
- CONST_INT
- ;
- signo:
- OPERADOR_RESTA
- ;
- definiciones:
- definicion_string
- | definicion_entero
- | definicion_real
- ;
- definicion_string:
- STRING DOSPUNTOS iteracion_id SEPARADOR_SENTENCIA
- ;
- definicion_entero:
- INTEGER DOSPUNTOS iteracion_id SEPARADOR_SENTENCIA
- ;
- definicion_real:
- REAL DOSPUNTOS iteracion_id SEPARADOR_SENTENCIA
- ;
- iteracion_id:
- ID
- | ID SEPARADOR_IDENTIFICADORES iteracion_id
- ;
- salida:
- DISPLAY PARENTESIS_ABRE ID PARENTESIS_CIERRA
- | DISPLAY PARENTESIS_ABRE literal_entero PARENTESIS_CIERRA
- | DISPLAY PARENTESIS_ABRE literal_real PARENTESIS_CIERRA
- | DISPLAY PARENTESIS_ABRE literal_string PARENTESIS_CIERRA
- ;
- %%
- int main(int argc,char *argv[])
- {
- if ((yyin = fopen(argv[1], "rt")) == NULL)
- {
- printf("\nNo se puede abrir el archivo: %s\n", argv[1]);
- }
- else
- {
- yyparse();
- }
- fclose(yyin);
- return 0;
- }
- int yyerror(void)
- {
- printf("Syntax Error\n");
- system ("Pause");
- exit (1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement