[Haskell-beginners] A Pascal-like Language Compiler
Joel Björnson
joel.bjornson at gmail.com
Thu Oct 23 11:35:46 EDT 2008
Hi,
On Thu, Oct 23, 2008 at 3:37 PM, Larry Evans <cppljevans at suddenlink.net> wrote:
> Does BNFC calculate the lookahead sets for a grammar?
> I'm attempting to do this with haskell, but I would hate
> to "reinvent the wheel". I would think if haskell can tranform
> a syntax tree, then haskell could transform a grammar tree
> to calculate the lookahead sets. My purpose it not so much
> create a compiler as illustrate how it's done. I found the
> Dragon's book description hard to follow and thought
> redoing it using functors (to transform the tree into
> another, with different operators) then simplify the
> transformed trees (one tree for each lookahead set)
> then find the fixpoint of those trees (really forest:
> 1 tree for each production) would be a good way
> to demonstrate the method.
As stated at the BNFC web page, "BNFC is a compiler compiler
compiler", i.e. it generates specifications for other lexers and
parsers based on the given grammar (expressed in Backus Nour Form).
In Haskell mode it outputs specifications for Alex[1] and Happy[2]
which in turn can be used to generate haskell code for lexing and
parsing.
So if I understood you correctly, I think the answer to your question
is no. But maybe you wanna have a look the haskell parser code
generated by Happy? Unfortunately I really don't know anything about
the implementations of either BNFC or Happy, so I'm sure others may
provide you with more insightful explanations.
- Joel
[1] http://www.haskell.org/alex/
[2] http://www.haskell.org/happy/
More information about the Beginners
mailing list