1 02/06/86  reductions, rdc
  2 
  3 Syntax as a command:  rdc path {-control_args}
  4 
  5 
  6 Function: generates language translators.  It compiles a segment
  7 containing reductions and action routines into a PL/I source segment;
  8 it then invokes the pl1 compiler to compile the PL/I source.  The
  9 reductions specify the syntax and semantics of a new language; the
 10 action routines perform the basic operations (e.g, generating code)
 11 required to translate the language.  For more information see the
 12 Commands manual.
 13 
 14 
 15 Arguments:
 16 path
 17    is the pathname of a translator source segment that is to be
 18    compiled by rdc.  If path does not have a suffix of rd, one is
 19    assumed; however the rd suffix must be the last component of the
 20    name of the source segment.
 21 
 22 
 23 Control arguments:
 24 -brief, -bf
 25    prints all error messages with only a brief summary of the error
 26    that has occurred.
 27 -long, -lg
 28    prints all error messages with a detailed description of the error
 29    that has occurred.
 30 -no_trace
 31    generates a translator without the tracing facility.  (Default)
 32 
 33 
 34 -trace {STR}
 35    adds a tracing facility to the generated translator.  STR defines
 36    whether tracing is enabled or disabled by default.  It can be "on"
 37    (default) or "off."  (See "Notes on tracing" below.)
 38 
 39    In addition, you can give any control argument accepted by the pl1
 40    command.
 41 
 42 
 43 Notes: Reductions are expressed in a highly compact form that
 44 emphasizes the syntax and semantics of the new language.  This command
 45 compiles these reductions into tables that drive an rdc-provided
 46 semantic analyzer for the language.  This analyzer compares the tokens
 47 (basic units) of a program written in the new language with the valid
 48 token phrases defined in the reductions.  When a valid phrase is found,
 49 the action routines defined by the reduction are invoked to translate
 50 the phrase.
 51 
 52 Translators generated by the command can be written more quickly than
 53 hand-programmed translators because rdc provides the semantic analyzer
 54 for the language.  They are easier to understand and to maintain
 55 because the all-important language syntax and semantics is concentrated
 56 in the reductions, rather than being spread throughout the semantic
 57 analyzer.
 58 
 59 
 60 This command can generate translators for the simplest type of
 61 language, a right-linear (finite state automaton) language.  Often such
 62 languages are composed of keywords with operands, such as the control
 63 language of the bind command.
 64 
 65 The organization of an rdc translator, the translation process, and the
 66 reduction language are described below.
 67 
 68 If you supply neither -brief nor -long, a detailed description is
 69 printed the first time an error occurs in a given compilation and a
 70 brief description is printed in subsequent occurrences of that error.
 71 
 72 
 73 Notes on tracing: The tracing facility helps in debugging the
 74 reductions for a new translator by showing which reductions are being
 75 applied, along with the source tokens of the language being compiled
 76 that match each reduction.  This gives you a running view of the flow
 77 of control through the reductions and of the processing of tokens.
 78 
 79 Because the tracing facility generates large amounts of output, it can
 80 be selectively turned on and off during debugging by setting a variable
 81 declared as follows:
 82    dcl TRACING bit(1) aligned int static init("1"b);
 83 A value of "1"b turns tracing on; "0"b turns it off.  The initial value
 84 is set by the operand of -trace.
 85 
 86 
 87 The translator can accept a control argument to turn TRACING on or off,
 88 or it can have a debugging entry point to set the switch, or the switch
 89 can be set at a particular probe breakpoint.  For example, to trace
 90 from the 28th through the 40th reductions, you can use the following
 91 set of probe requests:
 92    probe translator
 93    ps "RD_ACTION(NRED)"
 94    go to RD_ACTION(NRED);
 95    b: if NRED = 28: halt
 96 
 97 
 98 When halted, type--
 99    let TRACING = "1"b
100    reset
101    b: if NRED = 40: h
102    c
103 And when the 40th reduction was reached, type:
104    let TRACING = "0"b
105    reset
106    c
107 
108 
109 Notes on the reduction language: The reductions that define the syntax
110 and semantics of a language to be translated are written in the
111 reduction language.  This translator generation language consists of
112 two kinds of statements: reduction statements and attribute
113 declarations.
114 
115 Reduction statements specify the syntax of token phrases in the
116 language being translated.  They also name action routines that are
117 invoked to translate valid phrases and to diagnose invalid token
118 phrases.
119 
120 Attribute declarations control the size of some fixed-length tables
121 that the generated translator uses and cause translation action
122 routines provided by the reductions command to be included in the
123 translator.  They are described below under "Attribute Declarations."
124 
125 
126 Elements of the reduction language:
127 
128    labels     syntax          actions        next reduction
129    -------    ------------    -----------    --------------
130 
131    MAX_DEPTH label_stack_depth_number \
132    INCLUDE NEXT_STMT
133    \ INCLUDE ERROR \
134    INCLUDE LEX \
135    INCLUDE DELETE \
136    INCLUDE DELETE_STMT \
137    BEGIN   / absolute_spec  / semant(...) / label      \
138            / <relative_fcn> / [var="1"b]  /            \
139    label
140    label2  /                /             /            \
141    / <no-token>             / LEX         / RETURN     \
142    / <any-token>            / LEX(n)      / STACK      \
143    / <name> /               / NEXT_STMT   / STACK_POP  \
144    / <decimal-integer>
145                             / DELETE      /            \
146    / <quoted-string>/       / DELETE(n)   /            \
147    / <BS>                   / DELETE(m,n) /            \
148    /                        / DELETE_STMT /            \
149    /                        / ERROR(n)    /            \
150    /                        / PUSH(label) /            \
151    /                        / POP         /            \