Module Kwparse

module Kwparse: sig .. end

Operator precedence parsing

This parser uses a two-stack shift-reduce machine. See the Tutorial below.
Author(s): Keith Waclena


exception Syntax of string
exception raised when a syntax (or semantic) error is detected in parsing
val syntax : string -> 'a
convenience function to raise Syntax
type srae = 
| Shift
| Reduce
| Accept
| Err of string
The possible values returned by LEX.table
module type LEX = sig .. end
The type of lexer modules.
module type TRACE = sig .. end
The type of tracing modules.
module Make: 
functor (Lex : LEX) ->
functor (T : TRACE with module Lex = Lex) -> sig .. end
Functor taking a lexer Lex and a tracer T and returning a parser implementation.

Convenience implementation of TRACE.

Pass it your LEX implementation.

module NoTrace: 
functor (L : LEX) -> sig .. end
A no-op trace; good for production code.

Convenience functions for computing LEX.table.

This is optional; you can implement your LEX.table however you like: pattern matching, actual 2-dimensional array, etc. However, for more than 3-5 opertors, enumerations are excessively large; opdefs is much more convenient.

type associativity = 
| Nonassoc
| Leftassoc
| Rightassoc
The type of operator associativity for opdef (currently ignored)
type 'a opdef = {
   lexeme : 'a; (*
An operator lexeme
*)
   prec : int; (*
The operator's precedence: lower precedences bind more tightly (sorry, but I think that's most useful)
*)
   arity : int; (*
The operator's arity, i.e. how many arguments does it take (currently ignored)
*)
   assoc : associativity; (*
The operator's associativity (currently ignored)
*)
}
The type of operator definitions for opdef
val opdef : 'a -> pre:int -> ari:int -> associativity -> 'a opdef
Convenience function for constructing opdef records
val opdefs : 'a -> 'a opdef list -> 'a -> 'a -> srae
Convenience function for generating a function suitable for LEX.table.
Returns a LEX.table implementation
eof : the EOF lexeme
spec : a list of opdef records including all Operator lexemes

Tutorial

Coming soon!