Let's stop parser Hell

Roman D. Boiko rb at d-coding.com
Sat Jul 7 13:39:15 PDT 2012


On Saturday, 7 July 2012 at 20:26:07 UTC, David Piepgrass wrote:
> I'd like to add that if we give tree parsing first-class 
> treatment, I believe the most logical approach to parsing has 
> three or more stages instead of the traditional two (lex+parse):
>
> 1. Lexer
> 2. Tree-ification
> 3. Parsing to AST (which may itself use multiple stages, e.g. 
> parse the declarations first, then parse function bodies later)
>
> The new stage two simply groups things that are in parenthesis 
> and braces. So an input stream such as the following:

I bet that after stage 2 you would have performed almost the same 
amount of work (in other words, spent almost the same time) as 
you would if you did full parsing. After that you would need to 
iterate the whole tree (possibly multiple times), modify (or 
recreate if the AST is immutable) its nodes, etc. Altogether this 
might be a lot of overhead.

My opinion is that tree manipulation is something that should be 
available to clients of parser-as-a-library or even of 
parser+semantic analyzer, but not necessarily advantageous for 
parser itself.


More information about the Digitalmars-d mailing list