All Manuals > LispWorks® User Guide and Reference Manual > 21 The Parser Generator

21.3 Functions defined by defparser

The form (defparser name grammar) defines a number of functions. The main function name is defined as the parsing function. For example:

(defparser my-parser .. grammar .. )

defines the function:

my-parser lexer &optional symbol-to-string &key message-stream return-match-tree-p => form, error-found-p, match-tree

lexer specifies the lexical analyzer function to be used. This is a function of no arguments that returns two values: the next grammar token on the input and the associated semantic value.

The optional argument symbol-to-string should be a function mapping grammar symbols to strings for printing purposes. The default value of symbol-to-string is the function cl:identity.

message-stream specifies a stream for outputting messages that are produced during the parsing. It must be a value suitable for use as the first argument (destination) of format. message-stream defaults to t.

return-match-tree-p is a boolean controlling whether the parsing produces a match tree or not. It defaults to nil, which causes the result match-tree to always be nil. When return-match-tree-p is non-nil, match-tree is a match tree describing the matches during the parsing (see below).

The returned form is the result of the parsing.

error-found-p is nil for successful parsing, otherwise it is t.

match-tree, when return-match-tree-p is non-nil, is a match tree describing the matches found during the parsing. It is a tree of conses, where the car of each cons is the non-terminal of the matching rule, and the cdr is a list of the matches to the grammar symbols of the matching rule. When the grammar symbol is a non-terminal itself, the matching value is a subtree. Otherwise, when the grammar symbol is a lexer token, the matching value is the semantic value that lexer returned for that token.

Compatibility note: return-match-tree-p and match-tree were added in LispWorks 8.0.

defparser also defines functions corresponding to the individual actions of the parser.

Normal actions are named:

name-actionindex

and error actions are named:

name-error-actionindex

where name here is the name as given to defparser and index is the number of the rule or error rule in the grammar.

All function names are interned in the current package when defparser is called.


LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:23