Related articles |
---|
How to parse and call c++ constructors? groleo@gmail.com (Groleo) (2005-09-17) |
Re: How to parse and call c++ constructors? Meyer-Eltz@t-online.de (Detlef Meyer-Eltz) (2005-09-18) |
Re: How to parse and call c++ constructors? Juergen.Kahrs@vr-web.de (=?ISO-8859-1?Q?J=FCrgen_Kahrs?=) (2005-09-22) |
Re: How to parse and call c++ constructors? pohjalai@cc.helsinki.fi (A Pietu Pohjalainen) (2005-09-22) |
Re: How to parse and call c++ constructors? DrDiettrich@compuserve.de (Hans-Peter Diettrich) (2005-09-22) |
Re: How to parse and call c++ constructors? groleo@gmail.com (Groleo) (2005-09-22) |
Re: How to parse and call c++ constructors? cfc@shell01.TheWorld.com (Chris F Clark) (2005-09-23) |
From: | Detlef Meyer-Eltz <Meyer-Eltz@t-online.de> |
Newsgroups: | comp.compilers |
Date: | 18 Sep 2005 00:43:36 -0400 |
Organization: | Compilers Central |
References: | 05-09-072 |
Keywords: | C++, parse |
Posted-Date: | 18 Sep 2005 00:43:36 EDT |
> Given a file,:
> A {
> B {
> text="cucu"
> }
> }
> So, to show the actions too:
> A { <-- a =new A();
> B { <-- a->_b =new B();
> text="cucu" <-- a->_b->text = $2;
> }
> }
> How can this be done without errors?
I assume, that you used a yacc grammar for parsing your file. Please
excuse, that I can't really help you with yacc, but I cannot resist to
take your example as a demonstration of a statement, which I just made
here a week ago: the integration of semantic code in LL-parsers is a
very intuitive task. Your example could be implemented by the
TextTransformer as follows:
A[aptr a] ::=
"A" {_ a =new A(); _}
"{"
B[a->_b]
"}"
B[bptr b] ::=
"B" {_ b =new B(); _}
"{"
"text" "=" STRING
{_
// the text is the first sub-expression of STRING
b->text = new char[State.length(1) + 1];
strcpy(b->text, State.str(1).c_str());
_}
"}"
( To make it more general, you could use a factory, which delivers an
adequate class pointer to a class name. )
Regards
Detlef Meyer-Eltz
--
mailto:Meyer-Eltz@t-online.de
url: http://www.texttransformer.de
url: http://www.texttransformer.com
Return to the
comp.compilers page.
Search the
comp.compilers archives again.