![]() |
|
XP is just a number | |
PerlMonks |
Re: Parsing CCL (Common Command Language) commandsby mugwumpjism (Hermit) |
on Oct 17, 2002 at 11:46 UTC ( #205989=note: print w/replies, xml ) | Need Help?? |
Left logical grammars such as you have listed are very mechanically converted to `recursive descent' parsers. You might want to check out Parse::RecDescent. You should be able to go straight from your grammar to a working parser. Otherwise, make yourself a next_token(), an eat_token() function, and to make things easier, a save_position() and restore_position() pair to allow you to easily put already eaten tokens back onto the front of the stream (not necessary with some grammars, see books on recursive descent and LL grammars for more) and write code like this:
I think it should be fairly obvious why you'd want a module (or flex/yacc) to write this for you for larger grammers, but every programmer should write at least one recursive descent parser :-).
In Section
Seekers of Perl Wisdom
|
|