[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Parser base class (lalr1)
From: |
Jan Nabbefeld |
Subject: |
Re: Parser base class (lalr1) |
Date: |
Wed, 28 Sep 2005 14:37:50 +0200 |
User-agent: |
Mozilla Thunderbird 1.0 (X11/20041206) |
Hello,
Akim Demaille wrote:
This [1] was not defined.
Sorry, here it comes again:
http://lists.gnu.org/archive/html/help-bison/2002-07/msg00047.html
> about the possibelity off defining a base class for the generated
> yy::parser in lalr1 skeleton. Further I noticed that this was
> removed from the lalr1 skeleton on December 2004.
That is right, it seemed to cause more problems than provide
solutions. Do you have a concrete example where this would be useful?
Would you also want to derive from it?
A piece of the parser file:
-8<-----
/* ... */
cd_list: /* empty */ {$$=0;}
| cd_list cd { $$ = NRec(token, _CD_LIST, $1, $2, _CD); }
;
cd: opt_final class_definition ';'
{ $$ = NLift(token, _CD, $1, $2, _OPT_FINAL, _CLASS_DEFINITION); }
;
opt_final: /* empty */ {$$=0;}
| FINAL { $$=NNew(token); $$->type=FINAL; }
;
/* ... */
-8<-----
I would love to have NNew(), NLift() and NRec() as parser methods (for
building AST). Also the initial AST node would be a usefull class
attribute in parser. Unfortunately I'm bound by the BNF rules shown
above. So changes can only be made on the surrounding code.
Parent class of generated yy::parser:
-8<-----
class parserBase:
{
public:
parserBase(const Param& p) :
lexer (new FlexLexer ()),
token (new TokenType ()),
ast (0)
{}
tree * ast;
tree * NNew(tokenType *);
...
}
-8<-----
This works well with Bison <= 1.875e (OK, skeleton changes between the
1.875x releases broke the code again but it worked in general). I know
lalr1.cc skeleton is experimantal and not supported so I don't complain
about that. Would be nice to have the possibility again without
customize the skeleton.
I hope this makes the situation a little bit clearer.
Thanks,
Jan Nabbefeld