-1

I have a parser which parses the std input using Ocamlyacc and lex. How can I trigger the start parse rule on a string in OCaml?

abhishek
  • 850
  • 6
  • 14

1 Answers1

2

Without seeing your code, it's hard to answer but assuming your start rule is called start, and your generated parser module is called Parser.ml and yout generated lexer module is called Lexer.ml, you should do something like :

let parse_from_string s =
  let lex = Lexing.from_string s in
    try
      Lexing.(lex.lex_curr_p <- {lex.lex_curr_p with pos_cnum = 0});
      Parser.start Lexer.token lex
    with
    | Failure s ->
        Printf.eprintf "Error near %s\n\n"
        (string_of_position lex.lex_start_p)
ghilesZ
  • 1,502
  • 1
  • 18
  • 30