[Mono-dev] Mono-devel-list Digest, Vol 72, Issue 10
Chris Seaton
chris at chrisseaton.com
Thu Apr 7 14:43:50 EDT 2011
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.
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.
Do a quick google for a Make grammar for Antlr or Jay and see if anyone else has managed it.
Regards,
Chris Seaton
On 7 Apr 2011, at 19:30, Tom Spink wrote:
> On 7 April 2011 05:56, Sharp BladeÎÞºñÖ®ÈÐ <sharper.than.bladez at gmail.com> wrote:
>> Hello!
>>
>> Well,since I have a lot of experience with Antlr on C#,it does not
>> seem to be a good choice to use jay.And the makefile grammar is quiet
>> simple,I wonder if I could write the parser by hand.
>>
>> Sharp
>
> Hello!
>
> Unfortunately, the Makefile grammar is not as simple as you think, and
> simple or not, writing parsers by hand is generally discouraged
> nowadays, for the simple reason of:- why re-invent the wheel?
>
> There are tools available for parser (and lexer) generation, which are
> tried and tested and I think you'll find you'll make more mistakes
> rolling your own parser, than you'll get if you use a parser
> generator.
>
> Also, writing an LALR, LR(1) or indeed any bottom-up parser by hand is
> quite challenging - even for the simplest grammars. If you really
> went down this route, you'd be best off writing a top-down parser,
> which can exponentially increase in size as a grammar increases. But,
> I still wouldn't recommend it, as the more you get into the grammar,
> the more you'll find yourself changing your parser and wishing you'd
> used a generator.
>
> You'll also need to construct a lexer for the Makefile - which is
> itself a daunting challenge. Particularly because the Makefile syntax
> is really quite complex (since it's heavily context-based), so you'd
> have trouble implementing a lexer and parser yourself.
>
> Hope this helps,
>
> -- Tom.
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
More information about the Mono-devel-list
mailing list