Previous: , Up: Precedence Parsing   [Contents][Index]


4.1.6 Grammar Rule Definition

Here are procedures for defining rules for the syntax types introduced in 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:

Function: prec:prefix tk sop bp rule1 …

Returns a rule specifying the following actions take place when tk is parsed:

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:

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:

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:

Function: prec:prestfix tk sop bp rule1 …

Returns a rule specifying the following actions take place when tk is parsed:

Function: prec:commentfix tk stp match rule1 …

Returns rules specifying the following actions take place when tk is parsed:

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:

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:


Previous: , Up: Precedence Parsing   [Contents][Index]