Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] parsing forward references in ocamlyacc and other ocamlyacc questions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-09-05 (09:18)
From: Rafael 'Dido' Sevilla <dido@i...>
Subject: [Caml-list] parsing forward references in ocamlyacc and other ocamlyacc questions
I'm just wondering how you can guarantee that certain imperative effects
occur, like adding a name into a symbol table hash.  I'm writing a
compiler whose semantics allow some limited forward references, e.g.:

adt_declaration: IDENTIFIER COLON ADT OBRACE adt_member_list CBRACE SEMI

where the rules under the adt_member_list nonterminal have access to the
identifier name given in the ADT declaration.  For the original Yacc or
Bison, it can be done with an intermediate semantic action like:

adt_declaration: IDENTIFIER COLON ADT { Hashtbl.add symtable $1 ... } OBRACE ...

Something like (which is how you would do it without the use of
intermediate actions):

adt_name: IDENTIFIER COLON ADT { Hashtbl.add symtable $1 adt_skel; $1 }

adt_declaration: adt_name OBRACE adt_member_list CBRACE SEMI { ... }

doesn't seem to work.  The symbol table addition still doesn't occur
until after the entire adt_declaration has been parsed.  The
documentation for ocamlyacc has very little to say about it (unless
there's more documentation in other places besides the ocaml manual).

I'll also ask how I would go about processing file inclusion in
ocamlyacc using ocamllex...

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: