[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Suggestion: enumerating non-terminals
From: |
Ramaswamy R |
Subject: |
Re: Suggestion: enumerating non-terminals |
Date: |
Fri, 23 Feb 2007 19:32:03 +0530 |
Hi,
I had a similar requirement. So I ended up writing an awk script to extract
the production names from the grammar file. Executing the attached awkscript
on the .y file would generate the production names (which I route to a
file).
The catch is that it identifies a production name as the token from the
beginning of the lines in the grammar rules section. As long as you can make
sure that no other token comes 1st in a line, which is pretty reasonably
plausible, you should be able to automatically generate the production names
as and when the grammar file is modified.
All you need to name an enum of this like is a code similar to the one below
-
enum mylangPrdn
{
prdn_None = -1,
#include "myLangPrdns.h"
prdn_End
};
And if you need to generate a table with production names as well, you could
do that with another awk script file! Hope this helps, though a late
response.
Regards
Ramaswamy
--
"Chaos is the rule in nature, not an exception"
http://ramaswamy.r.googlepages.com
On 12/21/06, Tony Li <address@hidden> wrote:
Hi,
I have a small proposal that I'd like to float.
In building a parse tree for a complex language, it's very helpful to
identify which nodes correspond to which productions in the grammar.
Bison already has internal identifiers for each non-terminal and
carries around ASCII strings for each in yytname[]. What I'd dearly
love to see is the ability (probably as an option) to export these
symbols into y.tab.h, preferably as part of an enum.
It's possible to generate this by hand, but as it's not automatically
maintained today, any significant change in the grammar requires a
manual update of the symbols. This is Not Fun.
Comments? Suggestions?
Tony
_______________________________________________
address@hidden http://lists.gnu.org/mailman/listinfo/help-bison
awkprdn
Description: Text document
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Suggestion: enumerating non-terminals,
Ramaswamy R <=