caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* multiple %start symbols in parser
@ 2009-06-23 20:10 Ligia Nistor
  2009-06-23 20:30 ` [Caml-list] " Will Leiserson
  2009-06-23 21:37 ` Jon Harrop
  0 siblings, 2 replies; 3+ messages in thread
From: Ligia Nistor @ 2009-06-23 20:10 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 906 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 1122 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] multiple %start symbols in parser
  2009-06-23 20:10 multiple %start symbols in parser Ligia Nistor
@ 2009-06-23 20:30 ` Will Leiserson
  2009-06-23 21:37 ` Jon Harrop
  1 sibling, 0 replies; 3+ messages in thread
From: Will Leiserson @ 2009-06-23 20:30 UTC (permalink / raw)
  To: Ligia Nistor; +Cc: caml-list

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
>
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] multiple %start symbols in parser
  2009-06-23 20:10 multiple %start symbols in parser Ligia Nistor
  2009-06-23 20:30 ` [Caml-list] " Will Leiserson
@ 2009-06-23 21:37 ` Jon Harrop
  1 sibling, 0 replies; 3+ messages in thread
From: Jon Harrop @ 2009-06-23 21:37 UTC (permalink / raw)
  To: caml-list

On Tuesday 23 June 2009 21:10:32 Ligia Nistor wrote:
> I tried to call "HorsParser.main2", but I got a "Parsing.parse_error".

I think that means you managed to call it fine but whatever you fed it to 
parse was invalid.

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-06-23 20:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-23 20:10 multiple %start symbols in parser Ligia Nistor
2009-06-23 20:30 ` [Caml-list] " Will Leiserson
2009-06-23 21:37 ` Jon Harrop

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).