[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: seeking an OO or functional parser generator for Java
Seth Gordon wrote:
> a decent parser generator in Java that uses Java objects, not text
> files with snippets of Java code, to describe the grammars.
The functional world has long used parser combinators as an easily
graspable motivation to monads. There's no reason(*) why something
similar couldn't be done in OO.
* well, actually there are two reasons not to do it this way:
1) The performance is rather abysmal, anecdotally, but I don't know if
that's inherent, or merely an artefact of them often being toy parsers.
2) Building a parser via a sequence of explicit constructor calls seems
a rather painful prospect.
A completely different approach is to not describe any semantic actions
at all in your parser (thus avoiding snippets of java), and to then use
a visitor to fix up the generated AST. If you like Aspects, this may be
a good use of them, in that you could fire an advisable event after
parsing some kind of syntax tree node, and allow the advice to perform
whatever semantic action that node requires.