Version française
Home     About     Download     Resources     Contact us    
Browse thread
multiple %start symbols in parser
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Will Leiserson <wml@a...>
Subject: Re: [Caml-list] multiple %start symbols in parser
Hi Ligia,

I haven't used ocamlyacc, but remember that in a PDA you can always
combine two into one.  E.g.,

---

main ::= ...
main2 ::= ...

becomes,

start ::= main | main2;
main ::= ...
main2 ::= ...

---

Thus, you can still have a single entry point, which (I imagine) is
how ocamlyacc wants things to be.

Will

On Tue, Jun 23, 2009 at 4:10 PM, Ligia Nistor<ligia.nicoleta@gmail.com> wrote:
> Hi,
>
> I am writing a small parser in ocaml, using ocamlyacc. I need to define 2
> start symbols in my file parser.mly, but I don't know how to use them. The
> name of the 2 start symbols are "main"and "main2". I know how to use one
> start symbol, as here(taken form "calc.ml"):
>
>  let _ =
>           try
>             let in_channel = open_in "lines.txt" in
>
>             let lexbuf = Lexing.from_channel in_channel in
>             while true do
>               let result = HorsParser.main HorsLexer.token lexbuf in
>                 Hors.print_pair_list result;
>             done
>           with HorsLexer.Eof ->
>             exit 0
>
> but I don't know how to call the function "HorsParser.main2".
> I want to parse a part of the file "lines.txt" using the rule "main", and
> then, the other part of the file using "main2". Is this possible?
>  I tried to call "HorsParser.main2", but I got a "Parsing.parse_error".
>
> Thanks,
> Ligia
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>