* [Caml-list] Calling parser from inside a parser rule
@ 2004-09-17 22:22 James Lamanna
0 siblings, 0 replies; 3+ messages in thread
From: James Lamanna @ 2004-09-17 22:22 UTC (permalink / raw)
To: caml-list
Is it possible to call the parser from inside a parser rule?
For instance lets say I have a grammar rule which accepts
"load [filename]"
Now inside this rule, I want to open the file, and parse all the
commands in that file using that same parser.
Is there a way to do this?
Thanks.
--
James Lamanna
-------------------
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] Calling parser from inside a parser rule
@ 2004-09-19 15:50 James Lamanna
2004-09-20 8:52 ` Damien Pous
0 siblings, 1 reply; 3+ messages in thread
From: James Lamanna @ 2004-09-19 15:50 UTC (permalink / raw)
To: jamesl, skaller; +Cc: Jon Harrop, caml-list
On Sat Sep 18 20:52 , skaller <skaller@users.sourceforge.net> sent:
>On Sun, 2004-09-19 at 03:46, James Lamanna wrote:
>> {
>> let f = open_in $2 in
>> let lexbuf = Lexing.from_channel f in
>> let rec parse_file _ =
>> try
>> List.rev_append (main Lexer.token lexbuf) (parse_file () )
>> with _ -> []
>> in
>> parse_file ()
>> }
>>
>> which obviously doesn't work
>> because main (the parser main function) isn't defined yet.
>
>Do you mean, how to cope with the lack recursion across
>translation units?
>
Essentially.
I want to be able to recurse into my parser.
Thanks.
--
James Lamanna
-------------------
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] Calling parser from inside a parser rule
2004-09-19 15:50 James Lamanna
@ 2004-09-20 8:52 ` Damien Pous
0 siblings, 0 replies; 3+ messages in thread
From: Damien Pous @ 2004-09-20 8:52 UTC (permalink / raw)
To: caml-list
hi,
why don't you recurse before the parser level ?
lexer.mll:
<<
{ type token = [`Print | `Arf | `Eof] }
let blank = [' ' '\r' '\t' '\n']*
let word = [ 'a'-'z' '.' ]*
rule token = parse
| blank { token lexbuf }
| "#include" blank '"' (word as s) '"' { `Include s }
| "print" { `Print }
| "arf" { `Arf }
(* ... *)
| eof { `Eof }
>>
reclexer.mll
<<
let token lexbuf: unit -> Lexer.token =
let acc = ref [lexbuf] in
let rec aux () = match !acc with
| [] -> `Eof
| (x::q) as l ->
match Lexer.token x with
| `Include s -> acc := (Lexing.from_channel (open_in s))::l; aux()
| `Eof -> acc := q; aux()
| #Lexer.token as t -> t
in aux
>>
let t = token (Lexing.from_channel (open_in "toto"));;
t();;
t();;
...
of course you have to handle cyclic includes...
damien
On Sun, 19 Sep 2004 08:50:42 -0700
James Lamanna <jamesl@appliedminds.com> wrote:
> Essentially.
> I want to be able to recurse into my parser.
-------------------
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:[~2004-09-20 8:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-17 22:22 [Caml-list] Calling parser from inside a parser rule James Lamanna
2004-09-19 15:50 James Lamanna
2004-09-20 8:52 ` Damien Pous
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox