(Created page with "== Problema == == Solução == category:Compiladores category:Ensino") |
|||
Line 1: | Line 1: | ||
== Problema == | == Problema == | ||
+ | Considere a seguinte especificação sintáctica: | ||
+ | |||
+ | %token NUM | ||
+ | %union { int i; } | ||
+ | %type <nowiki><i></nowiki> NUM cnvl | ||
+ | %% | ||
+ | cnvl : NUM { $$ = $1; } | ||
+ | | cnvl '-' cnvl { $$ = $1 - $3; } | ||
+ | | cnvl '!' { $$ = printf("%d\n", $1); } | ||
+ | ; | ||
+ | %% | ||
+ | int yyerror(char *s) { printf("%s\n", s); return 0; } | ||
+ | int main() { return yyparse(); } | ||
+ | |||
+ | Considere e resolva as seguintes questões: | ||
+ | # A especificação sintáctica apresenta conflitos. Identifique esses conflitos e a sua origem. | ||
+ | # Elimine os conflitos da especificação sintáctica apresentada, SEM ALTERAR A GRAMÁTICA (i.e., o que está entre os %%). | ||
+ | # Elimine os conflitos da especificação sintáctica apresentada, alterando EXCLUSIVAMENTE a gramática. | ||
== Solução == | == Solução == |
Considere a seguinte especificação sintáctica:
%token NUM %union { int i; } %type <i> NUM cnvl %% cnvl : NUM { $$ = $1; } | cnvl '-' cnvl { $$ = $1 - $3; } | cnvl '!' { $$ = printf("%d\n", $1); } ; %% int yyerror(char *s) { printf("%s\n", s); return 0; } int main() { return yyparse(); }
Considere e resolva as seguintes questões: