caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@lri.fr>
To: Erik de Castro Lopo <ocaml-erikd@mega-nerd.com>
Cc: <caml-list@inria.fr>
Subject: Re: [Caml-list] yacc style
Date: Fri, 28 Jan 2005 10:04:15 +0100	[thread overview]
Message-ID: <16890.15.809674.392193@gargle.gargle.HOWL> (raw)
In-Reply-To: <20050128132812.7001512c.ocaml-erikd@mega-nerd.com>


Erik de Castro Lopo writes:
 > skaller <skaller@users.sourceforge.net> wrote:
 > > On Fri, 2005-01-28 at 08:39, Erik de Castro Lopo wrote:
 > > >
 > > > Yes, normally the parser generates a parse tree which is then
 > > > passed to the semantic analyser for semantic checking.
 > > 
 > > Unfortunately this is useless in the common case
 > > of needing to parse C.
 > 
 > Could you give a example?

When parsing C, the lexer  must produce different tokens for variables
identifiers  and  types identifiers,  otherwise  you may  misinterpret
things  like "a  * b"  (is it  the  declaration of  a pointer  b or  a
multiplication?) or casts. The following piece of code is illustrating
the difficulty:

======================================================================
int a, b;
typedef int t, u;
void f1() { a * b; }
void f2() { t * u; }
void f3() { t * b; }
void f4() { int t; t * b; }
void f5(t u, unsigned t) {
  switch ( t ) {
  case 0: if ( u )
    default: return;
  }
}
======================================================================

The  solution  is  to  have  the  parser  modifying  the  lexer  while
parsing. This is quite ugly in practice. The CIL framework includes a
full C parser written in ocaml, so you can get there one possible way
of handling this issue; see http://manju.cs.berkeley.edu/cil/

Hope this helps,
-- 
Jean-Christophe Filliâtre (http://www.lri.fr/~filliatr)


  parent reply	other threads:[~2005-01-28  9:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-27 20:17 Chris King
2005-01-27 21:39 ` [Caml-list] " Erik de Castro Lopo
2005-01-28  1:14   ` skaller
2005-01-28  2:28     ` Erik de Castro Lopo
2005-01-28  4:30       ` skaller
2005-01-28  9:04       ` Jean-Christophe Filliatre [this message]
     [not found] ` <200501272252.43720.jon@jdh30.plus.com>
2005-01-28  0:41   ` Chris King

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=16890.15.809674.392193@gargle.gargle.HOWL \
    --to=jean-christophe.filliatre@lri.fr \
    --cc=caml-list@inria.fr \
    --cc=ocaml-erikd@mega-nerd.com \
    /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).