lark-parser / lark

Lark is a parsing toolkit for Python, built with a focus on ergonomics, performance and modularity.
MIT License
4.89k stars 414 forks source link

How to resolve tokens ambuguity? #596

Closed imihajlow closed 4 years ago

imihajlow commented 4 years ago

I use lark to parse a C-like language. Among other, it has operators && (boolean AND), & (bitwise AND), and & (address of). Since boolean AND has lower priority than the other two, when parsing expressions like a < b && c < d it gets parsed as (a < b) & (&c < d). Is there a way to force the lexer to always treat double ampersand as a single token? Or maybe there's another way to write my grammar? For the reference, the grammar for my language is here.

MegaIng commented 4 years ago

Use the 'lalr' parser. Your grammar is unambiguous, and 'lalr' automatically resolves this ambiguity.

imihajlow commented 4 years ago

Thank you. After a few modification to the grammar it worked with the LALR parser.