3 ms·
> If the problem is a misspelled or out of scope identifier, the parser should should still be able to parse the program That's not necessarily true for all la
by nokcha 9y ago
> If the problem is a misspelled or out of scope identifier, the parser should should still be able to parse the program
That's not necessarily true for all languages. For example, in C, "(e1)&e2" is parsed differently depending on how e1 is declared. If e1 is declared as
typedef int* e1;
then the "&" in "(e1)&e2" is parsed as the address-of operator, but if e1 is declared as
int e1;
then "(e1)&e2" is parsed as a bitwise AND.
- swift 9y agoThis is a problem for a lot of languages, unfortunately, and it breaks the clean separation between syntax and semantics that we're hoping for when we write a formal grammar. I've had some success in the past with using GLR or another algorithm that can handle ambiguity, and then choosing among the possible parse trees in another pass that takes semantic information into account. How applicable that is really depends on the language, though; if things are so ambiguous that you're getting an exponential growth in possible parse trees, you may not want to use this approach.