RSS Element,demiblog Class,Language,Link,Title,Description channel,,en_GB,http://tobyinkster.co.uk/tag/parsers/,"Articles Tagged with ""Parsers""", item,B,en_GB,http://tobyinkster.co.uk/blog/2007/02/10/parsers/,10/02/2007: Re: Parsing Question...,"
cjl wrote:
Short of writing a parser, which is clearly beyond me, what are some reasonable approaches to handling user input that will be executed?
Writing a parser is the best option in the long-run. If you were to attempt to interpret the user input some other way, like pure regular expressions, then you would fall into a lot of traps, and your interpreter would behave oddly in many cases.
A full parser is a much better option: it will behave far more reliably and would be a lot easier to extend, should you feel the need to add extra features to the language at a later date.
Although it’s a lot of work, there are some fairly well established methods on writing them. What you basically need to write is three fairly independent components: a tokeniser, a parser and an interpreter. None of these share any code in common, except for the definitions of a few constants and classes.
Firstly, a tokeniser, which reads the user input and splits it into a long list of tokens. Each token should have the…
"