Skip to content

Instantly share code, notes, and snippets.

@PollRobots
Created January 18, 2013 05:29
let parseExpression (grammar:Map<string,Expression>) start (input:string) =
let rec parse offset = function
| Terminal x ->
let e = offset + x.Length - 1
if e < input.Length && input.[offset..e] = x then (TerminalSymbol x, e + 1) else (Unmatched, offset)
| NonTerminal x -> parse offset grammar.[x]
| Epsilon -> if offset = input.Length then (EmptyMatch, offset) else (Unmatched, offset)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment