[m-dev.] for review: Add "moose" to extras.
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri May 19 18:39:04 AEST 2000
On 19-May-2000, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
>
> Tom has written a parser generator for Mercury called "moose".
> I recently used this to implement a parser for all of C, and it works
> pretty well.
>
> I added some code to generalize the "actions" -- each action now
> generates a type class method in the parser_state type class.
> One method must be provided in every parser_state, and that is the
> "get_token" method. This way you can pass a parser state along that is
> as complicated as you like, just make it an instance of the type
> class. Also you can re-use the same parser with different instances of
> parser_state to do different tasks.
>
> Everything else is Tom's work. Outstanding issues before I commit:
> - licensing (GPL I guess, but it's polite to ask first)
> - finding out how much time Tom spent on this.
> - is the TODO document up-to-date
>
> If anyone feels like reviewing this:
>
> There is no documentation and almost no comments in the code.
> However most of it is similar to the LR parser stuff in the Dragon book.
> There are some examples. I have a C parser that I will add to extras
> soon, it will probably provide a pretty good example of what you can do
> with this system. I don't intend to write documentation or add comments
> to the code.
That looks OK. But it would be much much better if there was
some general documentation that at very least explained what
Moose is. Also if you're going to add Moose to the extras,
you should mention it in the extras/README file.
I had a look at the source code and examples and managed to figure out
a bit about what this program does. So here's a start at some
user documentation for it. It would be good if you could include
this when you commit it. It would be even better if the XXXs
in it got fixed ;-)
BTW, what category of grammars does Moose handle?
Is it LR(0), LR(1), LR(k), ...?
----------------------------------------------------------------------
Moose is a parser generator for Mercury.
It does the same sort of thing for Mercury that Yacc and Bison do for C.
Moose input files should be given a `.moo' suffix.
Moose input files contain Mercury code plus some additional
kinds of declarations and clauses that specify a grammar.
The `moose' program takes a Moose input file and converts it into
ordinary Mercury code.
Each Moose input file should contain:
- One Moose parser declaration, of the form
:- parse(<StartSymbol>, <EndToken>, <TokenType>, <Prefix>).
Here <StartSymbol> is the name of the starting symbol for the grammar,
<EndToken> is the token that signifies end-of-file,
<TokenType> is the name of the Mercury type for tokens in this grammar,
and <Prefix> is unused. (XXX we should change the syntax to
delete the <Prefix> argument here, since it is not used.)
- One or more Moose rule declarations, of the form
:- rule <Name>(<ArgumentTypes>).
A `:- rule' declaration declares a non-terminal symbol in the grammar.
Here <Name> is the name of the non-terminal symbol, and
<ArgumentTypes> gives the types of the arguments (i.e. attributes)
of that non-terminal.
- One or more Moose clauses.
The Moose clauses specify the productions for this grammar.
Each must be of the form
<NonTerminal> ---> <ProductionBody>.
Here <NonTerminal> is of the form <Name> or <Name>(<Arguments>),
where <Name> is the name of the non-terminal symbol, and
<Arguments> specify the arguments (i.e. attributes) for
that non-terminal.
<ProductionBody> must of one of the following forms:
[<TerminalList>]
<NonTerminal>
<ProductionBody> , <ProductionBody>
<ProductionBody> ; <ProductionBody>
{ <Action> }
[<TerminalList>] denotes a list of terminal symbols.
Each of the terminal symbols must be an element of the token type
specified in the `:- parse' declaration. The list can be empty.
<NonTerminal> denotes a non-terminal. Each non-terminal must be
declared with a `:- rule' declaration.
<Production> , <Production> denotes sequence.
<Production> ; <Production> denotes alternatives.
{ <Action> } denotes a grammar action. Here <Action> is an arbitrary
Mercury goal. Grammar actions can impose semantic conditions,
or can be used to compute attributes.
- One or more Moose action declarations, of the form
:- action(<Name>/<Arity>, <PredicateName>).
I'm not sure what these declarations mean.
(XXX we should document what those declarations do.)
(XXX we should also document the parser_state type class
and the get_token method.)
----------------------------------------------------------------------
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list