pol.y
%{
#include <stdio.h>
%}
%token COLON
%token COLON_EQUAL
%token NUMBER
%token PLUS
%token TIMES
%token VARIABLE
%%
assignment : VARIABLE COLON_EQUAL iterm_list
| VARIABLE COLON
{yyerror("':=' expected");}
| VARIABLE NUMBER
{yyerror("':=' expected");}
| VARIABLE VARIABLE
{yyerror("invalid id");}
;
iterm_list : iterm
| iterm_list iterm_list PLUS
| iterm_list iterm_list TIMES
;
iterm : VARIABLE
| NUMBER
;
%%
#include "lex.yy.c"
yyerror(s)
char *s;
{
if (!strcmp(s,"parse error"))
printf("Ligne %d: Erro sinta'tico perto de \"%s\"\n",
yylineno,yytext);
else
printf("Ligne %d: %s\n", yylineno, s);
}
main ()
{
printf("Digite uma atribuicao: ");
yyparse();
}
Generated by GNU enscript 1.6.4.