Related articles |
---|
Type-checking in bison, C++ converse@cs.uchicago.edu (Tim Converse) (1998-06-11) |
Re: Type-checking in bison, C++ pjmlp@students.si.fct.unl.pt (1998-06-18) |
Re: Type-checking in bison, C++ mzraly@world.std.com (1998-06-18) |
From: | pjmlp@students.si.fct.unl.pt (Paulo Jose Pinto - LEI) |
Newsgroups: | comp.compilers |
Date: | 18 Jun 1998 11:02:56 -0400 |
Organization: | Faculdade de Ciencias e Tecnologia, U.N.L., Portugal |
References: | 98-06-053 |
Keywords: | yacc, C++ |
Tim Converse (converse@cs.uchicago.edu) wrote:
: However, I doubt that a simple %union declaration,
: with some of the alternative types being my C++ classes,
: will let me compose classes using the bison type machinery.
You just have to use pointers. For example ...
%{
// Include your *.h here
%}
%union {
AstExp *exp; /* For expressions */
AstIntConst *ivalue; /* For integer constants */
int iconst; /* For the integer constants of the lexer */
}
%type <exp> AddExp
%type <ivalue> Integer
%type <iconst> IntConst
%%
/* Some part of your grammar ....*/
AddExp : IntConst '+' IntConst { $$ = new AstAddExp (new AstIntConst ($1),
new AstIntConst ($3));
}
| IntConst { $$ = new AstIntConst ($1); }
;
/* Some other part of your grammar ....*/
%%
// C/C++ code
In the example AstAddExp and AstIntConst are subclasses of AstExp. That
way you can make simple assignments and the compiler won't complain about
it.
I hope that this can help you.
--
| Paulo Pinto, pjmlp@students.si.fct.unl.pt |
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.