* [Caml-list] parsing forward references in ocamlyacc and other ocamlyacc questions
@ 2003-09-03 5:31 Rafael 'Dido' Sevilla
2003-09-05 12:07 ` Eckart Goehler
2003-09-05 20:56 ` Michal Moskal
0 siblings, 2 replies; 3+ messages in thread
From: Rafael 'Dido' Sevilla @ 2003-09-03 5:31 UTC (permalink / raw)
To: ocaml_beginners
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 caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] parsing forward references in ocamlyacc and other ocamlyacc questions
2003-09-03 5:31 [Caml-list] parsing forward references in ocamlyacc and other ocamlyacc questions Rafael 'Dido' Sevilla
@ 2003-09-05 12:07 ` Eckart Goehler
2003-09-05 20:56 ` Michal Moskal
1 sibling, 0 replies; 3+ messages in thread
From: Eckart Goehler @ 2003-09-05 12:07 UTC (permalink / raw)
To: caml-list, Rafael 'Dido' Sevilla
Hi,
On Wed, 3 Sep 2003, Rafael 'Dido' Sevilla wrote:
> 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.:
...
> 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).
As far as I understand ocamlyacc behaves as the original yacc (but not
bison).
> I'll also ask how I would go about processing file inclusion in
> ocamlyacc using ocamllex...
Tricky. Calling the parser function "main" from within the parser does not
work currently with ocamlyacc. I tried this myself and ended in patching
ocamlyacc:
- the main function generated by ocamlyacc has to be recursive (let rec
main = ...).
- the parser table written out has to be defined before the main function.
- because ocamllex needs the token information but must be defined
*before* the parser (otherwise you can't recursively call ocamllex) the
token have to be written into a different file (for foo.mly I choosed
the output file name to be footoken.ml/footoken.mli).
But file inclusion is a bit difficult because you can't always be shure
that the processing order is kept (mentioned by the main problem you have:
imperative features while parsing.
Maybe the patch should be implemented in ocamlyacc
eckart
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] parsing forward references in ocamlyacc and other ocamlyacc questions
2003-09-03 5:31 [Caml-list] parsing forward references in ocamlyacc and other ocamlyacc questions Rafael 'Dido' Sevilla
2003-09-05 12:07 ` Eckart Goehler
@ 2003-09-05 20:56 ` Michal Moskal
1 sibling, 0 replies; 3+ messages in thread
From: Michal Moskal @ 2003-09-05 20:56 UTC (permalink / raw)
To: Rafael 'Dido' Sevilla; +Cc: caml-list
On Wed, Sep 03, 2003 at 01:31:14PM +0800, Rafael 'Dido' Sevilla wrote:
> 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).
Are you *sure*? From what I know about yacc parser, this action *had* to
be taken before adt_member_list was parsed.
--
: Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv
: When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-09-05 20:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-03 5:31 [Caml-list] parsing forward references in ocamlyacc and other ocamlyacc questions Rafael 'Dido' Sevilla
2003-09-05 12:07 ` Eckart Goehler
2003-09-05 20:56 ` Michal Moskal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox