[antlr-interest] ambiguous parsing

William B. Clodius wclodius at los-alamos.net
Tue Feb 2 19:20:17 PST 2010


I hope you are wrong about the lexical ambiguity, as it is probably nasty to handle. This sort of thing is really best handled by semantic analysis, not by syntactical analysis. You will have a lexical category that can be either an identifier or a hexadecimal number. Then you will have to check whether the specific instance only has the characters that allow it to be potentially interpreted as a hexadecimal, if it has that potential interpretation then determine whether the context requires an identifier, in which case it is an identifier, whether the context requires a hexadecimal string, or as appears to be possible, whether the context allows both. If both you will need either an ad hoc method to disambiguate, or report the ambiguity with suggestions to the user as to how to remove it.

On Feb 2, 2010, at 11:03 AM, Hugo wrote:

> hi, sorry for this basic question but i try to parse a specific language.
> 
> my problem is that my language could have :
> 
> a variable declaration like this:
> 
> var tmp = ABCDEF09   where ABCDEF09 is considered as hexadecimal string
> 
> and a function declaration like this
> 
> func ABCDEF09 where ABCDEF09 is considered as normal user defined 
> function identifier
> 
> my question is how could i make the distinguish between this 2 case
> 
> thanks a lot
> 
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 



More information about the antlr-interest mailing list