Grammar Rule Definition
-----------------------
Here are procedures for defining rules for the syntax types introduced
in Note:Precedence Parsing Overview.
For the rule-defining procedures that follow, the variable TK may be a
character, string, or symbol, or a list composed of characters,
strings, and symbols. Each element of TK is treated as though the
procedure were called for each element.
For procedures prec:delim, ..., prec:prestfix, if the SOP argument is
`#f', then the token which triggered this rule is converted to a symbol
and returned. A false SOP argument to the procedures prec:commentfix,
prec:matchfix, or prec:inmatchfix has a different meaning.
Character TK arguments will match only character tokens; i.e.
characters for which no token-group is assigned. Symbols and strings
will both match token strings; i.e. tokens resulting from token groups.
- Function: prec:delim tk
Returns a rule specifying that TK should not be returned from
parsing; i.e. TK's function is purely syntactic. The end-of-file
is always treated as a delimiter.
- Function: prec:nofix tk sop
Returns a rule specifying the following actions take place when TK
is parsed:
* If SOP is a procedure, it is called with no arguments; the
resulting value is incorporated into the expression being
built. Otherwise, the list of SOP is incorporated.
- Function: prec:prefix tk sop bp rule1 ...
Returns a rule specifying the following actions take place when TK
is parsed:
* The rules RULE1 ... augment and, in case of conflict, override
rules currently in effect.
* `prec:parse1' is called with binding-power BP.
* If SOP is a procedure, it is called with the expression
returned from `prec:parse1'; the resulting value is
incorporated into the expression being built. Otherwise, the
list of SOP and the expression returned from `prec:parse1' is
incorporated.
* The ruleset in effect before TK was parsed is restored; RULE1
... are forgotten.
- Function: prec:infix tk sop lbp bp rule1 ...
Returns a rule declaring the left-binding-precedence of the token
TK is LBP and specifying the following actions take place when TK
is parsed:
* The rules RULE1 ... augment and, in case of conflict, override
rules currently in effect.
* One expression is parsed with binding-power LBP. If instead a
delimiter is encountered, a warning is issued.
* If SOP is a procedure, it is applied to the list of LEFT and
the parsed expression; the resulting value is incorporated
into the expression being built. Otherwise, the list of SOP,
the LEFT expression, and the parsed expression is
incorporated.
* The ruleset in effect before TK was parsed is restored; RULE1
... are forgotten.
- Function: prec:nary tk sop bp
Returns a rule declaring the left-binding-precedence of the token
TK is BP and specifying the following actions take place when TK
is parsed:
* Expressions are parsed with binding-power BP as far as they
are interleaved with the token TK.
* If SOP is a procedure, it is applied to the list of LEFT and
the parsed expressions; the resulting value is incorporated
into the expression being built. Otherwise, the list of SOP,
the LEFT expression, and the parsed expressions is
incorporated.
- Function: prec:postfix tk sop lbp
Returns a rule declaring the left-binding-precedence of the token
TK is LBP and specifying the following actions take place when TK
is parsed:
* If SOP is a procedure, it is called with the LEFT expression;
the resulting value is incorporated into the expression being
built. Otherwise, the list of SOP and the LEFT expression is
incorporated.
- Function: prec:prestfix tk sop bp rule1 ...
Returns a rule specifying the following actions take place when TK
is parsed:
* The rules RULE1 ... augment and, in case of conflict, override
rules currently in effect.
* Expressions are parsed with binding-power BP until a
delimiter is reached.
* If SOP is a procedure, it is applied to the list of parsed
expressions; the resulting value is incorporated into the
expression being built. Otherwise, the list of SOP and the
parsed expressions is incorporated.
* The ruleset in effect before TK was parsed is restored; RULE1
... are forgotten.
- Function: prec:commentfix tk stp match rule1 ...
Returns rules specifying the following actions take place when TK
is parsed:
* The rules RULE1 ... augment and, in case of conflict, override
rules currently in effect.
* Characters are read until and end-of-file or a sequence of
characters is read which matches the _string_ MATCH.
* If STP is a procedure, it is called with the string of all
that was read between the TK and MATCH (exclusive).
* The ruleset in effect before TK was parsed is restored; RULE1
... are forgotten.
Parsing of commentfix syntax differs from the others in several
ways. It reads directly from input without tokenizing; It calls
STP but does not return its value; nay any value. I added the STP
argument so that comment text could be echoed.
- Function: prec:matchfix tk sop sep match rule1 ...
Returns a rule specifying the following actions take place when TK
is parsed:
* The rules RULE1 ... augment and, in case of conflict, override
rules currently in effect.
* A rule declaring the token MATCH a delimiter takes effect.
* Expressions are parsed with binding-power `0' until the token
MATCH is reached. If the token SEP does not appear between
each pair of expressions parsed, a warning is issued.
* If SOP is a procedure, it is applied to the list of parsed
expressions; the resulting value is incorporated into the
expression being built. Otherwise, the list of SOP and the
parsed expressions is incorporated.
* The ruleset in effect before TK was parsed is restored; RULE1
... are forgotten.
- Function: prec:inmatchfix tk sop sep match lbp rule1 ...
Returns a rule declaring the left-binding-precedence of the token
TK is LBP and specifying the following actions take place when TK
is parsed:
* The rules RULE1 ... augment and, in case of conflict, override
rules currently in effect.
* A rule declaring the token MATCH a delimiter takes effect.
* Expressions are parsed with binding-power `0' until the token
MATCH is reached. If the token SEP does not appear between
each pair of expressions parsed, a warning is issued.
* If SOP is a procedure, it is applied to the list of LEFT and
the parsed expressions; the resulting value is incorporated
into the expression being built. Otherwise, the list of SOP,
the LEFT expression, and the parsed expressions is
incorporated.
* The ruleset in effect before TK was parsed is restored; RULE1
... are forgotten.