New single-file Earley implementation

 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 ---------------------------------------------------

real 0m0.548s
user 0m0.534s
sys 0m0.008s
time ./earley_main.exe earley_2021q1 :1x300
begin -------------------------------------------------
earley_2021q1; grammar=EEE; input_length=300 (bin/earley_main.ml)
Tjr_simple_earley__Earley_2021q1: count is 137256
end ---------------------------------------------------

real 0m2.500s
user 0m2.470s
sys 0m0.020s
time ./earley_main.exe earley_2021q1 :1x400
begin -------------------------------------------------
earley_2021q1; grammar=EEE; input_length=400 (bin/earley_main.ml)
Tjr_simple_earley__Earley_2021q1: count is 243006
end ---------------------------------------------------

real 0m6.867s
user 0m6.833s
sys 0m0.024s

Comments

Popular posts from this blog

The Economics of Writing (Good) Code Documentation

A model of file update

What is so special about cross-directory rename of a directory?