Version française
Home     About     Download     Resources     Contact us    
Browse thread
LL(n) stream parsers?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Hendrik Tews <tews@t...>
Subject: Re: [Caml-list] LL(n) stream parsers?
Dmitry Bely <dbely@mail.ru> writes:

   It looks like camlp4 can only generate LL(1) parsers. How difficult it
   would be to extend it to build LL(n) parsers?
   
Camlp4 does some left factorization in the parsing rules. This
gives some LL(n) effect:

          Objective Caml version 3.09.0

  # #load "camlp4o.cma";;
          Camlp4 Parsing version 3.09.0

  # #load "pa_extend.cmo";;
  # let gram = Grammar.gcreate (Plexer.gmake ());;
  val gram : Grammar.g = <abstr>
  # let test = Grammar.Entry.create gram "test";;
  val test : '_a Grammar.Entry.e = <abstr>
  # EXTEND
    test:
      [ [ "a"; "b"; "c"; "d" -> print_endline "abcd"
        | "a"; "b"; "c"; "e" -> print_endline "abce"
      ] ];
  END;;
            - : unit = ()
  # Grammar.Entry.parse test (Stream.of_string "a b c d");;
  abcd
  - : unit = ()
  # Grammar.Entry.parse test (Stream.of_string "a b c e");;
  abce
  - : unit = ()

Bye,

Hendrik