package lrgrep
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=84a1874d0c063da371e19c84243aac7c40bfcb9aaf204251e0eb0d1f077f2cde
sha512=5a16ff42a196fd741bc64a1bdd45b4dca0098633e73aa665829a44625ec15382891c3643fa210dbe3704336eab095d4024e093e37ae5313810f6754de6119d55
doc/lrgrep.runtime/Lrgrep_runtime/index.html
Module Lrgrep_runtimeSource
The Runtime library is used by the generated programs. It defines a compact representation for the automaton in the form of simple bytecoded instructions and a sparse index.
At runtime, an lr1 state is just an integer
For the interpreter, a clause is also represented by an integer. When a clause matches, its id is returned and it is the duty of the (generated) client program to map it to a semantic action.
Registers are also named by small integers.
A sparse table stores many partial mapping from 0..k-1 to 0..v-1 (the set of keys and values) and is directly serialized to a string.
The code of a program is a sequence of serialized program_instruction
A program_counter is an offset in the program_code string. By construction it always point at the beginning of an instruction (otherwise, it is invalid).
type program_instruction = | Store of register(*
*)Store rstores the state at the top of the parser stack in registerr.| Move of register * register(*
*)Move (src, dst)sets registerdstto the value in registersrc.| Swap of register * register(*
*)Swap (r1, r2)exchanges the values of registerr1andr2.| Clear of register| Yield of program_counter(*Jump and consume input:
*)Yield pcstops the current interpretation to consume one state of the input stack. After consuming, execution should resume atpc.| Accept of clause * priority * register option array(*When reaching
*)Accept (clause, priority, captures), the matcher found that clause numberclauseis matching at priority levelpriority. Add it to the set of matching candidates. Ifclausealready match, replace the match ifpriorityis less than or equal to the previous level. Resume execution.capturesdefines the variables captured in the clause definition:Noneif it is unbound,Some regif it is bound to the value stored in registerreg.| Match of Sparse_table.row(*
*)Match sidxlookup the sparse table for a cell matching the state at the top of the parser stack at indexsidx. If the lookup is successful, it returns thepcshould jump to. If unsuccesful, execution continue on next instruction.| Priority of clause * priority * priority(*
*)Priority (clause, p1, p2)remaps the priority of a previous match. Ifclausematched at priorityp1, it should now be considered a match at priorityp2.| Halt(*Program is finished, there will be no more matches.
*)
The instructions of the bytecode language of the matcher
The type of values stored in a register. All registers are initialized with Empty, and Clear set a register back to empty. Value x represents the capture of semantic value x. Initial is a place holder that represents the initial frame of the parser's stack. There is no semantic value associated to it, but one can still refer to the position, which will be the initial position of the file being parsed.
program_step program pc decodes the instruction at address !pc and increases pc.
type program = {registers : int;initial : program_counter;table : Sparse_table.t;code : program_code;
}All the elements composing an error matching program.
A minimal module type mimicking Menhir incremental interface, suitable to run a matching program.
A matching candidate. An lrgrep program found that a clause matches with the a set of register values. However this might not be the clause with the highest priority. The action is not executed immediately and the candidate is saved for later. 'element is the type of stack elements (semantic values) of the parser.
Instantiate an interpreter for a parser representation