| ▲ | stevefan1999 4 hours ago | |
Really I would love to know how parse context sensitive stuff like typedef which will have "switched" syntax for some tokens. Would like to know things like "hoisting" in C++, where you can you the class and struct after the code inside the function too, but I just find it hard to describe them in rigorous formal language and grammar. Hacky solution for PEG such as adding a context stack requires careful management of the entry/exit point, but the more fundamental problem is that you still can't "switch" syntax, or you have to add all possible syntax combination depending on the numbers of such stacks. I believe persistent data structure and transactional data structure would help but I just couldn't find a formalism for that. | ||
| ▲ | remexre 3 hours ago | parent [-] | |
https://en.wikipedia.org/wiki/Lexer_hack Make your parser call back into your lexer, so it can pass state to it; make the set of type names available to it. | ||