Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- === Result
- echo -n "bbaca" | ./a.out
- [A] -> a
- [B] -> b
- [A] -> B
- [A] -> a
- [B] -> b c
- [A] -> B
- === grammar
- %{
- #include <stdio.h>
- #define YYSTYPE char const *
- int yylex (void);
- void yyerror (char const *);
- %}
- %start start
- %glr-parser
- %%
- start: A
- A
- : 'a' { printf ("[A] -> a\n"); }
- | B { printf ("[A] -> B\n"); }
- B
- : 'b' A %dprec 1 { printf ("[B] -> b\n"); }
- | 'b' A 'c' A %dprec 2 { printf ("[B] -> b c\n"); }
- ;
- %%
- void yyerror(const char *str)
- {
- fprintf(stderr, "yyerror: %s\n", str);
- }
- int yywrap(){}
- int main()
- {
- return yyparse();
- }
- === lexer
- %%
- a { return 'a'; }
- b { return 'b'; }
- c { return 'c'; }
- %%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement