home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / extrnl / grammar.src < prev    next >
Encoding:
Text File  |  1988-05-03  |  44.5 KB  |  1,847 lines

  1. ::::::::::
  2. GRAMMAR.PRO
  3. ::::::::::
  4.  
  5. -------- SIMTEL20 Ada Software Repository Prologue ------------
  6. --                                                           -*
  7. -- Unit name    : HF-GRAMMAR
  8. -- Version      : 1.0
  9. -- Author       : Herman Fischer
  10. --              : Litton Data Systems
  11. --              : 8000 Woodley Ave, ms 44-30
  12. --              : Van Nuys, CA
  13. --              : 818-902-5139
  14. -- Credits      : G Fisher and P Charles
  15. -- DDN Address  : HFischer@ECLB
  16. -- Copyright    : (c) Herm Fischer 1984
  17. -- Date created : 
  18. -- Release date : 15 Dec 84
  19. -- Last update  : 26 Mar 84
  20. -- Machine/System Compiled/Run on : UNIX
  21. --                                                           -*
  22. ---------------------------------------------------------------
  23. --                                                           -*
  24. -- Keywords     :  Ada, Grammar, UNIX, LALR, LALR(1), YACC
  25. ----------------:
  26. --
  27. -- Abstract     :  
  28. ----------------:  
  29. --                                         
  30. --             A LALR(1) grammar for ANSI Ada*             
  31. --                                         
  32. --             Adapted for YACC (UNIX) Inputs              
  33. --                                         
  34. --                                                                           
  35. --                             Herman Fischer                                
  36. --                           Litton Data Systems                             
  37. --                       8000 Woodley Ave., ms 44-30                         
  38. --                              Van Nuys, CA                                 
  39. --                                                                           
  40. --                              818/902-5139                                 
  41. --                           HFischer@eclb.arpa                              
  42. --                        {cepu,trwrb}!litvax!fischer                        
  43. --                                                                           
  44. --                             March 26, 1984                                
  45. --                                         
  46. --                   A Contribution to the Public Domain                     
  47. --                                   for                                     
  48. --            Research, Development, and Training Purposes Only              
  49. --                                                                           
  50. --       Any Corrections or Problems are to be Reported to the Author        
  51. --                                                                           
  52. --                                                                           
  53. --                                                                           
  54. --                              adapted from                                 
  55. --                              the grammar                                  
  56. --                                  by:                                      
  57. --                                         
  58. --            Gerry Fisher                         Philippe Charles          
  59. --                                                                           
  60. --    Computer Sciences Corporation     &             Ada  Project           
  61. --         4045 Hancock Street                     New York University       
  62. --         San Diego, CA 92121                      251 Mercer Street        
  63. --                                               New York, New York 10012    
  64. --                                         
  65. --                                         
  66. --    This grammar is organized in the same order as the syntax summary     
  67. -- in appendix E of the ANSI Ada Reference Manual.   All reserved words     
  68. -- are     written  in  upper  case  letters.    The  lexical  categories     
  69. -- numeric_literal, string_literal, etc, are viewed as terminals.   The     
  70. -- rules  for  pragmas as  stated in  chapter 2,  section 8,  have been     
  71. -- incorporated in the grammar.   Comments are included wherever we had     
  72. -- to deviate from the syntax given in appendix E. Different symbols        
  73. -- used here (to comply with yacc requirements) are of note:            
  74. --    {,something}    is denoted ...something..                 
  75. --    {something}    is denoted ..something..                 
  76. --    [something]    is denoted .something.                    
  77. -- Constructs involving                                                     
  78. -- meta brackets, e.g., ...identifier.. are represented by a nonterminal    
  79. -- formed  by  concatenating  the  construct symbols ( as ...identifier..   
  80. -- in the example)   for  which  the  rules are given at the end.  When     
  81. -- reading  this  grammar,  it    is  important to  note that all symbols     
  82. -- appearing  in the  rules are  separated by  one or  more  blanks.  A     
  83. -- string  such  as   'identifier_type_mark   is  actually  a   single      
  84. -- nonterminal symbol defined at the end of the rules.  The '--' symbol     
  85. -- is used  to indicate that the rest of  the  line is a comment,  just     
  86. -- as in yacc programs.                                                     
  87. --                                                                          
  88. --     This grammar is presented here in a form suitable for input to a     
  89. -- yacc parser generator.  It has  been  processed  by the Bell System      
  90. -- III lex/yacc combination, and tested against over 400 ACVC tests.        
  91. --                                        
  92. -- *Ada is a registered trade mark of the  Department of  Defense  (Ada     
  93. -- Joint Program  Office).                             
  94. --                                         
  95.  
  96.  
  97. --                                                           -*
  98. ------------------ Revision history ---------------------------
  99. --                                                           -*
  100. -- DATE         VERSION    AUTHOR                  HISTORY
  101. -- 12/15/84    1.0    Herman Fischer        Initial Release
  102. --                                                           -*
  103. ------------------ Distribution and Copyright -----------------
  104. --                                                           -*
  105. -- This prologue must be included in all copies of this software.
  106. --
  107. -- This software is copyright by the author.
  108. --
  109. -- This software is released to the Ada community.
  110. -- This software is released to the Public Domain (note:
  111. --   software released to the Public Domain is not subject
  112. --   to copyright protection).
  113. -- Restrictions on use or distribution: See above for the author's
  114. --    requested restrictions; commercial use (ie, sale) prohibited
  115. --                                                           -*
  116. ------------------ Disclaimer ---------------------------------
  117. --                                                           -*
  118. -- This software and its documentation are provided "AS IS" and
  119. -- without any expressed or implied warranties whatsoever.
  120. -- No warranties as to performance, merchantability, or fitness
  121. -- for a particular purpose exist.
  122. --
  123. -- Because of the diversity of conditions and hardware under
  124. -- which this software may be used, no warranty of fitness for
  125. -- a particular purpose is offered.  The user is advised to
  126. -- test the software thoroughly before relying on it.  The user
  127. -- must assume the entire risk and liability of using this
  128. -- software.
  129. --
  130. -- In no event shall any person or organization of people be
  131. -- held responsible for any direct, indirect, consequential
  132. -- or inconsequential damages or lost profits.
  133. --                                                           -*
  134. -------------------END-PROLOGUE--------------------------------
  135. ::::::::::
  136. ADA.Y
  137. ::::::::::
  138.  
  139. /*---------------------------------------------------------------------------*/
  140. /*                                         */
  141. /*             A LALR(1) grammar for ANSI Ada*             */
  142. /*                                         */
  143. /*             Adapted for YACC (UNIX) Inputs              */
  144. /*                                         */
  145. /*                                                                           */
  146. /*                             Herman Fischer                                */
  147. /*                           Litton Data Systems                             */
  148. /*                       8000 Woodley Ave., ms 44-30                         */
  149. /*                              Van Nuys, CA                                 */
  150. /*                                                                           */
  151. /*                              818/902-5139                                 */
  152. /*                           HFischer@eclb.arpa                              */
  153. /*                        {cepu,trwrb}!litvax!fischer                        */
  154. /*                                                                           */
  155. /*                             March 26, 1984                                */
  156. /*                                         */
  157. /*                   A Contribution to the Public Domain                     */
  158. /*                                   for                                     */
  159. /*            Research, Development, and Training Purposes Only              */
  160. /*                                                                           */
  161. /*       Any Corrections or Problems are to be Reported to the Author        */
  162. /*                                                                           */
  163. /*                                                                           */
  164. /*                                                                           */
  165. /*                              adapted from                                 */
  166. /*                              the grammar                                  */
  167. /*                                  by:                                      */
  168. /*                                         */
  169. /*            Gerry Fisher                         Philippe Charles          */
  170. /*                                                                           */
  171. /*    Computer Sciences Corporation     &             Ada  Project           */
  172. /*         4045 Hancock Street                     New York University       */
  173. /*         San Diego, CA 92121                      251 Mercer Street        */
  174. /*                                               New York, New York 10012    */
  175. /*                                         */
  176. /*                                         */
  177. /*    This grammar is organized in the same order as the syntax summary     */
  178. /* in appendix E of the ANSI Ada Reference Manual.   All reserved words     */
  179. /* are     written  in  upper  case  letters.    The  lexical  categories     */
  180. /* numeric_literal, string_literal, etc, are viewed as terminals.   The     */
  181. /* rules  for  pragmas as  stated in  chapter 2,  section 8,  have been     */
  182. /* incorporated in the grammar.   Comments are included wherever we had     */
  183. /* to deviate from the syntax given in appendix E. Different symbols        */
  184. /* used here (to comply with yacc requirements) are of note:            */
  185. /*    {,something}    is denoted ...something..                 */
  186. /*    {something}    is denoted ..something..                 */
  187. /*    [something]    is denoted .something.                    */
  188. /* Constructs involving                                                     */
  189. /* meta brackets, e.g., ...identifier.. are represented by a nonterminal    */
  190. /* formed  by  concatenating  the  construct symbols ( as ...identifier..   */
  191. /* in the example)   for  which  the  rules are given at the end.  When     */
  192. /* reading  this  grammar,  it    is  important to  note that all symbols     */
  193. /* appearing  in the  rules are  separated by  one or  more  blanks.  A     */
  194. /* string  such  as   'identifier_type_mark   is  actually  a   single      */
  195. /* nonterminal symbol defined at the end of the rules.  The '/*' symbol     */
  196. /* is used  to indicate that the rest of  the  line is a comment,  just     */
  197. /* as in yacc programs.                                                     */
  198. /*                                                                          */
  199. /*     This grammar is presented here in a form suitable for input to a     */
  200. /* yacc parser generator.  It has  been  processed  by the Bell System      */
  201. /* III lex/yacc combination, and tested against over 400 ACVC tests.        */
  202. /*                                        */
  203. /* *Ada is a registered trade mark of the  Department of  Defense  (Ada     */
  204. /* Joint Program  Office).                             */
  205. /*                                         */
  206. /*---------------------------------------------------------------------------*/
  207.  
  208.  
  209. /*%terminals -----------------------------------------------------------     */
  210.  
  211. %token ABORT_ ABS_ ACCEPT_  ACCESS_ ALL_  AND_ ARRAY_
  212. %token AT_ BEGIN_  BODY_ CASE_  CONSTANT_
  213. %token DECLARE_ DELAY_ DELTA_ DIGITS_ DO_ ELSE_ ELSIF_
  214. %token END_  ENTRY_ EXCEPTION_ EXIT_ FOR_
  215. %token FUNCTION_ GENERIC_  GOTO_ IF_ IN_  IS_ LIMITED_
  216. %token LOOP_ MOD_  NEW_ NOT_  NULL_ OF_ OR_
  217. %token OTHERS_ OUT_  PACKAGE_ PRAGMA_  PRIVATE_
  218. %token PROCEDURE_  RAISE_  RANGE_ RECORD_ REM_
  219. %token RENAMES_ RETURN_ REVERSE_  SELECT_  SEPARATE_
  220. %token SUBTYPE_    TASK_ TERMINATE_    THEN_
  221. %token TYPE_ USE_ WHEN_ WHILE_ WITH_ XOR_
  222.  
  223. %token identifier numeric_literal string_literal character_literal
  224. %token ARROW_ DBLDOT_ EXP_ ASSIGN_ NOTEQL_ GTEQL_ LTEQ_ L_LBL_ R_LBL_ BOX_
  225.  
  226. %start compilation
  227.  
  228. %%
  229.  
  230.  
  231. /* 2.8 */
  232.  
  233. prag    :
  234.     PRAGMA_ identifier .arg_ascs ';' ;
  235.  
  236. arg_asc          :
  237.     expr
  238.    |    identifier ARROW_ expr  ;
  239.  
  240.  
  241.  
  242. /* 3.1 */
  243.  
  244. basic_d  :
  245.     object_d
  246.    |    ty_d           |  subty_d
  247.    |    subprg_d       |  pkg_d
  248.    |    task_d           |  gen_d
  249.    |    excptn_d       |  gen_inst
  250.    |    renaming_d     |  number_d
  251.    |    error ';' ;
  252.  
  253.  
  254. /* 3.2 */
  255.  
  256. object_d  :
  257.       idents ':'           subty_ind ._ASN_expr. ';'
  258.  |    idents ':'  CONSTANT_ subty_ind ._ASN_expr. ';'
  259.  |    idents ':'           c_arr_def ._ASN_expr. ';'
  260.  |    idents ':'  CONSTANT_ c_arr_def ._ASN_expr. ';' ;
  261.  
  262.  
  263. number_d  :
  264.     idents ':' CONSTANT_ ASSIGN_ expr ';' ;
  265.  
  266.  
  267. idents     :  identifier ...ident..    ;
  268.  
  269.  
  270. /* 3.3.1 */
  271.  
  272. ty_d  :
  273.     full_ty_d
  274.    |    incomplete_ty_d
  275.    |    priv_ty_d  ;
  276.  
  277. full_ty_d  :
  278.         TYPE_ identifier            IS_ ty_def ';'
  279.    |    TYPE_ identifier discr_part IS_ ty_def ';' ;
  280.  
  281.  
  282. ty_def     :
  283.     enum_ty_def        |  integer_ty_def
  284.    |    real_ty_def            |  array_ty_def
  285.    |    rec_ty_def         |  access_ty_def
  286.    |    derived_ty_def ;
  287.  
  288.  
  289. /* 3.3.2 */
  290.  
  291. subty_d  :
  292.     SUBTYPE_ identifier IS_ subty_ind ';' ;
  293.  
  294.  
  295. subty_ind  :    ty_mk .constrt. ;
  296.  
  297.  
  298. ty_mk  :  expanded_n ;
  299.  
  300.  
  301. constrt  :
  302.     rng_c
  303.    |    fltg_point_c  |  fixed_point_c
  304.    |    aggr ;
  305.  
  306.  
  307.  
  308. /* 3.4 */
  309.  
  310. derived_ty_def     :  NEW_ subty_ind ;
  311.  
  312.  
  313. /* 3.5 */
  314.  
  315. rng_c  :  RANGE_ rng ;
  316.  
  317. rng  :
  318.     name
  319.    |    sim_expr DBLDOT_ sim_expr    ;
  320.  
  321.  
  322. /* 3.5.1 */
  323.  
  324. enum_ty_def          :
  325.     '(' enum_lit_spec
  326.             ...enum_lit_spec.. ')' ;
  327.  
  328.  
  329. enum_lit_spec  :  enum_lit ;
  330.  
  331. enum_lit  : identifier  |  character_literal ;
  332.  
  333.  
  334. /* 3.5.4 */
  335.  
  336. integer_ty_def     :  rng_c ;
  337.  
  338.  
  339. /* 3.5.6 */
  340.  
  341. real_ty_def          :
  342.     fltg_point_c  |  fixed_point_c ;
  343.  
  344.  
  345. /* 3.5.7 */
  346.  
  347. fltg_point_c  :
  348.     fltg_accuracy_def .rng_c. ;
  349.  
  350.  
  351. fltg_accuracy_def      :
  352.     DIGITS_ sim_expr ;
  353.  
  354.  
  355. /* 3.5.9 */
  356.  
  357. fixed_point_c    :
  358.     fixed_accuracy_def .rng_c. ;
  359.  
  360.  
  361. fixed_accuracy_def       :
  362.     DELTA_ sim_expr ;
  363.  
  364.  
  365. /* 3.6 */
  366.  
  367. array_ty_def           :
  368.     uncnstrnd_array_def        |  c_arr_def ;
  369.  
  370.  
  371. uncnstrnd_array_def        :
  372.         ARRAY_ '(' idx_subty_def ...idx_subty_def.. ')' OF_
  373.                      subty_ind ;
  374.  
  375.  
  376. c_arr_def          :
  377.     ARRAY_ idx_c OF_ subty_ind ;
  378.  
  379.  
  380. idx_subty_def     :     name  RANGE_ BOX_ ;
  381.  
  382.  
  383. idx_c  :  '(' dscr_rng ...dscr_rng.. ')' ;
  384.  
  385.  
  386. dscr_rng    :
  387.     rng
  388.    |    name rng_c    ;
  389.  
  390.  
  391.  
  392. /* 3.7 */
  393.  
  394. rec_ty_def     :
  395.     RECORD_
  396.         cmpons
  397.     END_ RECORD_ ;
  398.  
  399.  
  400. cmpons    :
  401.     ..prag.. ..cmpon_d.. cmpon_d ..prag..
  402.    |    ..prag.. ..cmpon_d.. variant_part ..prag..
  403.    |    ..prag.. NULL_ ';' ..prag.. ;
  404.  
  405.  
  406. cmpon_d  :
  407.      idents ':' cmpon_subty_def ._ASN_expr. ';'  ;
  408.  
  409.  
  410. cmpon_subty_def          :  subty_ind ;
  411.  
  412.  
  413.  
  414. /* 3.7.1 */
  415.  
  416. discr_part  :
  417.         '(' discr_spec ...discr_spec.. ')' ;
  418.  
  419.  
  420. discr_spec  :
  421.     idents ':' ty_mk ._ASN_expr. ;
  422.  
  423.  
  424. /* 3.7.2 */
  425.  
  426. /*discr_c    :                             */
  427. /*      '(' discr_asc ... discr_asc.. ')' ;                */
  428. /*                                         */
  429. /*discr_asc        :                             */
  430. /*  .discr_sim_n ..or_discrim_sim_n.. ARROW. expressi */
  431. /*     ;                                     */
  432. /*"discr_c" is included under "aggr"             */
  433.  
  434.  
  435. /* 3.7.3 */
  436.  
  437. variant_part  :
  438.     CASE_ sim_n IS_
  439.           ..prag.. variant ..variant..
  440.         END_ CASE_ ';' ;
  441.  
  442.  
  443. variant  :
  444.     WHEN_ choice ..or_choice.. ARROW_
  445.         cmpons ;
  446.  
  447.  
  448. choice    :
  449.     sim_expr
  450.    |    name rng_c
  451.    |    sim_expr DBLDOT_ sim_expr
  452.    |    OTHERS_ ;
  453.  
  454.  
  455.  
  456. /* 3.8 */
  457.  
  458. access_ty_def     :  ACCESS_ subty_ind ;
  459.  
  460.  
  461. /* 3.8.1 */
  462.  
  463. incomplete_ty_d  :
  464.         TYPE_ identifier ';'
  465.    |    TYPE_ identifier discr_part ';'  ;
  466.  
  467. /* 3.9 */
  468.  
  469. decl_part      :
  470.     ..basic_decl_item..
  471.    |    ..basic_decl_item.. body ..later_decl_item.. ;
  472.  
  473. basic_decl_item     :
  474.     basic_d
  475.    |    rep_cl  |  use_cl    ;
  476.  
  477.  
  478. later_decl_item     :  body
  479.    |    subprg_d    |  pkg_d
  480.    |    task_d    |  gen_d
  481.    |    use_cl        |  gen_inst   ;
  482.  
  483. body  :  proper_body  |  body_stub  ;
  484.  
  485. proper_body  :
  486.     subprg_body  |  pkg_body  |  task_body     ;
  487.  
  488.  
  489.  
  490. /* 4.1 */
  491.  
  492. name  :  sim_n
  493.    |    character_literal  |  op_symbol
  494.    |    idxed_cmpon
  495.    |    selected_cmpon |  attribute ;
  496.  
  497.  
  498. sim_n  :    identifier  ;
  499.  
  500.  
  501. prefix    :  name  ;
  502.  
  503.  
  504.  
  505. /* 4.1.1 */
  506.  
  507. idxed_cmpon  :
  508.     prefix aggr  ;
  509.  
  510.  
  511. /* 4.1.2 */
  512.  
  513. /* slice  :  prefix '(' dscr_rng ')' ;       */
  514. /*                           */
  515. /* included under "idxed_cmpon".           */
  516.  
  517.  
  518. /* 4.1.3 */
  519.  
  520. selected_cmpon  :  prefix '.' selector  ;
  521.  
  522. selector  :  sim_n
  523.    |    character_literal  |  op_symbol  |  ALL_  ;
  524.  
  525.  
  526.  
  527. /* 4.1.4 */
  528.  
  529. attribute  :  prefix '\'' attribute_designator ;
  530.  
  531.  
  532. /*  This can be an attribute, idxed cmpon, slice, or subprg call. */
  533. attribute_designator :
  534.     sim_n
  535.    |    DIGITS_
  536.    |    DELTA_
  537.    |    RANGE_      ;
  538.  
  539.  
  540.  
  541.  
  542. /* 4.3 */
  543.  
  544. aggr  :
  545.         '(' cmpon_asc ...cmpon_asc.. ')' ;
  546.  
  547.  
  548. cmpon_asc        :
  549.     expr
  550.    |    choice ..or_choice.. ARROW_ expr
  551.    |    sim_expr DBLDOT_ sim_expr
  552.    |    name rng_c ;
  553.  
  554.  
  555.  
  556. /* 4.4 */
  557.  
  558. expr  :
  559.     rel..AND__rel..  |  rel..AND__THEN__rel..
  560.    |    rel..OR__rel.. |  rel..OR__ELSE__rel..
  561.    |    rel..XOR__rel..  ;
  562.  
  563.  
  564. rel  :
  565.     sim_expr .relal_op__sim_expr.
  566.    |    sim_expr.NOT.IN__rng_or_sim_expr.NOT.IN__ty_mk ;
  567.  
  568.  
  569. sim_expr  :
  570.     .unary_add_op.term..binary_add_op__term.. ;
  571.  
  572.  
  573. term  :  factor..mult_op__factor..  ;
  574.  
  575.  
  576. factor    :  pri ._EXP___pri.  |    ABS_ pri  |    NOT_ pri  ;
  577.  
  578.  
  579. pri  :
  580.     numeric_literal    |  NULL_
  581.    |    allocator  |  qualified_expr
  582.    |    name
  583.    |    aggr ;
  584.  
  585. /* "'(' expr ')'" is included under "aggr".  */
  586.  
  587.  
  588. /* 4.5 */
  589.  
  590. /* logical_op  :    AND_  |    OR_  |  XOR_  ;    */
  591. /*                        */
  592. /* This is an unused syntactic class.        */
  593.  
  594.  
  595. relal_op  :  '='  |  NOTEQL_  |  '<'  |  LTEQ_  |  '>'  |  GTEQL_  ;
  596.  
  597.  
  598. binary_add_op  :  '+'  |  '-'  |  '&' ;
  599.  
  600.  
  601. unary_add_op  :  '+'  |  '-'  ;
  602.  
  603.  
  604. mult_op  :  '*'  |  '/'  |  MOD_  |  REM_  ;
  605.  
  606.  
  607. /* highest_precedence_op    :  EXP_     |   ABS_   |   NOT_   ;     */
  608. /*                                  */
  609. /* This is an unused syntactic class.                  */
  610.  
  611.  
  612.  
  613. /* 4.6 */
  614.  
  615. /* ty_cnvr  :  ty_mk '(' expr ')' ;     */
  616. /*                              */
  617. /* The class "ty_cnvr" is included under "name".  */
  618.  
  619.  
  620. /* 4.7    */
  621.  
  622. qualified_expr    :
  623.     ty_mkaggr_or_ty_mkPexprP_ ;
  624.  
  625.  
  626.  
  627. /* 4.8 */
  628.  
  629. allocator  :
  630.     NEW_ ty_mk
  631.    |    NEW_ ty_mk aggr
  632.    |    NEW_ ty_mk '\'' aggr  ;
  633.  
  634.  
  635.  
  636. /* 5.1 */
  637.  
  638. seq_of_stmts    :
  639.          ..prag.. stmt ..stmt..  ;
  640.  
  641.  
  642. stmt  :
  643.     ..label.. sim_stmt  |  ..label.. compound_stmt
  644.    |    error    ';'  ;
  645.  
  646. sim_stmt  :    null_stmt
  647.    |    assignment_stmt   |  exit_stmt
  648.    |    return_stmt      |  goto_stmt
  649.    |    delay_stmt      |  abort_stmt
  650.    |    raise_stmt      |  code_stmt
  651.    |    name ';' ;
  652.  
  653. /* Procedure and ent call stmts are included under "name".   */
  654.  
  655.  
  656. compound_stmt  :
  657.     if_stmt   |  case_stmt
  658.    |    loop_stmt      |  block_stmt
  659.    |    accept_stmt  |    select_stmt  ;
  660.  
  661.  
  662. label  :  L_LBL_ sim_n R_LBL_  ;
  663.  
  664.  
  665. null_stmt  :  NULL_ ';'  ;
  666.  
  667.  
  668. /* 5.2 */
  669.  
  670. assignment_stmt  :  name ASSIGN_ expr ';' ;
  671.  
  672.  
  673. /* 5.3 */
  674.  
  675. if_stmt  :
  676.     IF_ cond THEN_
  677.         seq_of_stmts
  678.     ..ELSIF__cond__THEN__seq_of_stmts..
  679.     .ELSE__seq_of_stmts.
  680.         END_ IF_ ';' ;
  681.  
  682.  
  683. cond  :  expr ;
  684.  
  685.  
  686. /* 5.4 */
  687.  
  688. case_stmt    :
  689.     CASE_ expr IS_
  690.         case_stmt_alt..case_stmt_alt..
  691.         END_ CASE_ ';' ;
  692.  
  693.  
  694. case_stmt_alt  :
  695.     WHEN_ choice ..or_choice.. ARROW_
  696.         seq_of_stmts ;
  697.  
  698.  
  699. /* 5.5    */
  700.  
  701. loop_stmt    :
  702.     .sim_nC.  /*simple name colon */
  703.         .iteration_scheme. LOOP_
  704.         seq_of_stmts
  705.             END_ LOOP_ .sim_n. ';' ;
  706.  
  707.  
  708.  
  709. iteration_scheme  :
  710.     WHILE_ cond
  711.    |    FOR_ loop_prm_spec ;
  712.  
  713.  
  714. loop_prm_spec  :
  715.     identifier IN_ .REVERSE. dscr_rng ;
  716.  
  717.  
  718. /* 5.6 */
  719.  
  720. block_stmt  :
  721.     .sim_nC.
  722.         .DECLARE__decl_part.
  723.         BEGIN_
  724.         seq_of_stmts
  725.         .EXCEPTION__excptn_handler..excptn_handler...
  726.             END_ .sim_n. ';' ;
  727.  
  728.  
  729. /* 5.7 */
  730.  
  731. exit_stmt    :
  732.         EXIT_ .expanded_n. .WHEN__cond. ';' ;
  733.  
  734.  
  735. /* 5.8 */
  736.  
  737. return_stmt  :  RETURN_ .expr. ';' ;
  738.  
  739.  
  740. /* 5.9 */
  741.  
  742. goto_stmt  :  GOTO_ expanded_n ';' ;
  743.  
  744.  
  745.  
  746. /* 6.1 */
  747.  
  748. subprg_d  :  subprg_spec ';'  ;
  749.  
  750.  
  751. subprg_spec  :
  752.     PROCEDURE_ identifier .fml_part.
  753.    |    FUNCTION_  designator .fml_part. RETURN_ ty_mk  ;
  754.  
  755.  
  756. designator  :  identifier  |  op_symbol  ;
  757.  
  758.  
  759. op_symbol  :  string_literal  ;
  760.  
  761.  
  762. fml_part  :
  763.         '(' prm_spec .._.prm_spec.. ')' ;
  764.  
  765.  
  766. prm_spec  :
  767.     idents ':' mode ty_mk ._ASN_expr.  ;
  768.  
  769.  
  770. mode  :  .IN.  |  IN_ OUT_  |  OUT_   ;
  771.  
  772.  
  773.  
  774. /* 6.3 */
  775.  
  776. subprg_body  :
  777.     subprg_spec IS_
  778.         .decl_part.
  779.     BEGIN_
  780.         seq_of_stmts
  781.     .EXCEPTION__excptn_handler..excptn_handler...
  782.         END_ .designator. ';' ;
  783.  
  784.  
  785. /* 6.4 */
  786.  
  787. /* procedure_call_stmt    :                            */
  788. /*      procedure_n .act_prm_part. ';' ;                        */
  789. /*                                        */
  790. /* func_call  :                                */
  791. /*    func_n .act_prm.  ;                    */
  792. /*                                        */
  793. /* act_prm_part  :                            */
  794. /*      '(' prm_asc ... prm_asc .._paren ;                  */
  795. /*                                        */
  796. /* prm_asc      :                            */
  797. /*    .fml_prm ARROW. act_prm    ;            */
  798. /*                                        */
  799. /* fml_prm  : sim_n  ;                 */
  800. /*                                        */
  801. /* act_prm  :                                */
  802. /*      expr  |  name  |  ty_mk '(' name ')';   */
  803. /*                                        */
  804. /* "procedure_call_stmt" and "func_call" are included under "name".*/
  805.  
  806.  
  807.  
  808. /* 7.1 */
  809.  
  810. pkg_d  :  pkg_spec ';'  ;
  811.  
  812. pkg_spec  :
  813.     PACKAGE_ identifier IS_
  814.         ..basic_decl_item..
  815.     .PRIVATE..basic_decl_item...
  816.     END_ .sim_n.   ;
  817.  
  818.  
  819. pkg_body  :
  820.     PACKAGE_ BODY_ sim_n IS_
  821.         .decl_part.
  822.         .BEGIN__seq_of_stmts.EXCEPTION__excptn_handler..excptn_handler...
  823.     END_ .sim_n. ';'   ;
  824.  
  825.  
  826.  
  827. /* 7.4    */
  828.  
  829. priv_ty_d  :
  830.     TYPE_ identifier            IS_ .LIMITED. PRIVATE_ ';'
  831.       | TYPE_ identifier discr_part IS_ .LIMITED. PRIVATE_ ';' ;
  832.  
  833. /* defer_const_d      :             */
  834. /*      idents : CONSTANT_ ty_mk ';'       ;  */
  835. /*                             */
  836. /* Included under "object_d".          */
  837.  
  838.  
  839.  
  840. /* 8.4 */
  841.  
  842. use_cl  :  USE_ expanded_n ...expanded_n.. ';'  ;
  843.  
  844.  
  845.  
  846. /* 8.5 */
  847.  
  848. renaming_d  :
  849.         idents ':' ty_mk      RENAMES_ name ';'
  850.    |    idents ':' EXCEPTION_      RENAMES_ expanded_n ';'
  851.    |    PACKAGE_ identifier        RENAMES_ expanded_n ';'
  852.    |    subprg_spec  RENAMES_ name ';'   ;
  853.  
  854. /* idents in the two above rule must contain only one */
  855. /* identifier.                               */
  856.  
  857.  
  858. /* 9.1 */
  859.  
  860. task_d  :  task_spec ';'  ;
  861.  
  862. task_spec  :
  863.     TASK_ .TYPE. identifier
  864.         .IS..ent_d_..rep_cl_END.sim_n.
  865.         ;
  866.  
  867. task_body  :
  868.     TASK_ BODY_ sim_n IS_
  869.         .decl_part.
  870.     BEGIN_
  871.         seq_of_stmts
  872.     .EXCEPTION__excptn_handler..excptn_handler...
  873.         END_ .sim_n. ';' ;
  874.  
  875.  
  876. /* 9.5 */
  877.  
  878. ent_d  :
  879.     ENTRY_ identifier .fml_part. ';'
  880.    |    ENTRY_ identifier '(' dscr_rng ')' .fml_part. ';'  ;
  881.  
  882.  
  883. ent_call_stmt  :
  884.         ..prag.. name ';' ;
  885.  
  886.  
  887. accept_stmt  :
  888.     ACCEPT_ sim_n .Pent_idx_P..fml_part.
  889.             .DO__seq_of_stmts__END.sim_n.. ';' ;
  890.  
  891.  
  892. ent_idx  :    expr   ;
  893.  
  894.  
  895. /* 9.6 */
  896.  
  897. delay_stmt  :  DELAY_ sim_expr ';' ;
  898.  
  899.  
  900. /* 9.7 */
  901.  
  902. select_stmt  :    selec_wait
  903.    |    condal_ent_call    |  timed_ent_call  ;
  904.  
  905.  
  906. /* 9.7.1 */
  907.  
  908. selec_wait    :
  909.     SELECT_
  910.         select_alt
  911.         ..OR__select_alt..
  912.         .ELSE__seq_of_stmts.
  913.         END_ SELECT_ ';' ;
  914.  
  915.  
  916. select_alt  :
  917.     .WHEN__condARROW.selec_wait_alt  ;
  918.  
  919.  
  920. selec_wait_alt  :  accept_alt
  921.    |    delay_alt  |  terminate_alt  ;
  922.  
  923.  
  924. accept_alt  :
  925.     accept_stmt.seq_of_stmts.  ;
  926.  
  927.  
  928. delay_alt  :
  929.     delay_stmt.seq_of_stmts.  ;
  930.  
  931.  
  932. terminate_alt  :  TERM_stmt   ;
  933.  
  934.  
  935. /* 9.7.2 */
  936.  
  937. condal_ent_call    :
  938.     SELECT_
  939.         ent_call_stmt
  940.         .seq_of_stmts.
  941.     ELSE_
  942.         seq_of_stmts
  943.         END_ SELECT_ ';' ;
  944.  
  945.  
  946.  
  947. /* 9.7.3 */
  948.  
  949. timed_ent_call  :
  950.     SELECT_
  951.         ent_call_stmt
  952.         .seq_of_stmts.
  953.     OR_
  954.         delay_alt
  955.         END_ SELECT_ ';' ;
  956.  
  957.  
  958. /* 9.10  */
  959.  
  960. abort_stmt  :  ABORT_ name ...name.. ';'  ;
  961.  
  962.  
  963. /* 10.1 */
  964.  
  965. compilation  :    ..compilation_unit..   ;
  966.  
  967.  
  968. compilation_unit  :
  969.     context_cl library_unit
  970.    |    context_cl secondary_unit ;
  971.  
  972. library_unit  :
  973.     subprg_d    |  pkg_d
  974.    |    gen_d    |  gen_inst
  975.    |    subprg_body     ;
  976.  
  977.  
  978. secondary_unit    :
  979.     library_unit_body  |  subunit    ;
  980.  
  981.  
  982. library_unit_body  :
  983.     pkg_body_or_subprg_body  ;
  984.  
  985.  
  986.  
  987. /* 10.1.1  */
  988.  
  989. context_cl      : ..with_cl..use_cl.... ;
  990.  
  991.  
  992. with_cl  :  WITH_ sim_n ...sim_n.. ';'  ;
  993.  
  994.  
  995. /* 10.2 */
  996.  
  997. body_stub  :
  998.         subprg_spec IS_ SEPARATE_ ';'
  999.    |    PACKAGE_ BODY_ sim_n IS_ SEPARATE_ ';'
  1000.    |    TASK_ BODY_ sim_n    IS_ SEPARATE_ ';'   ;
  1001.  
  1002.  
  1003. subunit  :  SEPARATE_ '(' expanded_n ')' proper_body  ;
  1004.  
  1005.  
  1006.  
  1007. /* 11.1 */
  1008.  
  1009. excptn_d  :  idents ':' EXCEPTION_ ';' ;
  1010.  
  1011.  
  1012. /* 11.2 */
  1013.  
  1014. excptn_handler    :
  1015.     WHEN_ excptn_choice ..or_excptn_choice.. ARROW_
  1016.         seq_of_stmts  ;
  1017.  
  1018.  
  1019. excptn_choice  :  expanded_n  |    OTHERS_    ;
  1020.  
  1021.  
  1022. /* 11.3 */
  1023.  
  1024. raise_stmt  :  RAISE_ .expanded_n. ';' ;
  1025.  
  1026.  
  1027.  
  1028. /* 12.1 */
  1029.  
  1030. gen_d  :  gen_spec ';'  ;
  1031.  
  1032. gen_spec  :
  1033.     gen_fml_part subprg_spec
  1034.    |    gen_fml_part pkg_spec  ;
  1035.  
  1036.  
  1037. gen_fml_part  :    GENERIC_ ..gen_prm_d..  ;
  1038.  
  1039.  
  1040. gen_prm_d  :
  1041.     idents ':' .IN.OUT.. ty_mk ._ASN_expr. ';'
  1042.    |    TYPE_ identifier IS_ gen_ty_def ';'
  1043.    |    priv_ty_d
  1044.    |    WITH_ subprg_spec .IS_BOX_. ';' ;
  1045. /* |    WITH_ subprg_spec .IS_ name. ';'  */
  1046. /*                             */
  1047. /* This rule is included in the previous one.         */
  1048.  
  1049.  
  1050. gen_ty_def     :
  1051.         '(' BOX_ ')'  |  RANGE_ BOX_  |  DIGITS_ BOX_  |  DELTA_ BOX_
  1052.    |    array_ty_def           |  access_ty_def       ;
  1053.  
  1054.  
  1055. /* 12.3  */
  1056.  
  1057. gen_inst  :
  1058.     PACKAGE_ identifier IS_
  1059.             NEW_ expanded_n .gen_act_part. ';'
  1060.    |    PROCEDURE__ident__IS_
  1061.             NEW_ expanded_n .gen_act_part. ';'
  1062.    |    FUNCTION_  designator IS_
  1063.         NEW_ expanded_n .gen_act_part. ';'  ;
  1064.  
  1065.  
  1066. gen_act_part  :
  1067.         '(' gen_asc ...gen_asc.. ')'              ;
  1068.  
  1069.  
  1070. gen_asc         :
  1071.     .gen_fml_prmARROW.gen_act_prm ;
  1072.  
  1073.  
  1074. gen_fml_prm  :
  1075.     sim_n  |  op_symbol  ;
  1076.  
  1077. gen_act_prm  :
  1078.   expr_or_name_or_subprg_n_or_ent_n_or_ty_mk
  1079.      ;
  1080.  
  1081.  
  1082. /* 13.1 */
  1083.  
  1084. rep_cl  :
  1085.     ty_rep_cl  |  address_cl  ;
  1086.  
  1087. ty_rep_cl  :  length_cl
  1088.    |    enum_rep_cl
  1089.    |    rec_rep_cl        ;
  1090.  
  1091.  
  1092. /* 13.2 */
  1093.  
  1094. length_cl  :  FOR_ attribute USE_ sim_expr ';' ;
  1095.  
  1096.  
  1097.  
  1098. /* 13.3 */
  1099.  
  1100. enum_rep_cl  :
  1101.         FOR__ty_sim_n__USE_ aggr ';' ;
  1102.  
  1103.  
  1104.  
  1105. /* 13.4  */
  1106.  
  1107. rec_rep_cl    :
  1108.     FOR__ty_sim_n__USE_
  1109.         RECORD_ .algt_cl.
  1110.         ..cmpon_cl..
  1111.             END_ RECORD_ ';'   ;
  1112.  
  1113.  
  1114. algt_cl  :     AT_ MOD_ sim_expr ';' ;
  1115.  
  1116.  
  1117. cmpon_cl  :
  1118.         name AT_ sim_expr RANGE_ rng ';' ;
  1119.  
  1120.  
  1121.  
  1122. /* 13.5 */
  1123.  
  1124. address_cl  :  FOR_ sim_n USE_ AT_ sim_expr ';'  ;
  1125.  
  1126.  
  1127. /* 13.8 */
  1128.  
  1129. code_stmt  :  ty_mk_rec_aggr ';' ;
  1130.  
  1131.  
  1132. /*----------------------------------------------------------------------*/
  1133.  
  1134. /* The following rules define semantically qualified symbols under more
  1135. /* general categories.
  1136.  
  1137. ty_n_or_subty_n  :  expanded_n ;
  1138. /*                                      */
  1139. /* An "expanded_n" is used for names that can be written using only*/
  1140. /* selectors.                                  */
  1141.  
  1142. /*     ... these have been replaced logically to reduce the number    */
  1143. /*         of YACC_ nonterminal "rules"                                */
  1144.  
  1145. /* The following rules expand the concatenated constructs and define the */
  1146. /* specially added syntactical classes.                  */
  1147.  
  1148.  
  1149. /* 2.1 */
  1150.  
  1151. ..prag..  :
  1152.        /* empty */
  1153.    |    ..prag.. prag  ;
  1154.  
  1155. .arg_ascs :
  1156.        /* empty */
  1157.    |    '(' arg_ascs ')' ;
  1158.  
  1159. arg_ascs :
  1160.     arg_asc
  1161.    |    arg_ascs ',' arg_asc ;
  1162.  
  1163. /*                                      */
  1164. /* "name" is included under "expr"    */
  1165.  
  1166.  
  1167. /* 3.1 */
  1168.  
  1169. /*                                       */
  1170. /*  "defer_const_d" is included under "object_d".*/
  1171.  
  1172. ._ASN_expr.    :
  1173.        /* empty */
  1174.    |    ASSIGN_ expr  ;
  1175.  
  1176. ...ident..  :
  1177.        /* empty */
  1178.    |    ...ident.. ',' identifier   ;
  1179.  
  1180. .constrt.  :
  1181.        /* empty */
  1182.    |    constrt   ;
  1183.  
  1184. /*                                     */
  1185. /* "idx_c" and "discr_c" are included under     */
  1186. /* the class "aggr".                         */
  1187.  
  1188. expanded_n  :
  1189.     identifier
  1190.    |    expanded_n '.' identifier   ;
  1191.  
  1192. /*                                       */
  1193. /*  This expansion generalizes "rng" so that it may include ty and */
  1194. /*  subty names.                               */
  1195.  
  1196. ...enum_lit_spec.. :
  1197.        /* empty */
  1198.    |    ...enum_lit_spec.. ','
  1199.         enum_lit_spec ;
  1200.  
  1201. .rng_c.  :
  1202.        /* empty */
  1203.    |    rng_c    ;
  1204.  
  1205. ...idx_subty_def..           :
  1206.        /* empty */
  1207.    |    ...idx_subty_def.. ',' idx_subty_def                ;
  1208.  
  1209. /*                                   */
  1210. /* To avoid conflicts, the more general class "name" is used.       */
  1211.  
  1212. ...dscr_rng.. :
  1213.        /* empty */
  1214.    |    ...dscr_rng.. ',' dscr_rng  ;
  1215.  
  1216.  
  1217. /* A_ dscr subty ind given as a ty mk is included under rng*/
  1218.  
  1219.  
  1220. ..cmpon_d.. :
  1221.        /* empty */
  1222.    |    ..cmpon_d.. cmpon_d ..prag..    ;
  1223.  
  1224. ...discr_spec..    :
  1225.        /* empty */
  1226.    |    ...discr_spec.. ';' discr_spec  ;
  1227.  
  1228.  
  1229. /* Pragmas that can appear between two consecutive variants are picked    */
  1230. /* up in the cmpons part of the variants themselves.        */
  1231.  
  1232. ..variant..  :
  1233.        /* empty */
  1234.    |    ..variant.. variant  ;
  1235.  
  1236. ..or_choice.. :
  1237.        /* empty */
  1238.    |    ..or_choice.. '|' choice  ;
  1239.  
  1240. /* The "sim_expr" by itself may be a "dscr_rng" or a  */
  1241. /* "cmpon_sim_n".                         */
  1242.  
  1243. /* A_ body is the only later_decl_item that is not also a       */
  1244. /* basic_decl_item.        It is therefore used as the dividing   */
  1245. /* point between the two lists of decl items.               */
  1246.  
  1247. ..basic_decl_item..        :
  1248.     ..prag..
  1249.    |    ..basic_decl_item.. basic_decl_item ..prag.. ;
  1250.  
  1251. ..later_decl_item..      :
  1252.     ..prag..
  1253.    |    ..later_decl_item.. later_decl_item ..prag..  ;
  1254.  
  1255.  
  1256. /* 4.1 */
  1257.  
  1258.  
  1259. /* "slice" is included under "idxed_cmpon".  */
  1260.  
  1261. /* The def of "name" includes "func_call".                */
  1262. /* A_ prmless func call is recognized as a sim name or a    */
  1263. /* selected cmpon.    A_ func call with prms is recognized    */
  1264. /* as an idxed cmpon.                        */
  1265.  
  1266.  
  1267. /* Reserved word attribute designators are included in the rules as a         */
  1268. /* convenience.  Alternativly, since an attribute designator is always preced*/
  1269. /* by an apostrophe, as noted in the RR_ 4.1.4, such usage may be detected    */
  1270. /* during lexical analysis thus obviating the need for special rules.         */
  1271. /*                                         */
  1272. /* The univ static expr of an attribute designator is reduced     */
  1273. /* as an "idxed_cmpon".                             */
  1274.  
  1275. ...cmpon_asc..        :
  1276.        /* empty */
  1277.    |    ...cmpon_asc.. ',' cmpon_asc ;
  1278.  
  1279.  
  1280.  
  1281. /* Component ascs are generalized to include dscr rngs.        */
  1282. /* Thus, an "aggr" can be used for slices and idx and discr  */
  1283. /* constrts.                               */
  1284.  
  1285. rel..AND__rel..  :
  1286.     rel AND_ rel
  1287.    |    rel..AND__rel.. AND_ rel     ;
  1288.  
  1289. rel..OR__rel.. :
  1290.     rel OR_ rel
  1291.    |    rel..OR__rel.. OR_ rel ;
  1292.  
  1293. rel..XOR__rel..  :
  1294.     rel
  1295.    |    ..XOR__rel..  ;
  1296.  
  1297. ..XOR__rel..  :
  1298.     rel XOR_ rel
  1299.    |    ..XOR__rel.. XOR_ rel    ;
  1300.  
  1301. rel..AND__THEN__rel..  :
  1302.     rel AND_ THEN_ rel
  1303.    |    rel..AND__THEN__rel.. AND_ THEN_ rel  ;
  1304.  
  1305. rel..OR__ELSE__rel..    :
  1306.     rel OR_ ELSE_ rel
  1307.    |    rel..OR__ELSE__rel.. OR_ ELSE_ rel  ;
  1308.  
  1309. .relal_op__sim_expr.  :
  1310.        /* empty */
  1311.    |    relal_op sim_expr  ;
  1312.  
  1313. sim_expr.NOT.IN__rng_or_sim_expr.NOT.IN__ty_mk    :
  1314.     sim_expr .NOT. IN_ rng ;
  1315.  
  1316. /* The "ty_mk" is included under "rng"  */
  1317.  
  1318. .NOT.  :
  1319.        /* empty */
  1320.    |    NOT_    ;
  1321.  
  1322. .unary_add_op.term..binary_add_op__term..  :
  1323.     term
  1324.    |    unary_add_op term
  1325.    |    .unary_add_op.term..binary_add_op__term..
  1326.     binary_add_op term  ;
  1327.  
  1328. factor..mult_op__factor..    :
  1329.     factor
  1330.    |    factor..mult_op__factor.. mult_op factor ;
  1331.  
  1332. ._EXP___pri.  :
  1333.        /* empty */
  1334.    |    EXP_ pri ;
  1335.  
  1336. /* "stringsit" is included under "name" as "op_symbol".  */
  1337. /* "func_call" is included under "name".                */
  1338. /* "ty_cnvr" is included under "name".                */
  1339.  
  1340.  
  1341. ty_mkaggr_or_ty_mkPexprP_  :
  1342.         prefix '\'' aggr ;
  1343.  
  1344. /* The "prefix must be a "ty_mk".  The "PexprP_" is an "aggr". */
  1345.  
  1346.  
  1347. /* Here the "qualified_expr" can be given exactly  */
  1348.  
  1349.  
  1350. /* We use the fact that the constrt must be an idx or discr  */
  1351. /* constrt.                                 */
  1352.  
  1353.  
  1354. /* 5.1 */
  1355.  
  1356.  
  1357. ..stmt..  :
  1358.     ..prag..
  1359.    |    ..stmt.. stmt ..prag.. ;
  1360.  
  1361.  
  1362. ..label..   :
  1363.        /* empty */
  1364.    |    ..label.. label  ;
  1365.  
  1366.  
  1367.  
  1368. ..ELSIF__cond__THEN__seq_of_stmts..  :
  1369.        /* empty */
  1370.    |    ..ELSIF__cond__THEN__seq_of_stmts..
  1371.         ELSIF_ cond THEN_
  1372.             seq_of_stmts   ;
  1373.  
  1374. .ELSE__seq_of_stmts.    :
  1375.        /* empty */
  1376.    |    ELSE_
  1377.         seq_of_stmts    ;
  1378.  
  1379. case_stmt_alt..case_stmt_alt.. :
  1380.         ..prag..
  1381.         case_stmt_alt
  1382.         ..case_stmt_alt..  ;
  1383.  
  1384. ..case_stmt_alt..    :
  1385.        /* empty */
  1386.    |    ..case_stmt_alt.. case_stmt_alt ;
  1387.  
  1388. .sim_nC.    :
  1389.        /* empty */
  1390.    |    sim_n ':' ;
  1391.  
  1392. .sim_n. :
  1393.        /* empty */
  1394.    |    sim_n  ;
  1395.  
  1396. .iteration_scheme.  :
  1397.        /* empty */
  1398.    |    iteration_scheme  ;
  1399.  
  1400. .REVERSE. :
  1401.        /* empty */
  1402.    |    REVERSE_   ;
  1403.  
  1404. .DECLARE__decl_part.         :
  1405.        /* empty */
  1406.    |    DECLARE_
  1407.         decl_part        ;
  1408.  
  1409. .EXCEPTION__excptn_handler..excptn_handler... :
  1410.        /* empty */
  1411.    |    EXCEPTION_
  1412.         ..prag.. excptn_handlers     ;
  1413.  
  1414. excptn_handlers    :
  1415.     excptn_handler
  1416.    |    excptn_handlers excptn_handler   ;
  1417.  
  1418. .expanded_n.  :
  1419.        /* empty */
  1420.    |    expanded_n  ;
  1421.  
  1422. .WHEN__cond.  :
  1423.        /* empty */
  1424.    |    WHEN_ cond    ;
  1425.  
  1426. .expr.    :
  1427.        /* empty */
  1428.    |    expr   ;
  1429.  
  1430.  
  1431. /* 6.1 */
  1432.  
  1433. .fml_part.  :
  1434.        /* empty */
  1435.    |    fml_part  ;
  1436.  
  1437. .._.prm_spec..  :
  1438.        /* empty */
  1439.    |    .._.prm_spec.. ';' prm_spec  ;
  1440.  
  1441. .IN.  :
  1442.        /* empty */
  1443.    |    IN_      ;
  1444.  
  1445. .decl_part.        :  decl_part     ;
  1446.  
  1447. /* A_ "decl_part" may be empty.        */
  1448.  
  1449. .designator.  :
  1450.        /* empty */
  1451.    |    designator    ;
  1452.  
  1453.  
  1454. /* 7.1    */
  1455.  
  1456. .PRIVATE..basic_decl_item... :
  1457.        /* empty */
  1458.    |    PRIVATE_
  1459.         ..basic_decl_item.. ;
  1460.  
  1461. .BEGIN__seq_of_stmts.EXCEPTION__excptn_handler..excptn_handler...
  1462.                 :
  1463.        /* empty */
  1464.    |    BEGIN_
  1465.         seq_of_stmts
  1466.     .EXCEPTION__excptn_handler..excptn_handler...  ;
  1467.  
  1468. .LIMITED.  :
  1469.        /* empty */
  1470.    |    LIMITED_    ;
  1471.  
  1472. ...expanded_n.. :
  1473.        /* empty */
  1474.    |    ...expanded_n.. ',' expanded_n  ;
  1475.  
  1476.  
  1477. /* 9.1 */
  1478.  
  1479. .TYPE.    :
  1480.        /* empty */
  1481.    |    TYPE_   ;
  1482.  
  1483. .IS..ent_d_..rep_cl_END.sim_n.  :
  1484.        /* empty */
  1485.    |    IS_
  1486.         ..ent_d..
  1487.         ..rep_cl..
  1488.     END_ .sim_n.          ;
  1489.  
  1490.  
  1491. ..ent_d..  :
  1492.     ..prag..
  1493.    |    ..ent_d.. ent_d ..prag..    ;
  1494.  
  1495. ..rep_cl..  :
  1496.        /* empty */
  1497.    |    ..rep_cl.. rep_cl ..prag..    ;
  1498.  
  1499.  
  1500. .Pent_idx_P..fml_part.  :
  1501.     .fml_part.
  1502.    |    '(' ent_idx ')' .fml_part.  ;
  1503.  
  1504. .DO__seq_of_stmts__END.sim_n..  :
  1505.        /* empty */
  1506.    |    DO_
  1507.       seq_of_stmts
  1508.     END_ .sim_n.  ;
  1509.  
  1510. ..OR__select_alt..  :
  1511.        /* empty */
  1512.    |    ..OR__select_alt.. OR_ select_alt    ;
  1513.  
  1514. .WHEN__condARROW.selec_wait_alt  :
  1515.     selec_wait_alt
  1516.    |    WHEN_ cond ARROW_ selec_wait_alt  ;
  1517.  
  1518. accept_stmt.seq_of_stmts.  :
  1519.     ..prag.. accept_stmt .seq_of_stmts.  ;
  1520.  
  1521. delay_stmt.seq_of_stmts.  :
  1522.     ..prag.. delay_stmt .seq_of_stmts. ;
  1523.  
  1524. TERM_stmt   :  ..prag.. TERMINATE_ ';' ..prag..  ;
  1525.  
  1526. .seq_of_stmts.    :
  1527.     ..prag..
  1528.    |    seq_of_stmts    ;
  1529.  
  1530. ...name..    :
  1531.        /* empty */
  1532.    |    ...name.. ',' name  ;
  1533.  
  1534.  
  1535.  
  1536. /* 10.1 */
  1537.  
  1538. ..compilation_unit..  :
  1539.     ..prag..
  1540.    |    ..compilation_unit.. compilation_unit ..prag.. ;
  1541.  
  1542. pkg_body_or_subprg_body   :  pkg_body  ;
  1543.  
  1544. /* "subprg_body" is already contained in the class "library_unit". */
  1545.  
  1546. ..with_cl..use_cl.... :
  1547.        /* empty */
  1548.    |    ..with_cl..use_cl.... with_cl use_cls ;
  1549.  
  1550.  
  1551. use_cls  :
  1552.     ..prag..
  1553.    |    use_cls use_cl ..prag..  ;
  1554.  
  1555. ...sim_n..  :
  1556.        /* empty */
  1557.    |    ...sim_n.. ',' sim_n  ;
  1558.  
  1559.  
  1560.  
  1561. /* 11.1  */
  1562.  
  1563. ..or_excptn_choice.. :
  1564.        /* empty */
  1565.    |    ..or_excptn_choice.. '|' excptn_choice ;
  1566.  
  1567.  
  1568.  
  1569. /* 12.1 */
  1570.  
  1571. ..gen_prm_d..  :
  1572.        /* empty */
  1573.    |    ..gen_prm_d.. gen_prm_d ;
  1574.  
  1575. .IN.OUT..  :
  1576.     .IN.
  1577.    |    IN_ OUT_     ;
  1578.  
  1579. .IS_BOX_.    :
  1580.        /* empty */
  1581.    |    IS_ name
  1582.    |    IS_ BOX_ ;
  1583.  
  1584. PROCEDURE__ident__IS_       :  subprg_spec IS_ ;
  1585.  
  1586. /* To avoid conflicts, the more general "subprg_spec" is used.  */
  1587.  
  1588. .gen_act_part.  :
  1589.        /* empty */
  1590.    |    gen_act_part ;
  1591.  
  1592. ...gen_asc.. :
  1593.        /* empty */
  1594.    |    ...gen_asc.. ',' gen_asc ;
  1595.  
  1596. .gen_fml_prmARROW.gen_act_prm  :
  1597.     gen_act_prm
  1598.    |    gen_fml_prm ARROW_ gen_act_prm  ;
  1599.  
  1600. expr_or_name_or_subprg_n_or_ent_n_or_ty_mk
  1601.                 :  expr  ;
  1602.  
  1603. /* The above alts are included under "expr". */
  1604.  
  1605.  
  1606. /* 13.1 */
  1607.  
  1608. FOR__ty_sim_n__USE_  :
  1609.     FOR_ sim_n USE_    ;
  1610.  
  1611. /* The "sim_n" must be a "ty_sim_n". */
  1612.  
  1613. .algt_cl.  :
  1614.     ..prag..
  1615.    |    ..prag.. algt_cl ..prag..   ;
  1616.  
  1617. ..cmpon_cl..  :
  1618.        /* empty */
  1619.    |    ..cmpon_cl.. cmpon_cl ..prag..  ;
  1620.  
  1621. ty_mk_rec_aggr  :  qualified_expr      ;
  1622.  
  1623. /* The qualified expr must contain a rec aggr. */
  1624.  
  1625. %%
  1626.  
  1627. #include "lex.yy.c"
  1628. #include <stdio.h>
  1629. #include "main.h"
  1630.  
  1631. ::::::::::
  1632. LEX.IN
  1633. ::::::::::
  1634.  
  1635. %{
  1636. /*------------------------------------------------------------------------*/
  1637. /* Lexical input for LEX for LALR(1) Grammar for ANSI Ada                 */
  1638. /*                                                                        */
  1639. /*              Herman Fischer                                            */
  1640. /*            Litton Data Systems                                         */
  1641. /*              March 26, 1984                                            */
  1642. /*                                                                        */
  1643. /* Accompanies Public Domain YACC format Ada grammar                      */
  1644. /*                                                                        */
  1645. /*                                                                        */
  1646. /*                                                                        */
  1647. /*                                                                        */
  1648. /*                                                                        */
  1649. /*                                                                        */
  1650. /*                                                                        */
  1651. /*------------------------------------------------------------------------*/
  1652. #include        "y.tab.h"
  1653. int             lines = 1;      /* line number being processed */
  1654.  
  1655. char id_string[256];            /* identifier being processed  */
  1656. char char_lit[256];             /* character or string literal */
  1657. char num_lit[80];               /* numeric literal             */
  1658. int num_errors = 0;             /* number of errors encountered*/
  1659.  
  1660. #define linenum printf("\n[%d]\t",++lines)
  1661. %}
  1662.  
  1663. %e      1500  /* tree nodes array size    */
  1664. %p      4500  /* positions                */
  1665. %a      4000  /* transitions array size   */
  1666. %k      150   /* packed character classes */
  1667. %o      6000  /* output array size        */
  1668.  
  1669. %START IDENT Z
  1670.  
  1671. %%
  1672. ABORT|abort     {ECHO; BEGIN Z; return(ABORT_);}
  1673. ABS|abs         {ECHO; BEGIN Z; return(ABS_);}
  1674. ACCEPT|accept   {ECHO; BEGIN Z; return(ACCEPT_);}
  1675. ACCESS|access   {ECHO; BEGIN Z; return(ACCESS_);}
  1676. ALL|all         {ECHO; BEGIN Z; return(ALL_);}
  1677. AND|and         {ECHO; BEGIN Z; return(AND_);}
  1678. ARRAY|array     {ECHO; BEGIN Z; return(ARRAY_);}
  1679. AT|at           {ECHO; BEGIN Z; return(AT_);}
  1680. BEGIN|begin     {ECHO; BEGIN Z; return(BEGIN_);}
  1681. BODY|body       {ECHO; BEGIN Z; return(BODY_);}
  1682. CASE|case       {ECHO; BEGIN Z; return(CASE_);}
  1683. CONSTANT|constant {ECHO; BEGIN Z; return(CONSTANT_);}
  1684. DECLARE|declare {ECHO; BEGIN Z; return(DECLARE_);}
  1685. DELAY|delay     {ECHO; BEGIN Z; return(DELAY_);}
  1686. DELTA|delta     {ECHO; BEGIN Z; return(DELTA_);}
  1687. DIGITS|digits   {ECHO; BEGIN Z; return(DIGITS_);}
  1688. DO|do           {ECHO; BEGIN Z; return(DO_);}
  1689. ELSE|else       {ECHO; BEGIN Z; return(ELSE_);}
  1690. ELSIF|elsif     {ECHO; BEGIN Z; return(ELSIF_);}
  1691. END|end         {ECHO; BEGIN Z; return(END_);}
  1692. ENTRY|entry     {ECHO; BEGIN Z; return(ENTRY_);}
  1693. EXCEPTION|exception {ECHO; BEGIN Z; return(EXCEPTION_);}
  1694. EXIT|exit       {ECHO; BEGIN Z; return(EXIT_);}
  1695. FOR|for         {ECHO; BEGIN Z; return(FOR_);}
  1696. FUNCTION|function {ECHO; BEGIN Z; return(FUNCTION_);}
  1697. GENERIC|generic {ECHO; BEGIN Z; return(GENERIC_);}
  1698. GOTO|goto       {ECHO; BEGIN Z; return(GOTO_);}
  1699. IF|if           {ECHO; BEGIN Z; return(IF_);}
  1700. IN|in           {ECHO; BEGIN Z; return(IN_);}
  1701. IS|is           {ECHO; BEGIN Z; return(IS_);}
  1702. LIMITED|limited {ECHO; BEGIN Z; return(LIMITED_);}
  1703. LOOP|loop       {ECHO; BEGIN Z; return(LOOP_);}
  1704. MOD|mod         {ECHO; BEGIN Z; return(MOD_);}
  1705. NEW|new         {ECHO; BEGIN Z; return(NEW_);}
  1706. NOT|not         {ECHO; BEGIN Z; return(NOT_);}
  1707. NULL|null       {ECHO; BEGIN Z; return(NULL_);}
  1708. OF|of           {ECHO; BEGIN Z; return(OF_);}
  1709. OR|or           {ECHO; BEGIN Z; return(OR_);}
  1710. OTHERS|others   {ECHO; BEGIN Z; return(OTHERS_);}
  1711. OUT|out         {ECHO; BEGIN Z; return(OUT_);}
  1712. PACKAGE|package {ECHO; BEGIN Z; return(PACKAGE_);}
  1713. PRAGMA|pragma   {ECHO; BEGIN Z; return(PRAGMA_);}
  1714. PRIVATE|private {ECHO; BEGIN Z; return(PRIVATE_);}
  1715. PROCEDURE|procedure {ECHO; BEGIN Z; return(PROCEDURE_);}
  1716. RAISE|raise     {ECHO; BEGIN Z; return(RAISE_);}
  1717. RANGE|range     {ECHO; BEGIN Z; return(RANGE_);}
  1718. RECORD|record   {ECHO; BEGIN Z; return(RECORD_);}
  1719. REM|rem         {ECHO; BEGIN Z; return(REM_);}
  1720. RENAMES|renames {ECHO; BEGIN Z; return(RENAMES_);}
  1721. RETURN|return   {ECHO; BEGIN Z; return(RETURN_);}
  1722. REVERSE|reverse {ECHO; BEGIN Z; return(REVERSE_);}
  1723. SELECT|select   {ECHO; BEGIN Z; return(SELECT_);}
  1724. SEPARATE|separate {ECHO; BEGIN Z; return(SEPARATE_);}
  1725. SUBTYPE|subtype {ECHO; BEGIN Z; return(SUBTYPE_);}
  1726. TASK|task       {ECHO; BEGIN Z; return(TASK_);}
  1727. TERMINATE|terminate {ECHO; BEGIN Z; return(TERMINATE_);}
  1728. THEN|then       {ECHO; BEGIN Z; return(THEN_);}
  1729. TYPE|type       {ECHO; BEGIN Z; return(TYPE_);}
  1730. USE|use         {ECHO; BEGIN Z; return(USE_);}
  1731. WHEN|when       {ECHO; BEGIN Z; return(WHEN_);}
  1732. WHILE|while     {ECHO; BEGIN Z; return(WHILE_);}
  1733. WITH|with       {ECHO; BEGIN Z; return(WITH_);}
  1734. XOR|xor         {ECHO; BEGIN Z; return(XOR_);}
  1735. "=>"    {ECHO; BEGIN Z; return(ARROW_);}
  1736. ".."    {ECHO; BEGIN Z; return(DBLDOT_);}
  1737. "**"    {ECHO; BEGIN Z; return(EXP_);}
  1738. ":="    {ECHO; BEGIN Z; return(ASSIGN_);}
  1739. "/="    {ECHO; BEGIN Z; return(NOTEQL_);}
  1740. ">="    {ECHO; BEGIN Z; return(GTEQL_);}
  1741. "<="    {ECHO; BEGIN Z; return(LTEQ_);}
  1742. "<<"    {ECHO; BEGIN Z; return(L_LBL_);}
  1743. ">>"    {ECHO; BEGIN Z; return(R_LBL_);}
  1744. "<>"    {ECHO; BEGIN Z; return(BOX_);}
  1745. "&"     {ECHO; BEGIN Z; return('&'); }
  1746. "("     {ECHO; BEGIN Z; return('('); }
  1747. ")"     {ECHO; BEGIN IDENT; return(')'); }
  1748. "*"     {ECHO; BEGIN Z; return('*'); }
  1749. "+"     {ECHO; BEGIN Z; return('+'); }
  1750. ","     {ECHO; BEGIN Z; return(','); }
  1751. "-"     {ECHO; BEGIN Z; return('-'); }
  1752. "."     {ECHO; BEGIN Z; return('.'); }
  1753. "/"     {ECHO; BEGIN Z; return('/'); }
  1754. ":"     {ECHO; BEGIN Z; return(':'); }
  1755. ";"     {ECHO; BEGIN Z; return(';'); }
  1756. "<"     {ECHO; BEGIN Z; return('<'); }
  1757. "="     {ECHO; BEGIN Z; return('='); }
  1758. ">"     {ECHO; BEGIN Z; return('>'); }
  1759. "|"     {ECHO; BEGIN Z; return('|'); }
  1760. <IDENT>\'  {ECHO; BEGIN Z; return('\'');}   /* type mark only */
  1761.  
  1762.  
  1763. [a-z_A-Z][a-z_A-Z0-9]*       {ECHO; BEGIN IDENT; strcpy(id_string,yytext);
  1764.                   return(identifier);}
  1765. [0-9][0-9_]*([.][0-9_]+)?([Ee][-+]?[0-9_]+)?  {
  1766.                   ECHO; BEGIN Z; strcpy(num_lit,yytext);
  1767.                   return(numeric_literal);}
  1768.  
  1769. [0-9][0-9_]*#[0-9a-fA-F_]+([.][0-9a-fA-F_]+)?#([Ee][-+]?[0-9_]+)? {
  1770.                   ECHO; BEGIN Z; strcpy(num_lit,yytext);
  1771.                   return(numeric_literal);}
  1772.  
  1773.  
  1774. \"([^"]*(\"\")*)*\" {ECHO; BEGIN Z; strcpy(char_lit,yytext);
  1775.               return(string_literal);}
  1776. <Z>\'([^']|\'\')\'    {ECHO; BEGIN Z; strcpy(char_lit,yytext);
  1777.               return(character_literal);}
  1778.  
  1779.  
  1780. [ \t]   ECHO;          /* ignore spaces and tabs */
  1781. "--".*  ECHO;          /* ignore comments to end-of-line */
  1782.  
  1783. .       {ECHO; printf("?? lexical error [%s] ??\n\t", yytext);
  1784.                        /* unlexable chars */
  1785.     ++num_errors;}
  1786. [\n]    linenum;
  1787. %%
  1788.  
  1789. ::::::::::
  1790. MAIN.H
  1791. ::::::::::
  1792. extern int lines;
  1793. extern int num_errors;
  1794. extern char id_string[];
  1795. extern char char_lit[];
  1796. extern char num_lit[];
  1797.  
  1798. main()  {
  1799.     printf( "\nStarting Ada grammatical analysis\n\n[1]\t" );
  1800.     yyparse();
  1801.     printf( "---> Grammatical analysis complete!! %d error(s) <---\n", num_errors);
  1802.     }
  1803.  
  1804. yyerror(s)
  1805. char *s;
  1806.     {
  1807.     printf(  "?? %s ??\n\t", s );
  1808.     ++num_errors;
  1809.     }
  1810. ::::::::::
  1811. MAKEADA.
  1812. ::::::::::
  1813. # this shell makes the ada grammar analyzer from lex.in and ADA.Y
  1814. # and calls it "adadl"
  1815. set -v
  1816. cc -O y.tab.c -o adadl y.tab.o -ly -ll -l
  1817. # to run adadl, type in adadl or type in "adadl < sourcefilename"
  1818. ::::::::::
  1819. MAKELEXYACC.
  1820. ::::::::::
  1821. # compile lex & yacc (run in background as "makelexyacc &")
  1822. set -v
  1823. lex lex.in > lex.prt
  1824. cat lex.prt
  1825. # note - I called yacc "yaccbig" when re-made for the 
  1826. # huge model as shown in file "y.statistics"
  1827. yaccbig -vd ADA.Y
  1828. makeada
  1829. ::::::::::
  1830. Y.STATISTICS
  1831. ::::::::::
  1832.  
  1833. 95/127 terminals, 238/300 nonterminals
  1834. 459/900 grammar rules, 860/2500 states
  1835. 0 shift/reduce, 0 reduce/reduce conflicts reported
  1836. 238/350 working sets used
  1837. memory: states,etc. 4125/16000, parser 3113/16000
  1838. 601/2500 distinct lookahead sets
  1839. 946 extra closures
  1840. 1235 shift entries, 65 exceptions
  1841. 571 goto entries
  1842. 1414 entries saved by goto default
  1843. Optimizer space used: input 3376/16000, output 1147/16000
  1844. 1147 table entries, 0 zero
  1845. maximum spread: 333, maximum offset: 857
  1846.  
  1847.