+-*- mode: outline; -*-
-Macro FUCC:DEFPARSER variable initial (&rest terminals) (&rest rules)
- &key reserved-terminals
+Macro FUCC:DEFPARSER VARIABLE
+ (&rest LIST-OF-RULE-GROUPS)
+ &key RESERVED-TERMINALS
-Defines parser who's data is stored in VARIABLE that is declared
-special with DEFPARAMETER. INITIAL is symbol: initial nonterminal.
-TERMINALS is list of terminals that parser can accept. Other symbols
-are treated as nonterminals. RULES is list of rules in arbitrary order.
+The macro defines special VARIABLE (with DEFPARAMETER) where parser's
+tables are stored. INITIAL is symbol that designated initial
+nonterminal. TERMINALS is list of terminals that parser can accept
+(they are returned by lexer). Other symbols in rules are treated as
+non-terminals. LIST-OF-RULE-GROUPS is list of rule groups.
-Each rule in RULES list is list. First element is non-terminal
-(symbol that is member of TERMINALS list), second is
-action-description list (see below) and other elements (if any)
-are right side of the rule.
+RULE-GROUP may describe one rule or some rules with same left side.
-RULE := (SYMBOL [DELIM VAR-DESIGNATOR*]+)
+ ;; Three rules: A -> B C, A-> epsilon and A -> D.
+RULE-GROUP := (SYMBOL [DELIM [VAR-DESIGNATOR* ACTION-DESCRIPTION?]]+)
VAL-DESIGNATOR := (:var SYMBOL RULE-EXP)
| (:initarg SYMBOL RULE-EXP)
ACTION-DESCRIPTION := (:call FUNCTION)
| (:LIST RULE-EXP RULE-EXP)
-DELIM in one RULE is same symbol:
+First element of RULE-GROUP is a non-terminal (symbol that is not
+member of TERMINALS list), and other elements (if any) are right side
+DELIM is a symbol that separates right side of rules. Left side is
+same for all rules in group: it is a first element of a RULE-GROUP.
+DELIM may be different symbol in different rule groups, but the
+separator is same within one group. Write
+If separator contains alpha character (a-z) or digit, warning is
+issued. It helps to prevent errors like lost separator:
+ (a b c ; Warning is issued here
ACTION-DESCRIPTION describes action performed when the rule is reduced
-and intermediate actions. If last VAL-DESIGNATOR is not an
-ACTION-DESCRIPTION, then default action description is inserted: it is
-(CONSTANTLY NIL) for epsilon-rules, #'IDENTITY for one-element (middle
-actions are ingored) rule and #'LIST for other rules.
+and intermediate actions. If last VAL-DESIGNATOR is not followed by
+an ACTION-DESCRIPTION, then default final action description is
+inserted: it is (CONSTANTLY NIL) for epsilon-rules, #'IDENTITY for
+one-element (middle actions are ingored) rule and #'LIST for other
+Value of final ACTION-DESCRIPTION (default or explicit) is treated as
+semantic value of the rule.
FUNCTION here is a form that evaluates to function designator. For
:CLASS-form creates object of class CLASS, who's initargs are defined
with :INITARG VAL-DESIGNATORs. You can use :INITARG VAL-DESIGNATORs
+only with :CLASS-form. Class form may be final (at end of rule right
-:DO evaluates form with variables who's names are
-symbols in :VAR VAL-DESIGNATORs bound in lexical context with values
-of semantic values of corresponding RULE-EXP. You can use :VAR
-VAL-DESIGNATORs only with :FORM-form.
+:DO evaluates form with variables who's names are symbols in :VAR
+VAL-DESIGNATORs bound in lexical context with values of semantic
+values of corresponding RULE-EXP. You can use :VAR VAL-DESIGNATORs
+only with :DO-form. (:DO form is like PROGN in usual Lisp programs).
Rules can be more complex than list of terminals/nonterminals: it can
contain repetition operators like +, *, :LIST and :MAYBE for optional
Rule expression (CL:* RULE-EXP) returns list of RULE-EXP as semantic
value. It matches 0 or more repetitions of RULE-EXP.
-Rule expression (CL:+ RULE-EXP) is similar to CL:*, but minimal number
+Rule expression (CL:+ RULE-EXP) is similar to CL:*, but matches 1 or
+more repetitions of RULE EXP.
(:MAYBE RULE-EXP) defines optional elements. If RULE-EXP doesn't
match, NIL is returned as semantic value, otherwise semantic value of
delimited by RULE-EXP2. Semantic values aof RULE-EXP1 and RULE-EXP2
are in same list. For example:
- (:LIST OPERATOR SEMICOLON))
+ (SEQ -> (:LIST OPERATOR SEMICOLON))
- (:LIST OPERATOR SEMICOLON) SEMICOLON)
+ (SEQ2 -> (:LIST OPERATOR SEMICOLON) SEMICOLON)
OPERATOR SEMICOLON OPERATOR SEMICOLON OPERATOR SEMICOLON)
-Such expression must be used with caution: they can introduce
+Such expression must be used with caution: they can introduce
-Parser type: :LALR (default), :LR (aka :LR1), :LR0
, :SLR and : LL .
+Parser type: :LALR (default), :LR (aka :LR1), :LR0 and :.
List of options. Currently only one option is available: :CONTEXT.
-So, value is either empty list (default) or '(:CONTEXT).
+So, valid value is either empty list (default) or '(:CONTEXT). See
+file LEXER for more info.