Browse thread
yacc style
-
Chris King
-
Erik de Castro Lopo
-
skaller
-
Erik de Castro Lopo
- skaller
- Jean-Christophe Filliatre
-
Erik de Castro Lopo
-
skaller
- Chris King
-
Erik de Castro Lopo
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jean-Christophe Filliatre <Jean-Christophe.Filliatre@l...> |
| Subject: | Re: [Caml-list] yacc style |
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)