%{ #include #include #include int yylex() ; void yyerror(const char *s) { fprintf(stderr, "yyerror: %s\n", s) ; exit(1) ; } FILE *of ; %} %token NAME NUMBER %% expression: expression '+' NUMBER { fprintf (of, "%d + ", $3) ; } | expression '-' NUMBER { fprintf (of, "%d - ", $3) ; } | NUMBER { fprintf (of, "%d ", $1) ; } ; %% int main () { fprintf (stderr, "Enter an expression:\n") ; of = fopen ("out.fs", "w") ; assert(of != NULL) ; yyparse() ; fprintf (of, "\n.s CR\n") ; fclose(of) ; return 0 ; } /* End of main() */