[mercury-users] Mercury grammar definition

Gabor Bakos aborgabor at gmail.com
Tue Jul 3 00:01:40 AEST 2012


On 2012.07.02. 2:41, Richard O'Keefe wrote:
> 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. 
You are right, it is easy to distinguish between them, but not with the
rules described on the Terms.html
<http://www.mercury.csse.unimelb.edu.au/information/doc-release/mercury_ref/Terms.html>
and the Builtin-Operators.html
<http://www.mercury.csse.unimelb.edu.au/information/doc-release/mercury_ref/Builtin-Operators.html#Builtin-Operators>
disagree with the precedence rules. It was not too hard to make this
change
<https://gist.github.com/3025801/2b48f39914721191f0f3cad9ad2c2520a62bfbf5>,
just I am not sure it will be ok. (The previous versions could not
properly parse expressions like ":- pred main(io::di, io::uo) is det.",
because of the precedence rules, or maybe I did something wrong during
the formulation.)

>> - 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.
Thanks, this was not clear from the reference.
>   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.
Interesting, so ./* is a possible operator, but .% is not? That's good
to know.
> 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.
Yeah, I did know about this from Prolog, but I thought in Mercury these
are more limited, ex. they can have only precedence 120, they should be
between backquotes ("a name, a module qualified name (see The module
system
<http://www.mercury.csse.unimelb.edu.au/information/doc-release/mercury_ref/The-module-system.html#The-module-system>),
or a variable between grave accents (backquotes)"). Could you please
provide a link to this definition?
Thanks, gabor

PS.: I still have problems with the precedence 950 fxy parts, because of
the prefix and infix + (-?) operators.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20120702/6d0afda3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4462 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.mercurylang.org/archives/users/attachments/20120702/6d0afda3/attachment.bin>


More information about the users mailing list