[mercury-users] Mercury grammar definition

Richard O'Keefe ok at cs.otago.ac.nz
Mon Jul 2 10:41:32 AEST 2012


On 1/07/2012, at 10:39 AM, Bakos Gábor wrote:
> - The comments are not defined anywhere, (I guess it was handled by
> referring to ISO Prolog), could you confirm, that those are the % single
> line, and non-nesting /*, */ comments (and there is no more)?

Yes.

> - Do the comments act as a whitespace? (I guess yes, but as comments
> not mentioned anywhere, this might be just an implementation choice.)

Yes.

> - How could be the built-in , be distinguished from the argument's
> comma? (I tried to define the arguments as simple terms, but the
> precedence rules make it not working for the basic hello world program.
> See: https://gist.github.com/3025801 you can open it with AntlrWorks for
> syntax highlight, and navigation. When I tried to defined as simple left
> associative terms separated by comma, there were ambiguity errors
> because of the other alternative.)

I find it hard to imagine a parser that would confuse them.
Commas can occur in three contexts:

	f( .... , ... )

    where f is an atom immediately adjacent to a left parenthesis;

	[ ... , ... ]

    where the comma separates list elements;

	... , ...

    anywhere else.

> - I think the . has also double meaning, but maybe I do misunderstand
> something:

Yes.  A token that is a dot followed by white space is an end of term
token; other dots are not.  Tokens may be made of sequences of symbols
like ++, +*@, and even .. and ./* are possible tokens.  However, such
a sequence may not include %, so we'd expect "x.% foo!" to be a well
terminated clause as it is in Prolog.

Like Prolog, Mercury allows user-defined operators, so it is not clear
to me how you can build an LL(1) parser unless it can process those
declarations.


--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list