[Mono-dev] Mono-devel-list Digest, Vol 72, Issue 10
tspink at gmail.com
Thu Apr 7 15:21:01 EDT 2011
2011/4/7 Chris Seaton <chris at chrisseaton.com>:
> Just be aware that not all grammars can express all languages, and so not all parser-generators can parse all languages. GNU Make does not use a parser-generator to parse Makefiles - perhaps there's a good reason. You say that a lexer for Make would be very context-dependent, and most parse-generators don't handle that well at all.
Good points! But, there are tools available that make
context-sensitive lexing and parsing much easier - flex and bison, for
> Generally, parsing is a pretty simple problem in the first place and I think that parser-generators often introduce more problems than they solve. Why can't you nest block comments in C? Because of a limited lexer-generator.
Well - okay... but you can use a better lexer generator. Writing
lexers and parsers by hand does have it's merits - for both academic
and practical reasons (e.g. at University, I thoroughly enjoyed making
a finite-state-machine based lexer, and writing an LALR parsing table
by hand), but when tools that are purpose built for solving a complex
problem - because in fact parsing /is/ a complex problem - then those
tools should be utilised as an aid to reduce the amount of time you
have to spend debugging and altering your own implementation.
The reason I say that parsing /is/ a complex problem is because
parsing isn't just about matching input to a specified grammar, it's
also about building a data structure describing what the input is
representing, and giving feedback when the input does not conform to
syntax. Taking into account this, although it seems that all you're
trying to do is recognise input, it's actually quite complicated when
you start having to deal with and process this input.
> Do a quick google for a Make grammar for Antlr or Jay and see if anyone else has managed it.
I presume you mention this because there aren't any.
Touche, Chris. ;-)
> Chris Seaton
More information about the Mono-devel-list