Posts

Showing posts with the label parsing

Updated combinator parsing library: P0 (2021 version)

Image
 I updated my minimal monadic/combinator parsing library to specialize to strings, and to remove ineffectual functors. The link is here: https://github.com/tomjridge/p0/blob/master/src/p0_2021.ml

New single-file Earley implementation

Image
 After reviewing my old code for an Earley parser, I thought I would try to write a new version following my preferences for OCaml coding in 2021. The result is here: https://github.com/tomjridge/tjr_simple_earley/blob/master/src/earley_2021q1.ml Compared to previous versions, the code is pleasingly easy to read (due to use of mutability everywhere). For example, the following are the types and implementations for sets and "map to set"s: Timings: time ./earley_main.exe earley_2021q1 :1x100 begin ------------------------------------------------- earley_2021q1; grammar=EEE; input_length=100 (bin/earley_main.ml) Tjr_simple_earley__Earley_2021q1: count is 15756 end --------------------------------------------------- real 0m0.110s user 0m0.090s sys 0m0.004s time ./earley_main.exe earley_2021q1 :1x200 begin ------------------------------------------------- earley_2021q1; grammar=EEE; input_length=200 (bin/earley_main.ml) Tjr_simple_earley__Earley_2021q1: count is 61506 end --...

A review of the "tjr_simple_earley" code

Image
Repository is here:  https://github.com/tomjridge/tjr_simple_earley This commentary refers to commit 0dc99ad ocamldoc is available OCaml source code in src/ Main file: tjr_simple_earley.ml  https://github.com/tomjridge/tjr_simple_earley/blob/master/src/tjr_simple_earley.ml Config and Misc are utility modules.  Earley_intf has the main interfaces. Earley_base is the first implementation. General comments about the code: In order to run fast, we want every representation (of terminal, nonterminal, symbol, list of symbols, etc) to be an integer. Thus, we try to keep everything independent of the exact representation. Unfortunately this code was written about 5 years ago and I think I could do a better job today. Earley_intf https://github.com/tomjridge/tjr_simple_earley/blob/master/src/earley_intf.ml Starts with a general input type. Introduces nonterminals nt and terminals tm (symbols). A (simple) grammar is a function from nt to a list of (a list of symbols). A variation ...