%{ // ---------------------------------------------------------------------- // Fichier : lparser.y // Type : yacc // Contient: Analyseur de lambda-calcul (pourrait être non typé) // ---------------------------------------------------------------------- #include "lparser-code.h" int main(void) { return yyparse() ; } void yyerror (const char *s) { fprintf(stdout, "Syntax error !\n") ; } %} // Les tokens principaux sont utilisés comme type dans le reste du code. %token VAR CTE P1 P2 C1 C2 Q LBD AF %% /* Interface */ S: E S | /* epsilon */ ; E: F '?' { printf("Formule reconnue\n") ; /* printf("Avant beta-réduction : \n") ; affiche_formule((noeud *) $$) ; printf("\n ... Après : \n") ; affiche_formule(beta_reduit((noeud *)$$)) ; printf("\n") ; */ } ; /* Formules : Termes, formules atomiques, formules */ T: VAR { $$ = (int) cree_n(VAR, $1, 0, 0) ; } | CTE { $$ = (int) cree_n(CTE, $1, 0, 0) ; } | P1 { $$ = (int) cree_n(P1, $1, 0, 0) ; } | P2 { $$ = (int) cree_n(P2, $1, 0, 0) ; } ; F: T | C1 F { $$ = (int) cree_n(C1, $1, (noeud *) $2, 0) ; } | '(' F C2 F ')' { $$ = (int) cree_n(C2, $3, (noeud *) $2, (noeud *) $4) ; } | Q VAR F { $$ = (int) cree_n(Q, $1, cree_n(VAR, $2, 0, 0), (noeud *) $3) ; } | LBD VAR '.' F { $$ = (int) cree_n(LBD, 0, cree_n(VAR, $2, 0, 0), (noeud *) $3) ; } | '[' F ']' F { $$ = (int) cree_n(AF, 0, (noeud *) $2, (noeud *) $4) ; } ; %%