The stupid question is the question not asked | |
PerlMonks |
Re: A minilanguage with the least effort?by ELISHEVA (Prior) |
on Feb 17, 2009 at 14:34 UTC ( [id://744420]=note: print w/replies, xml ) | Need Help?? |
The simplest parser begins with the simplest language design. A language that has a one token (or even two) look-ahead will always be easier to parse than a language that requires consuming long runs of tokens before you know what the run means. For example, suppose we had a language that looked like this:
Language samples would look like this:
and a parser (sans error detection) could be as simple as this:
Of course, for production purposes you would probably want to do some error checking. Also you might want to make certain combinations of verbs and targets illegal. For example, it doesn't make much sense to "WALK A FISH". And if you really want to get fancy you can explore the wonderful world of lexers. But hopefully this will illustrate the basic idea. I wanted to provide you with a link to an easy to understand non-jargon filled article on designing an easy to parse language, but I'm having little luck googling for that. Perhaps another Monk with better search term fu can help you with that. Best, beth
In Section
Seekers of Perl Wisdom
|
|