[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: XML file formats .... was: Re: gEDA-user: Some footprints I tried to create
On Mar 15, 2007, at 8:32 AM, Evan Lavelle wrote:
However, I ended up implementing a flat, lexer-only solution,
which of course is possible only with reverse polish notation.
So, if
you need a *small*, truely extensible (trivial, even), and easy to
write parser, that doesn't require even more complexities like
bison/yacc (not all platforms have them), then you might want to
consider the RPN option as well.
<pedantic_warning>
A lexer just tokenises an input stream for you; it matches the
input against a set of regular expressions that you specify, and
lets you execute some code when it finds a match.
You could, in principle, implement an RPN (postfix) calculator
using something like lex, by just pushing matched tokens onto a
stack and popping them off when you match an operator. IMHO,
though, this would be pretty pointless. You might just as well
match "a + b" or "+ a b" and make a note to carry out evaluation
one or two tokens after the '+', instead of immediately. This then
gives you an infix or a prefix calculator, rather than a postfix
one. There's nothing special about the RPN case - it's just
marginally easier to implement, at the expense of readability.
In practice, it's trivial (and normal) to just pass the matched
tokens to a parser such as yacc, which lets you check the structure
of the input, recover from errors, distinguish unary from binary
operators, evaluate complex expressions with precedence and
associativity, and so on. It's very difficult to build any smarts
into a lexer-based solution, but easy when you've got a parser on top.
Where RPN is useful is where you have (very) simple stack-based
hardware, hence the usage in calculators.
</pedantic_warning>
Evan
Using the standard Unix compiler development tools for a Forth is
swatting fles with a cannon.
John Doty Noqsi Aerospace, Ltd.
jpd@xxxxxxxxx
_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user