Can someone explain this to me? In particular the difference between:
http://github.com/whymirror/greg and http://piumarta.com/software/peg/
The former being a re-entrant version of the later.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
At its simplest a re-entrant parser doesn’t use global variables and thus can have multiple instances active at the same time (not necessarily related to threading, but this is the main use case I suspect).
In more complex use cases, however, you can have a parser that parses, in effect, multiple languages in the same source document. Consider a JSP parser, for example, that has to parse Java code and HTML in the same file. Instead of making one huge parser that covers both languages (something likely highly impractical) you can make two parsers and switch between them. If your parsers, however, use global state switching between them could be problematical. A re-entrant parser allows you to switch between parsers easily, either in the form of coroutines or in simple “parser-A calls parser-B for embedded code and then returns” situations.
Edited to add:
If you want an extreme form of re-entrant parsing, take a look at parser combinators (like Parsec) where each sub-expression in the “grammar” is a separate parser entirely. You build a large parser by combining a myriad of small ones.