Page
Library
Module
Module type
Parameter
Class
Class type
Source
Copyright Deducteam
Pratter is a library that allows to parse expressions with infix, postfix or prefix operators.
Pratter is a top-down operator precedence parser that implements the Pratt parsing algorithm. In contrast with Menhir or ocamlyacc, Pratter is a parser, not a parser generator: no code is produced during compilation. In consequence, parsing rules can be modified dynamically. On the other hand, Pratter parses a much more restricted class of grammars called operator grammars while Menhir and ocamlyacc parse LR(1) and LALR(1) grammars respectively.
You are free to copy, modify and distribute Pratter with attribution under the terms of the BSD 3 Clause license. See the license for more details.
To compile and use pratter, you need
Then, at the root of the source tree,
$ make installTo ensure it's working write the following code in some file plus.ml to parse the language defined by the grammar T ::= T + T | id where id denotes identifiers
type t = A of t * t | S of string
let appl t u = A (t, u)
let token = Fun.id
let ops = function
| S "+" as s -> Pratter.[ Infix Left, 0.3, s ]
| _ -> []
let parse = Pratter.expression ~token ~appl ~ops
let () =
let input = List.to_seq [ S "x"; S "+"; S "y"] in
assert (Result.is_ok @@ Pratter.run parse input)then execute the following lines which should return 0
$ echo "module Pratter = struct $(cat pratter.ml) end $(cat plus.ml)" > plus_.ml
$ ocamlc plus_.ml
$ ./a.outYou can report issues, ask questions or start discussions using the issue tracker.