Slightly nicer grammar token syntax
GNU Bison has an interesting feature, which is that it lets you associate strings with tokens and use the strings in rules. That is, you can declare:
%token ARROW "=>"
or
%token COMMA ","
and then in in a grammar rule, you may use ","
instead of COMMA
(though you may still use COMMA
if you wish). Note that this is pure syntactic sugar and has no impact at all on the semantics of the rule, which simply interprets ","
as though COMMA
had been written.
This results in much more readable grammars because instead of having to say OBRACE
or some such, one just has "{" present, which is much more easily read in the grammar rule.
For example, instead of
| DO statement WHILE OPAREN expression CPAREN SEMI
one can have
| DO statement WHILE "(" expression ")" ";"
Again, note this is purely syntactic sugar.