class grammar : object end
This represents a Multiple Context-Free Grammar and all of the
information we've managed to wring out of it. It contains an array of
rules, a set of category information (category names, distinguished
start category, category arities, terminal strings, terminal
identifiers, rules headed by each category, information about whether
the category is empty or non-empty, or both), a list of mapping
function types, a list of patterns used for parsing (instead of
looking at the rules directly, when parsing we construct these
patterns that allow us to detect what can be added to the chart in as
efficient a manner as possible), and a list of patterns used to
reconstruct parse trees from charts.
method get_rule : int -> rule
Returns the rule with index idx, 0<=idx<num_rules
idx
: Index of rule to get
method add_rule : rule -> unit
Adds a new rule to the grammar.
Returns nothing
rule
: Rule to add
method del_rule : int -> unit
Deletes the rule at idx.
Returns nothing
idx
: Index of rule to delete, 0 <= idx <= num_rules
method num_rules : int
Returns the number of rules in the grammar
method rules_headed_by : int -> int list
Returns a list of rule indices for rules whose head category is cat
cat
: Head category
method output_rule : int -> unit
Displays a rule to stdout.
Returns nothing
idx
: Index of rule to output (0 <= idx <= num_rules)
method output_rules : unit -> unit
Displays the list of rules in the grammar
Returns nothing
method check_rules : unit -> unit
Makes sure category arities and that sort of thing are consistent.
Returns nothing
method start_cat : int
Returns the distinguished start category for the grammar
method set_start_cat : int -> unit
Sets the start category to cat
Returns nothing
cat
: Start category for the grammar, 1 <= cat < num_cats
method new_category : int -> int
Adds a new category to the grammar whose base category is bc.
Returns the category number
bc
: Number of base category for new cat (1 <= bc < num_base_cats)
method base_cat : int -> int
Returns the base category of cat
cat
: Category whose base category we want, 0 <= cat < num_cats
method lookup_base_cat : string -> int
Raises Not_found
if no base category is named str
Returns the base category with string value str
str
: String to look up
method arity : int -> int
Returns the arity of category cat
cat
: Category whose arity we want to know,
0 <= cat
< num_cats
method num_cats : int
Returns the number of categories in the grammar
method new_base_category : string -> int
If there is no base category already named name, creates a
new base category with that name.
Returns the (possibly newly assigned) base category number of the
named category
name
: Name of base category to add or look up
method set_arity : int -> int -> unit
Sets the arity for cat
to new_arity
.
Raises Duplicate_category
if cat
already had an assigned arity
different from new_arity
.
Returns nothing
cat
: Category whose arity we wish to set
new_arity
: Arity (dimension) we want to set the category to have
(1 <= new_arity
<= 2)
method num_base_cats : int
Returns the number of base categories
method cat_string : int -> string
Returns the string corresponding to cat
cat
: Category to look up, 1 <= cat
<= num_cats
method is_empty_cat : int -> bool
Returns whether the category heads any productions of the
form 'C --> ""'
cat
: Category to check
method is_nonempty_cat : int -> bool
Returns whether the category heads any productions other than ones
of the form 'C --> ""'
cat
: Category to check
method set_empty_cat : int -> bool -> unit
Indicate whether cat
heads any empty productions.
Returns nothing
cat
: Category in question
value
: Whether cat
heads a production like 'C --> ""'
method set_nonempty_cat : int -> bool -> unit
Indicate whether cat
heads any non-empty productions.
Returns nothing
cat
: Category in question
value
: Whether cat
heads any production not of the form
'C --> ""'
method new_terminal : string -> int
Adds str
as a new terminal item if it isn't already one.
Returns ID number of the terminal (whether just added or not)
str
: Terminal to add
method terminal_id : string -> int
Raises Unknown_terminal(name)
if there is no known terminal with the
string form name
Returns the terminal id number corresponding to name
name
: Name of terminal whose ID we want
method terminal_name : int -> string
Raises Not_found
if no terminal has the ID id
Returns String representing the terminal whose ID is id
id
: Numerical ID of terminal whose name we want to know
method build_patterns : unit -> unit
Gathers information about the grammar for use by parsing
Returns nothing
method patterns : int -> rule_pat list
Returns the patterns that tell you what categories to look up from cat
to see what rules can apply to add new items to the chart
cat
: Category of a trigger item
method reconstruction_pattern : int -> reconstruct_pat
Returns the rule reconstruction pattern for rule ridx
ridx
: Index of rule whose reconstruction pattern is desired
method add_mapping_func : mapfunc -> int
Adds map_func
function to the grammar, if it wasn't already there.
Returns the index of the mapping function (whether just added or not)
map_func
: String mapping function to add
method mapping_function : int -> mapfunc
Returns the mapping function with index midx
midx
: Index of mapping function desired
method arity_of_type : int -> int
Returns the arity of the head category of any rule using map type midx
midx
: Mapping function index