I'm writing a parser for a subset of C++. I know it's extremely hard
to do correctly, but I'm not trying to do it correctly - just good
enough to do some "smarter search and replace" on some code. That is,
I don't need the AST to capture every little detail of the program.

That said, I'm having trouble with ambiguity in the grammar. In
particular, I can't parse both of these correctly :

        A = (B*C);
        A = (int)C;

When the parser sees B* it doesn't know whether it's the beginning of
an expression or a cast. It assumes it's a cast so it gets confused by
the C token.

I'm not sure why is this ambiguous, since the cast ends with a ), not
with an expression. I'm not an expert in parsers, as you can see.

I don't know whether to fix the grammar (or how), or to handle this
with an error token and somehow manipulate the parser stack to force
it to go for the correct interpretation (I don't know exactly how to
do this, either).

Any help or comments will be extremely appreciated.

Thanks,
--Gabriel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ply-hack" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/ply-hack?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to