rule
defstruct is used to store grammar rules; a
rule
struct has two fields, lhs
(a symbol
denoting a non-terminal) and rhs
(a list of symbols
denoting non-terminals or lexical categories).
(defstruct rule lhs rhs)
entry
defstruct is used to store entries on the
agenda and chart.(defstruct (entry (:print-function print-entry)) start end category children lexeme id)An
entry
struct has the following fields:
start
: the starting position in the input (integer)
end
: the ending position in the input (integer)
category
: the lexical or non-terminal category (symbol)
children
: the list of child node ids (symbols;
non-terminals only)
lexeme
: the input symbol (lexical categories only)
id
: a unique identifier for each entry (integer)
Note that there is a predefined print function for entries; when Lisp tries to print an entry structure, it will use this function instead of the default:
(defun print-entry (s stream depth) (declare (ignore depth)) (prin1 (list (entry-start s) (entry-end s) (entry-category s) (or (entry-lexeme s) (entry-children s)) (entry-id s)) stream))This has the effect of printing entries as list containing start, end, category, either the lexeme or child list, and the id.
arc
defstruct is used to store active arcs during parsing.(defstruct arc start end index lhs rhs children)An
arc
struct has the following fields:
start
: the starting position for the arc
end
: the ending position for the arc
index
: the offset (0-based) into the set of RHS symbols, equivalent to the position of Allen's circle mark
lhs
: the LHS of the original rule
rhs
: the RHS of the original rule
children
: a list of entry ids (integers)
When you need to lookup an input symbol to determine its set of
lexical categories, use the function lookup-word
, which
takes a single argument (an input symbol) and returns a list of
symbols denoting lexical categories.