[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
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
_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user