caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Angela Zhu <angela.zhu@cs.rice.edu>
To: skaller <skaller@users.sourceforge.net>
Cc: caml-list@yquem.inria.fr
Subject: Re: Re:  Re: [Caml-list] Problem with precedence declaration in .mly  file
Date: Wed, 31 Oct 2007 02:16:07 -0500	[thread overview]
Message-ID: <117B8C1B-3586-4A77-B3B6-5FF881BE8B62@cs.rice.edu> (raw)
In-Reply-To: <1193814307.8355.68.camel@rosella.wigram>

Thanks a lot for your detailed explanation.
The problem is that now the AST for my language is getting really big.
I am not sure how much work it will take.

Best regards,
Angela
------------------------------------------
Dept. of CS, Rice Unitersity
http://www.cs.rice.edu/~yz2/
------------------------------------------



On Oct 31, 2007, at 2:05 AM, skaller wrote:

>
> On Wed, 2007-10-31 at 01:02 -0500, Angela Zhu wrote:
>>>
>>>
>>> DO NOT USE THEM. The rules are hard to explain and very badly
>>> designed, in other words, they're a hack. Ocaml provides
>>> them for compatibility with older yacc like tools.
>>>
>>> Write your grammar properly instead, in pseudo code:
>>>
>>> 	term = factor | term + factor
>>> 	factor = atom | factor * atom
>>> 	atom = INTEGER | ( term )
>>
>> ... Then I need to change my whole AST.....
>> :(
>
> Yes, that's possible. The 'simple' AST isn't efficient,
> that is, where you have a variant
>
> 	type term = Term_Factor of factor | Term_plus of term * factor
>
> because of the first case. However this isn't necessary if you just
> use something like
>
> 	type expr = Integer of int | Apply of string * expr list
>
> then you can just do:
>
> 	term:
> 	| factor { $1 }
> 	| term + factor { Apply  ("+",[$1;$3]) }
>
> and similarly for the other productions. The typing here
> is weaker than you may want, for example you can get
> nonsense like
>
> 	Apply ["*",Integer 1]
>
> so you might try a safer encoding, eg using
>
> 	| Integer of int
> 	| Unary of string * expr
> 	| Binary of string * expr * expr
> 	
>
> The point is, this AST is still less structured than one
> which exactly reflects the syntax tree -- but that is the
> point of an 'Abstract' syntax tree (AST).
>
> Exactly how much work you do in the parser is a difficult
> design choice.
>
>
> -- 
> John Skaller <skaller at users dot sf dot net>
> Felix, successor to C++: http://felix.sf.net
>


  parent reply	other threads:[~2007-10-31  7:16 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           ` Angela Zhu [this message]
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
     [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=117B8C1B-3586-4A77-B3B6-5FF881BE8B62@cs.rice.edu \
    --to=angela.zhu@cs.rice.edu \
    --cc=caml-list@yquem.inria.fr \
    --cc=skaller@users.sourceforge.net \
    /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).