Writing a Parser
Jascha Wetzel
firstname at mainia.de
Fri Jan 4 23:25:21 PST 2008
Dan wrote:
> I've been messing with how to write a parser, and so far I've played with numerous patterns before eventually wanting to cry.
>
> At the moment, I'm trying recursive descent parsing.
>
> The problem is that I've realized I'm duplicating huge volumes of code to cope with the tristate decision of { unexpected, allow, require } for any given token.
>
> For example, to consume a for loop, you consume something similar to
> /for\s*\((.*?)\)\s*\{(.*?)\}/
>
> I have it doing that, but my soul feels heavy with the masses of looped switches it's doing. Is there any way to ease the pain?
a parser generator :)
writing a parser or scanner manually is a bit like writing any program
in assembler - tedious, error-prone and not well maintainable. there's a
lot of stuff in a parser that can be automatically generated.
even if you want to write the parser all by yourself, i'd rather suggest
you write a simple parser generator to do that tedious part for you.
More information about the Digitalmars-d-learn
mailing list