From: Angela Zhu <angela.zhu@cs.rice.edu>
To: Thomas Gazagnaire <thomas.gazagnaire@irisa.fr>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Problem with precedence declaration in .mly file
Date: Wed, 31 Oct 2007 09:40:25 -0500 [thread overview]
Message-ID: <11C06B30-EA78-40BB-984F-B403DC9BAE68@cs.rice.edu> (raw)
In-Reply-To: <47288DE3.3000603@irisa.fr>
[-- Attachment #1: Type: text/plain, Size: 2288 bytes --]
But here are all the precedence rules I have:
/***** Precedence Rules *****/
%left GT LT
%left PLUS MINUS
%left STAR DIVIDE
%left ATOB
%nonassoc prec_unary_minus
-Angela
On Oct 31, 2007, at 9:14 AM, Thomas Gazagnaire wrote:
> The following code works perfectly for me. Maybe you introduce some
> undesired precedence rules in your grammar rules.
>
>
> ----
>
> %token <int> INT
> %token PLUS MINUS DIVIDE STAR ATOB END
>
> %start main
> %type <int> main
>
> %left PLUS MINUS
> %left STAR DIVIDE
> %left ATOB
>
> %%
>
>
> main:
> | expr END { $1 }
>
> expr:
> | INT { $1 }
> | expr PLUS expr { $1 + $3 }
> | expr MINUS expr { $1 - $3 }
> | expr DIVIDE expr { $1 / $3 }
> | expr STAR expr { $1 * $3 }
> | expr ATOB expr { int_of_float ( (float_of_int $1) **
> (float_of_int $3) ) }
> ;
>
> ---
>
> And then "2^2+7\n" gives me "11"
>
> Cheers,
> Thomas
>
> Angela Zhu a écrit :
>> On Oct 31, 2007, at 6:52 AM, Peter Ilberg wrote:
>>>
>>> I have no experience with ocamlyacc, but looking at your grammar
>>> below, it seems that you don't need the 'value PLUS exp' etc
>>> rules. All these cases should be covered already by the 'exp PLUS
>>> exp' rules at the beginning and the 'value' rule at the end.
>>>
>>> Try removing the 'value PLUS exp' rules. Maybe ocamlyacc gets
>>> confused if it has two sets of productions that it has to
>>> disambiguate with precedence rules.
>> I removed 'value PLUS exp' rules.
>> The precedence is still not correct, what is more, 1+ t (with t
>> declared) gives a syntax error.
>> Thanks,
>> Angela
>>>
>>> --- Peter
>> _______________________________________________
>> Caml-list mailing list. Subscription management:
>> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
>> Archives: http://caml.inria.fr
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
[-- Attachment #2: Type: text/html, Size: 11070 bytes --]
next prev parent reply other threads:[~2007-10-31 14:40 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-30 14:00 Angela Zhu
2007-10-30 14:20 ` [Caml-list] " Oliver Bandel
[not found] ` <1193753915.47273d3bb15f2@webmail.in-berlin.de>
2007-10-31 4:11 ` Angela Zhu
2007-10-31 4:26 ` Angela Zhu
2007-10-31 5:52 ` skaller
[not found] ` <BE3BA36D-7E69-426F-B558-26CBCF9D78F6@cs.rice.edu>
[not found] ` <1193814307.8355.68.camel@rosella.wigram>
2007-10-31 7:16 ` Re: " Angela Zhu
2007-10-31 11:52 ` Peter Ilberg
2007-10-31 13:51 ` Angela Zhu
2007-10-31 14:14 ` Thomas Gazagnaire
2007-10-31 14:40 ` Angela Zhu [this message]
[not found] ` <472894EC.8040902@irisa.fr>
[not found] ` <F5672A31-E4C0-488B-B594-F75E3DA262D8@cs.rice.edu>
[not found] ` <47289C47.8020609@irisa.fr>
2007-10-31 15:34 ` Angela Zhu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11C06B30-EA78-40BB-984F-B403DC9BAE68@cs.rice.edu \
--to=angela.zhu@cs.rice.edu \
--cc=caml-list@yquem.inria.fr \
--cc=thomas.gazagnaire@irisa.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).