[antlr-interest] ambiguity

Anthony Brenelière abreneliere at telys.com
Tue Jul 8 01:52:34 PDT 2003



> -----Message d'origine-----
> De : Adrian Sandor [mailto:aditsu at yahoo.com]
> Envoyé : mardi 8 juillet 2003 10:42
> À : antlr-interest at yahoogroups.com
> Objet : [antlr-interest] ambiguity
> 
> 
> I'm trying to parse C++ source code (for writing a formatter), and I
> stumbled on a problem
> take a look at this program:
> 
> //---snip
> int f(int x){return x;}
> typedef char c;
> 
> int main()
> {
> int x=5, y;
> y=(f)(x);
> y=(c)(x);
> }
> //---snip
> 
> it compiles ok, and look at the last 2 instructions: lexically they
> are identical, but semantically the first one is a function call and
> the second one is a cast
> the question is.. how should I write the parser? should I still try
> to distinguish the 2 instructions, or should I treat them the same
> way sintactically? (for this project it could be ok)
> 
> thanks
> 
> Adrian
> 

It depends on the actions you have to perform for each case. If actions
are different for each case, you should differentiate them semantically,
if they are identical, you don't have to.

To distinguish them semantically, you should ask the question : how
should an instruction be identified as a cast or as a function call ?

Cordially,
Anthony Breneliere


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list