[comp.lang.ada] Ada YACC & LEX

jwabik@shamash.UUCP (09/26/87)

A few days ago I posted an offering of "tweaked" version of the Ada LEX 
and YACC that  Herm Fischer has been distributing.  Response has been 
overwhelming (I counted 18 requests today alone!).  I started mailing
out goodies today, but since 95% of the addresses bounced (I dont know
whose fault it is .. ), I've decided to post all the stuff here.  Here
goes:

This distribution will be in three parts:

	1)  READMEs, ada.doc, etc, etc
	2)  ada.y
	3)  ada.l

The first package is a shar -- the rest are straight code.  Please read thru 
the READMEs, and the other docs before trying to use this stuff.  I made
made some modifications to both that were unique to my application that
I removed before posting to make it generic, there may be a few anomalies
in the code..  (i.e.  Its not "Ready to roll!", and will require a good
30 minutes of hacking to get a parser working... 8^)  I'll be happy to
answer any questions that come up..   Please use the address provided in
the .signature below -- this node is new to the world and not in many
maps yet.  Enjoy!

	-Jeff


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Jeff A. Wabik (HQM207B)			      { umn-cs \
Control Data Corporation              UUCP:             -> !shamash!jwabik }
Bloomington, MN	55440			      { meccts /

Disclaimer of the day:  Of course my employer has no idea what I'm doing .. 
Moral of the day:       Live long and program.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=



echo x - DISTRIBUTION
sed 's/^X//' >DISTRIBUTION <<'*-*-END-of-DISTRIBUTION-*-*'
X
X
X
X
XHere is a list of everyone who requested the Ada YACC and LEX.  This list
Xis distributed with the idea of everyone keeping in touch if there are 
Xproblems/etc.  Of course, I'd be happy to be a central coordinator for 
Xproblems/questions/etc..
X
X
X	Jeff Wabik
X	Control Data Corporation
X
X	UUCP:	umn-cs!shamash!jwabik
X	ARPA:   jwabik@ub.d.umn.edu
X
X==============================================================================
X==============================================================================
XJim Walker				UUCP:	...!harvard!bunny!jjw1
XGTE Laboratories			CSNET:	jjw1@gte-labs
XWaltham, MA
X==============================================================================
Xdaven@lll-crg.arpa
X   -OR-
Xdaven@crg.llnl.gov
X==============================================================================
X-Mike Ramnarine
X
X  UUCP:  ...{ulowell,mit-erl,mit-eddie,yale,uw-beaver,decvax}!apollo!ramnarine
X  USPS:  Apollo Computer, 330 Billerica Rd., Chelmsford MA 01824
X  ARPA:  apollo!ramnarine@eddie.mit.edu
X
Xci-dandelion!ulowell!apollo!ramnarine
X==============================================================================
XFrom: PAYRE%M_SMRVX2%sdr.slb.com@RELAY.CS.NET
XX-Vms-To: MRGATE::M_SDR::IN%"jwabik@ub.d.umn.edu"
X
XMy ARPA address is :
X  PAYRE%M_SMRVX1@SDR.SLB.COM        on ARPA.
X
XMy phone number is :
X  [33] (1) 47 46 66 88. This is in Paris, France.
X
XHenri Payre.
X==============================================================================
X
XARPA:  hermix!fischer@rand-unix.arpa
XUUCP:  {ihnp4,decvax,trwrb,seismo,etc.}!hermix!fischer
X==============================================================================
X
X  matthews@wwu.edu
X
XGeoffrey Matthews
XComputer Science department
XWestern Washington Unviersity
XBellingham, WA 98225
X(206)676-3797
X==============================================================================
X
XFrom: umix!itivax!mnetor!lsuc!geac!daveb@RUTGERS.EDU (Dave Collier-Brown)
X
X David Collier-Brown.                 {mnetor|yetti|utgpu}!geac!daveb
X Geac Computers International Inc.,   |  Computer Science loses its
X 350 Steelcase Road,Markham, Ontario, |  memory (if not its mind)
X CANADA, L3R 1B3 (416) 475-0525 x3279 |  every 6 months.
X==============================================================================
X
XFrom: hwang%uicsgva.LOCAL@uxc.cso.uiuc.edu (David Hwang)
X
X hwang%uicsg.csg.uiuc.edu@a.cs.uiuc.edu
X
X==============================================================================
X
XFrom: "Harry S. Delugach" <hsd%uvacs.cs.virginia.edu@RELAY.CS.NET>
X
XHarry S. Delugach   University of Virginia, Dept. of Computer Science
X                    UUCP: ..!uunet!virginia!uvacs!hsd
X                    INTERNET: hsd@cs.virginia.edu
X                    BITNET: hsd2x@virginia
X                    ARPANET: hsd2x@nrao-nrao1.arpa
X==============================================================================
XFrom: Asheem Chandna <asheem%mandrill.cwru.edu@RELAY.CS.NET>
X
Xuucp: {decvax,sun,cbosgd}!mandrill!asheem
Xarpa: asheem%mandrill.cwru.edu@berkeley.edu
Xcsnet: asheem@mandrill.cwru.edu
X==============================================================================
*-*-END-of-DISTRIBUTION-*-*
echo x - README
sed 's/^X//' >README <<'*-*-END-of-README-*-*'
X
X
X	From:  Jeff Wabik
X	       { umn-cs!shamash!jwabik }
X	       September, 1987
X
X
X
XThanks to everyone who responded to my posting.  
X
X
XThe Table sizes needed for YACC are as follows:
X
X95/6000 terminals, 238/600 nonterminals
X459/1000 grammar rules, 859/1250 states
X0 shift/reduce, 0 reduce/reduce conflicts reported
X238/700 working sets used
Xmemory: states,etc. 4122/24000, parser 3113/12000
X599/1200 distinct lookahead sets
X946 extra closures
X1234 shift entries, 65 exceptions
X570 goto entries
X1413 entries saved by goto default
XOptimizer space used: input 3372/24000, output 1146/12000
X1146 table entries, 0 zero
Xmaximum spread: 333, maximum offset: 856
X
X
XIf your YACC isn't big enough and you DO have the sources, dig around
Xin /usr/src/usr.bin/yacc and play with the "dextern" file.  As you can
Xsee, my YACC has been converted to a Super-YACC.  
X
XThere is a missing routine called "yyerror".  yyerror should look something
Xlike this:
X
X	yyerror(string)
X	char *string;
X	{
X
X		 extern int yylineno;
X
X		 fprintf(stderr,"Syntax error at line %d near %s.\n",
X			 yylineno,yytext);
X		 if (dABORT)
X		    exit(dSYN_ERROR);
X		 else
X		    return(0);
X
X	}
X
XTake a CLOSE look at memory management in the LEX (i.e.  There is none.)  Each 
Xreturned IDENTIFIER makes a call to calloc() that is never ever cfree()'ed.  
XHow you're going to feed memory to the "$$" and "$?" specs in YACC is up
Xto you, but be warned that if you dont have a virtual machine, this version
Xwill never free up allocated memory.
X
XIf you have questions about what more I did to this, or how my routines
Xwork, please feel free to contact  me:
X
X	Jeff Wabik
X	Control Data Corporation
X	2800 E. Old Shakopee Road
X	Bloominton, MN  55420
X	(612) 853-6811
X
X	{ umn-cs \
XUUCP:		   !shamash!jwabik }
X	{ meccts /
X
X
X=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
XOfficial Disclaimer:
X
XControl Data Corporation is not responsible in any way for the contents of
Xthis Ada Language specification, nor does CDC make a commitment to future 
Xsuport of this Public Domain grammar.  What you see is what you get.
X=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
X
XHope my mods can be helpful to others.  Happy hacking!
X
X
X			-Jeff
X
*-*-END-of-README-*-*
echo x - ada.doc
sed 's/^X//' >ada.doc <<'*-*-END-of-ada.doc-*-*'
X
X			 A LALR(1) grammar for ANSI Ada*		     
X
X			      November 17, 1983			     	     
X				Gerry Fisher			     	     
X
X			Computer Sciences Corporation		     	     
X			     4045 Hancock Street			     
X			     San Diego, CA 92121		     	     
X
X									     
X                             Phillipe Charles
X                               Ada Project
X                           New York University
X         	 	       251 Mercer Street			     
X  	 		    New York, New York 10012			     
X
X									     
X									     
X
X     This grammar is organized in the same order as the syntax summary     
X  in appendix E of the ANSI Ada Reference Manual.   All reserved words     
X  are   written  in  upper  case  letters.    The  lexical  categories     
X  numeric_literal, string_literal, etc, are viewed as terminals.   The     
X  rules  for  pragmas as  stated in  chapter 2,  section 8,  have been     
X  incorporated in the grammar.   Comments are included wherever we had     
X  to deviate from the syntax given in appendix E. Constructs involving     
X  meta brackets, e.g., {, identifier} are represented by a nonterminal     
X  formed  by  concatenating  the  construct symbols ( as {,identifier}     
X  in the example)   for  which  the  rules are given at the end.  When     
X  reading  this  grammar,  it  is  important to  note that all symbols     
X  appearing  in the  rules are  separated by  one or  more  blanks.  A     
X  string  such  as   'identifier:type_mark'   is  actually  a   single     
X  nonterminal symbol defined at the end of the rules.  The '--' symbol     
X  is used  to indicate that the rest of  the  line is a comment,  just     
X  as in Ada programs.							     
X
X								  
X
X
X
X
X  This grammar is  presented here in  a form suitable  for input to  a
XLALR parser  generator.   It has  been  processed by  the  NYU  Parser
XGenerator and tested against Version 1.3 of the ACVC Test Suite.
X									     
X *Ada is a registered trade mark of the  Department of  Defense  (Ada     
X  Joint Program  Office).						     
X
X===========================================================================
XThis is what the grammar used to look like.  Blech.
X===========================================================================
X
X
Xterminals -------------------------------------------------------------
X
X  ABORT ABS ACCEPT  ACCESS ALL  AND ARRAY  AT BEGIN  BODY CASE  CONSTANT
X  DECLARE DELAY DELTA DIGITS DO ELSE ELSIF END  ENTRY EXCEPTION EXIT FOR
X  FUNCTION GENERIC  GOTO IF IN  IS LIMITED LOOP MOD  NEW NOT  NULL OF OR
X  OTHERS OUT  PACKAGE PRAGMA  PRIVATE PROCEDURE  RAISE  RANGE RECORD REM
X  RENAMES RETURN REVERSE  SELECT  SEPARATE SUBTYPE  TASK TERMINATE  THEN
X  TYPE USE WHEN WHILE WITH XOR
X
X  identifier    numeric_literal     string_literal     character_literal
X
X  & ' ( ) * + , - . / : ;  < = >  '|' => .. **  := /=  >=  <= <<  >>  <>
X
X
X%start -----------------------------------------------------------------
X
X    compilation
X
X%rules -----------------------------------------------------------------
X
X
X-- 2.8
X
Xpragma  ::=
X	PRAGMA identifier [(argument_association{,argument_association})] ;
X
Xargument_association  ::=
X	[argument_identifier=>]expression__|__[argument_identifier=>]name  
X
X
X
X-- 3.1
X
Xbasic_declaration  ::=
X	deferred_constant_declaration__|__object_declaration
X   |	type_declaration 	       |  subtype_declaration
X   |	subprogram_declaration 	       |  package_declaration
X   |	task_declaration 	       |  generic_declaration
X   |	exception_declaration 	       |  generic_instantiation
X   |	renaming_declaration	       |  number_declaration
X
X
X
X-- 3.2
X
Xobject_declaration  ::=
X   	identifier_list : [CONSTANT]subtype_indication [:=expression] ;
X   |	identifier_list : [CONSTANT]constrained_array_definition
X							[:=expression] ;
X
X
Xnumber_declaration  ::=
X	identifier_list : CONSTANT := universal_static_expression ;
X
X
Xidentifier_list  ::=  identifier {,identifier}
X
X
X-- 3.3.1
X
Xtype_declaration  ::=
X	full_type_declaration
X   |	incomplete_type_declaration
X   |	private_type_declaration
X
Xfull_type_declaration  ::=  
X	TYPE identifier [discriminant_part]IS type_definition ;
X
X
Xtype_definition  ::=
X	enumeration_type_definition 	|  integer_type_definition
X   |	real_type_definition 		|  array_type_definition
X   |	record_type_definition 		|  access_type_definition
X   |	derived_type_definition
X
X
X-- 3.3.2
X
Xsubtype_declaration  ::=  
X	SUBTYPE identifier IS subtype_indication ;
X
X
Xsubtype_indication  ::=  type_mark [constraint]
X
X
Xtype_mark  ::=  type_name__|__subtype_name
X
X
Xconstraint  ::=
X	range_constraint
X   |	floating_point_constraint  |  fixed_point_constraint
X   |	index_constraint__|__discriminant_constraint
X
X
X
X-- 3.4
X
Xderived_type_definition  ::=  NEW subtype_indication
X
X
X-- 3.5
X
Xrange_constraint  ::=  RANGE range
X
Xrange  ::=
X 	range_attribute__|__simple_expression..simple_expression
X
X
X-- 3.5.1
X
Xenumeration_type_definition  ::=
X	( enumeration_literal_specification
X			{,enumeration_literal_specification} )
X
X
Xenumeration_literal_specification  ::=  enumeration_literal
X
Xenumeration_literal  ::=  identifier  |  character_literal
X
X
X-- 3.5.4
X
Xinteger_type_definition  ::=  range_constraint
X
X
X-- 3.5.6
X
Xreal_type_definition  ::=  
X	floating_point_constraint  |  fixed_point_constraint
X
X
X-- 3.5.7
X
Xfloating_point_constraint  ::=  
X	floating_accuracy_definition [range_constraint]
X
X
Xfloating_accuracy_definition  ::=  
X	DIGITS static_simple_expression 
X
X
X-- 3.5.9
X
Xfixed_point_constraint  ::=  
X	fixed_accuracy_definition [range_constraint]
X
X
Xfixed_accuracy_definition  ::=  
X	DELTA static_simple_expression 
X
X
X-- 3.6
X
Xarray_type_definition  ::=
X	unconstrained_array_definition  |  constrained_array_definition
X
X
Xunconstrained_array_definition  ::=
X	ARRAY ( index_subtype_definition {,index_subtype_definition} ) OF 
X					 component_subtype_indication
X
X
Xconstrained_array_definition  ::=
X	ARRAY index_constraint OF component_subtype_indication
X
X
Xindex_subtype_definition  ::=  	type_mark__RANGE__<>
X
X
Xindex_constraint  ::=  ( discrete_range {,discrete_range} )
X
X
Xdiscrete_range  ::=  discrete_subtype_indication__|__range
X
X
X
X-- 3.7
X
Xrecord_type_definition  ::=
X	RECORD 
X            component_list
X	END RECORD
X
X
Xcomponent_list  ::=
X	component_declaration{component_declaration}
X   |	{component_declaration}variant_part
X   |	NULL;
X
X
Xcomponent_declaration  ::=
X	identifier_list : component_subtype_definition [:=expression] ;
X
X
Xcomponent_subtype_definition  ::=  subtype_indication
X
X
X
X-- 3.7.1
X
Xdiscriminant_part  ::=  
X	( discriminant_specification {;discriminant_specification} )
X
X
Xdiscriminant_specification  ::=  
X	identifier_list : type_mark [:=expression]
X
X
X-- 3.7.2
X
X-- discriminant_constraint  ::=
X--	( discriminant_association {, discriminant_association} )
X--
X-- discriminant_association  ::=
X--	[discriminant_simple_name {| discriminant_simple_name} =>] expression
X--
X-- "discriminant_constraint" is included under "aggregate"
X
X
X-- 3.7.3
X
Xvariant_part  ::=
X	CASE discriminant_simple_name IS
X	    variant{variant}
X	END CASE ;
X
X
Xvariant  ::=
X	WHEN choice {|choice} =>
X	    component_list
X
X
Xchoice  ::=  simple_expression__|__discrete_range__|__component_simple_name
X   |	OTHERS
X
X
X
X-- 3.8
X
Xaccess_type_definition  ::=  ACCESS subtype_indication
X
X
X-- 3.8.1
X
Xincomplete_type_declaration  ::=
X	TYPE identifier [discriminant_part];
X
X-- 3.9
X
Xdeclarative_part  ::=
X	{basic_declarative_item}{later_declarative_item}
X
X
Xbasic_declarative_item  ::=
X	basic_declaration
X   |	representation_clause  |  use_clause
X
X
Xlater_declarative_item  ::=  body
X   |	subprogram_declaration  |  package_declaration
X   |	task_declaration 	|  generic_declaration
X   |	use_clause 		|  generic_instantiation
X
Xbody  ::=  proper_body  |  body_stub
X
Xproper_body  ::=
X	subprogram_body  |  package_body  |  task_body
X 
X
X
X-- 4.1
X
Xname  ::=  simple_name
X   |	character_literal  |  operator_symbol
X   |	indexed_component__|__slice
X   |	selected_component |  attribute
X
X
Xsimple_name  ::=  identifier
X
X
Xprefix  ::=  name__|__function_call
X
X
X
X-- 4.1.1
X
Xindexed_component  ::=  
X 	prefix(expression{,expression})
X
X
X-- 4.1.2
X
X-- slice  ::=  prefix ( discrete_range )
X--
X-- included under "indexed_component".
X
X
X-- 4.1.3
X
Xselected_component  ::=  prefix . selector
X
Xselector  ::=  simple_name
X   |	character_literal  |  operator_symbol  |  ALL
X
X
X
X-- 4.1.4
X
Xattribute  ::=  prefix ' attribute_designator
X
X
Xattribute_designator ::=
X	simple_name[(universal_static_expression)]
X
X
X
X-- 4.3
X
Xaggregate  ::=  
X   	( component_association {,component_association} )
X
X
Xcomponent_association  ::=  
X	[choice{|choice}=>]expression
X
X
X
X-- 4.4
X
Xexpression  ::=
X	relation{AND__relation}  |  relation{AND__THEN__relation}
X   |	relation{OR__relation}   |  relation{OR__ELSE__relation}
X   |	relation{XOR__relation}
X
X
Xrelation  ::=
X	simple_expression [relational_operator__simple_expression]
X   |	simple_expression[NOT]IN__range__|__simple_expression[NOT]IN__type_mark
X
X
Xsimple_expression  ::=
X	[unary_adding_operator]term{binary_adding_operator__term}
X
X
Xterm  ::=  factor{multiplying_operator__factor}
X
X
Xfactor  ::=  primary [**__primary]  |  ABS primary  |  NOT primary
X
X
Xprimary  ::=
X	numeric_literal  |  NULL  
X   |	allocator  |  qualified_expression
X   |	name__|__string_literal__|__function_call__|__type_conversion
X   |	aggregate__|__(expression)
X
X
X
X-- 4.5
X
X-- logical_operator  ::=  AND  |  OR  |  XOR
X--
X-- This is an unused syntactic class.
X
X
Xrelational_operator  ::=  =  |  /=  |  <  |  <=  |  >  |  >=
X
X
Xbinary_adding_operator  ::=  +  |  -  |  &
X
X
Xunary_adding_operator  ::=  +  |  -
X
X
Xmultiplying_operator  ::=  *  |  /  |  MOD  |  REM
X
X
X-- highest_precedence_operator  ::=  **   |   ABS   |   NOT
X--
X-- This is an unused syntactic class.
X
X
X
X-- 4.6
X
X-- type_conversion  ::=  type_mark ( expression )
X--
X-- The class "type_conversion" is included under "name".
X
X
X-- 4.7
X
Xqualified_expression  ::=
X	type_mark'aggregate__|__type_mark'(expression)
X
X
X
X-- 4.8
X
Xallocator  ::=
X	NEW__subtype_indication  |  NEW__qualified_expression
X
X
X
X-- 5.1
X
Xsequence_of_statements  ::=  statement{statement}
X
X
Xstatement  ::=
X	{label} simple_statement  |  {label} compound_statement
X
X
Xsimple_statement  ::=  null_statement
X   |	assignment_statement      |  exit_statement
X   |	return_statement          |  goto_statement
X   |    delay_statement           |  abort_statement
X   |	raise_statement           |  code_statement
X   |	procedure_call_statement__|__entry_call_statement
X
X
Xcompound_statement  ::=
X	if_statement      |  case_statement
X   |	loop_statement    |  block_statement
X   |	accept_statement  |  select_statement
X
X
Xlabel  ::=  << label_simple_name >>
X
X
Xnull_statement  ::=  NULL ; 
X
X
X-- 5.2
X
Xassignment_statement  ::=  variable_name := expression ; 
X
X
X-- 5.3
X
Xif_statement  ::=
X	IF condition THEN
X            sequence_of_statements
X        {ELSIF__condition__THEN__sequence_of_statements}
X        [ELSE__sequence_of_statements]
X	END IF ; 
X
X
Xcondition  ::=  boolean_expression  
X
X
X-- 5.4
X
Xcase_statement  ::=
X	CASE expression IS
X	    case_statement_alternative{case_statement_alternative}
X	END CASE ;
X
X
Xcase_statement_alternative  ::=
X	WHEN choice {|choice} =>
X	    sequence_of_statements
X
X
X-- 5.5
X
Xloop_statement  ::=
X	[loop_simple_name:]
X	    [iteration_scheme] LOOP
X		sequence_of_statements
X	    END LOOP [loop_simple_name] ;
X
X
X
Xiteration_scheme  ::=
X	WHILE condition
X   |	FOR loop_parameter_specification
X
X
Xloop_parameter_specification  ::=
X	identifier IN [REVERSE] discrete_range
X
X
X-- 5.6
X
Xblock_statement  ::=
X	[block_simple_name:]
X	    [DECLARE__declarative_part]
X	    BEGIN
X	        sequence_of_statements
X            [EXCEPTION__exception_handler{exception_handler}]
X	    END [block_simple_name] ; 
X
X
X-- 5.7
X
Xexit_statement  ::=
X	EXIT [loop_name] [WHEN__condition] ; 
X
X
X-- 5.8
X
Xreturn_statement  ::=  RETURN [expression] ; 
X
X
X-- 5.9
X
Xgoto_statement  ::=  GOTO label_name ; 
X
X
X
X-- 6.1
X
Xsubprogram_declaration  ::=  subprogram_specification ;
X
X
Xsubprogram_specification  ::=
X   	PROCEDURE identifier [formal_part]
X   |	FUNCTION  designator [formal_part] RETURN type_mark
X
X
Xdesignator  ::=  identifier  |  operator_symbol
X
X
Xoperator_symbol  ::=  string_literal
X
X
Xformal_part  ::=
X	( parameter_specification {;parameter_specification} )
X
X
Xparameter_specification  ::=  
X	identifier_list : mode type_mark [:=expression]
X
X
Xmode  ::=  [IN]  |  IN OUT  |  OUT
X
X
X
X-- 6.3
X
Xsubprogram_body  ::=
X	subprogram_specification IS
X	    [declarative_part]          
X	BEGIN
X	    sequence_of_statements
X	[EXCEPTION__exception_handler{exception_handler}]
X	END [designator] ; 
X
X
X-- 6.4
X
X-- procedure_call_statement  ::=
X--	procedure_name [actual_parameter_part] ;
X--
X-- function_call  ::=
X--	function_name [actual_parameter]
X--
X-- actual_parameter_part  ::= 
X--	( parameter_association {, parameter_association })
X--
X-- parameter_association  ::=
X--	[formal_parameter =>] actual_parameter
X--
X-- formal_parameter  ::= parameter_simple_name
X--
X-- actual_parameter  ::=
X--	expression  |  variable_name  |  type_mark ( variable_name )
X--
X-- "procedure_call_statement" and "function_call" are included under "name".
X
X
X
X-- 7.1
X
Xpackage_declaration  ::=  package_specification ;
X
Xpackage_specification  ::=
X	PACKAGE identifier IS
X	    {basic_declarative_item}
X	[PRIVATE{basic_declarative_item}]
X	END [package_simple_name]
X
X
Xpackage_body  ::=
X	PACKAGE BODY package_simple_name IS
X	    [declarative_part]
X[BEGIN__sequence_of_statements[EXCEPTION__exception_handler{exception_
Xhandler}]]
X	END [package_simple_name] ;
X
X
X
X-- 7.4
X
Xprivate_type_declaration  ::=
X	TYPE identifier [discriminant_part]IS [LIMITED] PRIVATE ;
X
X-- deferred_constant_declaration  ::=
X--	identifier_list : CONSTANT type_mark ;
X--
X-- Included under "object_declaration".
X
X
X
X-- 8.4
X
Xuse_clause  ::=  USE package_name {,package_name} ; 
X
X
X
X-- 8.5
X
Xrenaming_declaration  ::=
X	identifier:type_mark      RENAMES object_name ;
X   |	identifier:EXCEPTION      RENAMES exception_name ;
X   |	PACKAGE identifier        RENAMES package_name ;
X   |	subprogram_specification  RENAMES subprogram_or_entry_name ;
X
X
X-- 9.1
X
Xtask_declaration  ::=  task_specification ;
X
Xtask_specification  ::=
X	TASK [TYPE] identifier
X	    [IS{entry_declaration}{representation_clause}END[task_simple_name]]
X
X
Xtask_body  ::=
X	TASK BODY task_simple_name IS
X	    [declarative_part]      
X	BEGIN
X	    sequence_of_statements
X	[EXCEPTION__exception_handler{exception_handler}]
X	END [task_simple_name] ;
X
X
X-- 9.5
X
Xentry_declaration  ::=
X	ENTRY identifier [(discrete_range)][formal_part] ;
X
X
Xentry_call_statement  ::=  
X	entry_name[actual_parameter_part] ; 
X
X
Xaccept_statement  ::=
X	ACCEPT entry_simple_name [(entry_index)][formal_part]
X	    [DO__sequence_of_statements__END[entry_simple_name]] ;
X
X
Xentry_index  ::=  expression
X
X
X-- 9.6
X
Xdelay_statement  ::=  DELAY simple_expression ; 
X
X
X-- 9.7
X
Xselect_statement  ::=  selective_wait
X   |	conditional_entry_call  |  timed_entry_call
X  
X
X-- 9.7.1
X
Xselective_wait  ::=
X	SELECT
X	    select_alternative
X	    {OR__select_alternative}
X	    [ELSE__sequence_of_statements]
X	END SELECT ; 
X
X
Xselect_alternative  ::=  
X	[WHEN__condition=>]selective_wait_alternative
X
X
Xselective_wait_alternative  ::=  accept_alternative
X   |	delay_alternative  |  terminate_alternative
X
X
Xaccept_alternative  ::=  
X	accept_statement[sequence_of_statements]
X
X
Xdelay_alternative  ::=  
X	delay_statement[sequence_of_statements]
X
X
Xterminate_alternative  ::=  TERMINATE;
X
X
X-- 9.7.2	
X
Xconditional_entry_call  ::=
X	SELECT
X	    entry_call_statement   
X	    [sequence_of_statements]
X	ELSE
X	    sequence_of_statements
X	END SELECT ; 
X
X
X
X-- 9.7.3
X
Xtimed_entry_call  ::=
X	SELECT
X	    entry_call_statement   
X	    [sequence_of_statements]
X	OR
X	    delay_alternative
X	END SELECT ; 
X
X
X-- 9.10
X
Xabort_statement  ::=  ABORT task_name {,task_name} ; 
X
X
X-- 10.1 
X
Xcompilation  ::=  {compilation_unit}
X
X
Xcompilation_unit  ::=
X	context_clause library_unit
X
X   |	context_clause secondary_unit
X
X
Xlibrary_unit  ::=
X	subprogram_declaration  |  package_declaration
X   |	generic_declaration     |  generic_instantiation
X   |	subprogram_body
X
X
Xsecondary_unit  ::=
X	library_unit_body  |  subunit
X
X
Xlibrary_unit_body  ::=
X	package_body__|__subprogram_body 
X
X
X
X-- 10.1.1
X
Xcontext_clause  ::= {with_clause{use_clause}}
X
X
Xwith_clause  ::=  WITH unit_simple_name {,unit_simple_name} ;
X
X 
X-- 10.2
X
Xbody_stub  ::=
X	subprogram_specification IS SEPARATE ;
X   |	PACKAGE BODY package_simple_name IS SEPARATE ;
X   |	TASK BODY task_simple_name    IS SEPARATE ;
X
X
Xsubunit  ::=  SEPARATE ( parent_unit_name ) proper_body
X
X
X
X-- 11.1
X
Xexception_declaration  ::=  identifier_list : EXCEPTION ;
X
X
X-- 11.2
X
Xexception_handler  ::=
X	WHEN exception_choice {|exception_choice} => 
X	    sequence_of_statements
X
X
Xexception_choice  ::=  exception_name  |  OTHERS
X
X
X-- 11.3
X
Xraise_statement  ::=  RAISE [exception_name] ; 
X
X
X
X-- 12.1
X
Xgeneric_declaration  ::=  generic_specification ;
X
Xgeneric_specification  ::=
X	generic_formal_part subprogram_specification
X   |	generic_formal_part package_specification
X
X
Xgeneric_formal_part  ::=  GENERIC {generic_parameter_declaration}
X
X
Xgeneric_parameter_declaration  ::=
X	identifier_list : [IN[OUT]] type_mark [:=expression] ;
X   |	TYPE identifier IS generic_type_definition ;
X   |	private_type_declaration
X   |	WITH subprogram_specification [IS<>] ;
X-- |	WITH subprogram_specification [IS name] ;
X--
X-- This rule is included in the previous one.
X
X
Xgeneric_type_definition  ::=
X	( <> )  |  RANGE <>  |  DIGITS <>  |  DELTA <>
X   |	array_type_definition  |  access_type_definition
X
X
X-- 12.3
X
Xgeneric_instantiation  ::=
X	PACKAGE identifier IS
X	    NEW generic_package_name [generic_actual_part] ;
X   |	PROCEDURE__identifier__IS
X  	    NEW generic_procedure_name [generic_actual_part] ;
X   |	FUNCTION  designator IS
X	    NEW generic_function_name [generic_actual_part] ;
X
X
Xgeneric_actual_part  ::=  
X	( generic_association {,generic_association} )
X
X
Xgeneric_association  ::=
X	[generic_formal_parameter=>]generic_actual_parameter
X
X
Xgeneric_formal_parameter  ::=
X	parameter_simple_name  |  operator_symbol
X
Xgeneric_actual_parameter  ::=  
X  expression__|__variable_name__|__subprogram_name__|__entry_name__|__type_mark
X
X
X
X-- 13.1
X
Xrepresentation_clause  ::=
X	type_representation_clause  |  address_clause
X
Xtype_representation_clause  ::=  length_clause
X   |	enumeration_representation_clause
X   |	record_representation_clause
X
X
X-- 13.2
X
Xlength_clause  ::=  FOR attribute USE simple_expression ;
X
X
X
X-- 13.3
X
Xenumeration_representation_clause  ::=
X	FOR__type_simple_name__USE aggregate ; 
X
X
X
X-- 13.4
X
Xrecord_representation_clause  ::=
X	FOR__type_simple_name__USE
X	    RECORD [alignment_clause]
X		{component_clause}
X	    END RECORD ; 
X
X
Xalignment_clause  ::=  	AT MOD static_simple_expression ; 
X
X
Xcomponent_clause  ::=
X	component_name AT static_simple_expression RANGE static_range ;
X
X
X
X-- 13.5
X
Xaddress_clause  ::=  FOR simple_name USE AT simple_expression ; 
X
X
X--13.8
X
Xcode_statement  ::=  type_mark'record_aggregate ;
X
X
X------------------------------------------------------------------------
X
X-- The following rules define semantically qualified symbols under more
X-- general categories.
X
Xtype_name__|__subtype_name  ::=  expanded_name
X--
X-- An "expanded_name" is used for names that can be written using only
X-- selectors.
X
Xuniversal_static_expression  ::=  expression
X
Xstatic_simple_expression  ::=  simple_expression
X
Xcomponent_subtype_indication  ::=  subtype_indication
X
Xdiscriminant_simple_name  ::=  simple_name
X
Xlabel_simple_name  ::=  simple_name
X
Xvariable_name  ::=  name
X
Xboolean_expression  ::=  expression
X
Xlabel_name  ::=  expanded_name
X
Xpackage_simple_name  ::=  simple_name
X
Xobject_name  ::=  name
X
Xexception_name  ::=  expanded_name
X
Xpackage_name  ::=  expanded_name
X
Xsubprogram_or_entry_name  ::=  name
X
Xtask_simple_name  ::=  simple_name
X
Xentry_simple_name  ::=  simple_name
X
Xtask_name  ::=  name
X
Xunit_simple_name  ::=  simple_name
X
Xparent_unit_name  ::=  expanded_name
X
Xgeneric_package_name  ::=  expanded_name
X
Xgeneric_procedure_name  ::=  expanded_name
X
Xgeneric_function_name  ::=  expanded_name
X
Xparameter_simple_name  ::=  simple_name
X
Xcomponent_name  ::=  name
X
Xstatic_range  ::=  range
X
X
X-- The following rules expand the concatenated constructs and define the
X-- specially added syntactical classes.
X
X
X-- 2.1
X
X{pragma}  ::=
X	empty
X   |	{pragma} pragma
X 
X[(argument_association{,argument_association})]  ::=
X	empty
X   |	( argument_association_list )
X
Xargument_association_list  ::=
X	argument_association
X   |	argument_association_list , argument_association
X
X[argument_identifier=>]expression__|__[argument_identifier=>]name  ::=
X	expression
X   |	identifier => expression
X--
X-- "name" is included under "expression"
X
X
X-- 3.1
X
Xdeferred_constant_declaration__|__object_declaration  ::=  object_declaration
X--
X--  "deferred_constant_declaration" is included under "object_declaration".
X
X[:=expression]  ::=
X	empty
X   |	:= expression
X
X[CONSTANT]subtype_indication  ::=
X	subtype_indication
X   |	CONSTANT subtype_indication
X
X[CONSTANT]constrained_array_definition  ::=
X	constrained_array_definition
X   |	CONSTANT constrained_array_definition
X
X{,identifier}  ::=
X	empty
X   |	{,identifier} , identifier
X
X[discriminant_part]IS  ::=
X	IS
X   |	discriminant_part IS
X
X[constraint]  ::=
X	empty
X   |	constraint
X
Xindex_constraint__|__discriminant_constraint  ::=  aggregate
X--
X-- "index_constraint" and "discriminant_constraint" are included under
X-- the class "aggregate".
X
Xexpanded_name  ::=
X	identifier
X   |	expanded_name . identifier
X
X range_attribute__|__simple_expression..simple_expression  ::=
X	name
X   |	simple_expression .. simple_expression
X--
X--  This expansion generalizes "range" so that it may include type and 
X--  subtype names.
X
X{,enumeration_literal_specification} ::=
X	empty
X   |	{,enumeration_literal_specification} , 
X		enumeration_literal_specification
X
X[range_constraint]  ::=
X	empty
X   |	range_constraint
X
X{,index_subtype_definition}  ::=
X	empty
X   |	{,index_subtype_definition} , index_subtype_definition
X
Xtype_mark__RANGE__<>  ::=  name RANGE <>
X--
X-- To avoid conflicts, the more general class "name" is used.
X
X{,discrete_range} ::=
X	empty
X   |	{,discrete_range} , discrete_range
X
Xdiscrete_subtype_indication__|__range  ::=
X	range
X   |	name range_constraint
X--
X-- A discrete subtype indication given as a type mark is included under "range".
X
Xcomponent_declaration{component_declaration}  ::=
X	{pragma} {component_declaration} component_declaration {pragma}
X
X{component_declaration}variant_part  ::=
X	{pragma} {component_declaration} variant_part {pragma}
X
XNULL;  ::=  {pragma} NULL ; {pragma}
X
X{component_declaration} ::=
X	empty
X   |	{component_declaration} component_declaration {pragma}
X
X{;discriminant_specification}  ::=
X	empty
X   |	{;discriminant_specification} ; discriminant_specification
X
Xvariant{variant}  ::=  {pragma} variant {variant}
X
X-- Pragmas that can appear between two consecutive variants are picked
X-- up in the component_list part of the variants themselves.
X
X{variant}  ::=
X	empty
X   |	{variant} variant
X
X{|choice} ::=
X	empty
X   |	{|choice} '|' choice
X
Xsimple_expression__|__discrete_range__|__component_simple_name  ::=
X	simple_expression
X   |	name range_constraint
X   |	simple_expression .. simple_expression
X--
X-- The "simple_expression" by itself may be a "discrete_range" or a 
X-- "component_simple_name".
X
X[discriminant_part];  ::=
X	;
X   |	discriminant_part ;
X
X{basic_declarative_item}{later_declarative_item}  ::=
X	{basic_declarative_item}
X   |	{basic_declarative_item} body {later_declarative_item}
X--
X-- A body is the only later_declarative_item that is not also a
X-- basic_declarative_item.  It is therefore used as the dividing
X-- point between the two lists of declarative items.
X
X{basic_declarative_item}  ::=
X	{pragma}
X   |	{basic_declarative_item} basic_declarative_item {pragma}
X
X{later_declarative_item}  ::=
X	{pragma}
X   |	{later_declarative_item} later_declarative_item {pragma}
X
X
X-- 4.1
X
Xindexed_component__|__slice  ::=  indexed_component
X--
X-- "slice" is included under "indexed_component".
X
Xname__|__function_call  ::=  name
X--
X-- The definition of "name" includes "function_call".
X-- A parameterless function call is recognized as a simple name or a
X-- selected component.  A function call with parameters is recognized
X-- as an indexed component.
X
Xprefix(expression{,expression})  ::=  
X	prefix aggregate
X--
X--  This can be an attribute, indexed component, slice, or subprogram call.
X
Xsimple_name[(universal_static_expression)]  ::=  
X	simple_name
X   |	DIGITS
X   |	DELTA
X   |	RANGE
X--
X-- Reserved word attribute designators are included in the rules as a
X-- convenience.  Alternativly, since an attribute designator is always
X   preceded
X-- by an apostrophe, as noted in the RR 4.1.4, such usage may be detected 
X-- during lexical analysis thus obviating the need for special rules.
X--
X-- The universal static expression of an attribute designator is reduced
X-- as an "indexed_component".
X
X{,component_association}  ::=
X	empty
X   |	{,component_association} , component_association
X
X[choice{|choice}=>]expression  ::=
X	expression
X   |	choice {|choice} => expression
X   |	simple_expression .. simple_expression
X   |	name range_constraint
X
X--
X-- Component associations are generalized to include discrete ranges.
X-- Thus, an "aggregate" can be used for slices and index and discriminant
X-- constraints.
X
Xrelation{AND__relation}  ::=
X	relation AND relation
X   |	relation{AND__relation} AND relation
X
Xrelation{OR__relation}  ::=
X	relation OR relation
X   |	relation{OR__relation} OR relation
X
Xrelation{XOR__relation}  ::=
X	relation
X   |	{XOR__relation}
X
X{XOR__relation}  ::=
X	relation XOR relation
X   |	{XOR__relation} XOR relation
X
Xrelation{AND__THEN__relation}  ::=
X	relation AND THEN relation
X   |	relation{AND__THEN__relation} AND THEN relation
X
Xrelation{OR__ELSE__relation}  ::=
X	relation OR ELSE relation
X   |	relation{OR__ELSE__relation} OR ELSE relation
X
X[relational_operator__simple_expression]  ::=
X	empty
X   |	relational_operator simple_expression
X
Xsimple_expression[NOT]IN__range__|__simple_expression[NOT]IN__type_mark  ::=
X	simple_expression [NOT] IN range
X--
X-- The "type_mark" is included under "range"
X
X[NOT]  ::=
X	empty
X   |	NOT
X
X[unary_adding_operator]term{binary_adding_operator__term}  ::=
X	term
X   |	unary_adding_operator term
X   |	[unary_adding_operator]term{binary_adding_operator__term}
X	binary_adding_operator term
X
Xfactor{multiplying_operator__factor}  ::=
X	factor
X   |	factor{multiplying_operator__factor} multiplying_operator factor
X
X[**__primary]  ::=
X	empty
X   |	** primary
X
Xname__|__string_literal__|__function_call__|__type_conversion  ::=  name
X--
X-- "string_literal" is included under "name" as "operator_symbol".
X-- "function_call" is included under "name".
X-- "type_conversion" is included under "name".
X
Xaggregate__|__(expression)  ::=  aggregate
X--
X-- "( expression )" is included under "aggregate".
X
Xtype_mark'aggregate__|__type_mark'(expression)  ::=
X	prefix ' aggregate
X--
X-- The "prefix must be a "type_mark".  The "(expression)" is an "aggregate".
X
XNEW__qualified_expression  ::=
X	NEW type_mark ' aggregate
X--
X-- Here the "qualified_expression" can be given exactly
X
XNEW__subtype_indication  ::=
X	NEW type_mark
X   |	NEW type_mark aggregate
X--
X-- We use the fact that the constraint must be an index or discriminant 
X-- constraint.
X
X
X-- 5.1
X
Xstatement{statement}  ::=  {pragma} statement {statement}
X
X{statement}  ::=
X	{pragma}
X   |	{statement} statement {pragma}
X
X
X{label}   ::=
X	empty
X   |	{label} label
X
Xprocedure_call_statement__|__entry_call_statement  ::= name ;
X--
X-- Procedure and entry call statements are included under "name".
X
X
X{ELSIF__condition__THEN__sequence_of_statements}  ::=
X	empty
X   |	{ELSIF__condition__THEN__sequence_of_statements}
X		ELSIF condition THEN
X		    sequence_of_statements
X
X[ELSE__sequence_of_statements]  ::=
X	empty
X   |	ELSE
X	    sequence_of_statements
X
Xcase_statement_alternative{case_statement_alternative}  ::=
X            {pragma} 
X	    case_statement_alternative
X	    {case_statement_alternative}
X
X{case_statement_alternative}  ::=
X	empty
X   |	{case_statement_alternative} case_statement_alternative
X
X[simple_name:]  ::=
X	empty
X   |	simple_name :
X
X[simple_name] ::=
X	empty
X   |	simple_name
X
X[iteration_scheme]  ::=
X	empty
X   |	iteration_scheme
X
X[loop_simple_name:]  ::=  [simple_name:]
X
X[loop_simple_name]   ::=  [simple_name]
X
X[REVERSE] ::=
X	empty
X   |	REVERSE
X
X[block_simple_name:]  ::=  [simple_name:]
X
X[block_simple_name]   ::=  [simple_name]
X
X[DECLARE__declarative_part]  ::=
X	empty
X   |	DECLARE 
X            declarative_part
X
X[EXCEPTION__exception_handler{exception_handler}]  ::=
X	empty
X   |	EXCEPTION 
X            {pragma} exception_handler_list
X
Xexception_handler_list  ::=
X	exception_handler
X   |	exception_handler_list exception_handler
X
X[loop_name]  ::=  [expanded_name]
X
X[expanded_name]  ::=
X	empty
X   |	expanded_name
X
X[WHEN__condition]  ::=
X	empty
X   |	WHEN condition
X
X[expression]  ::=
X	empty
X   |	expression
X
X
X-- 6.1
X
X[formal_part]  ::=
X	empty
X   |	formal_part
X
X{;parameter_specification}  ::=
X	empty
X   |	{;parameter_specification} ; parameter_specification
X
X[IN]  ::=
X	empty
X   |	IN
X
X[declarative_part]  ::=  declarative_part
X--
X-- A "declarative_part" may be empty.
X
X[designator]  ::=
X	empty
X   |	designator
X
X
X-- 7.1
X
X[PRIVATE{basic_declarative_item}]  ::=
X	empty
X   |	PRIVATE 
X            {basic_declarative_item}
X
X[BEGIN__sequence_of_statements[EXCEPTION__exception_handler{exception_handler}]]
X				::=
X	empty
X   |	BEGIN
X	    sequence_of_statements
X	[EXCEPTION__exception_handler{exception_handler}]
X
X[LIMITED]  ::=
X	empty
X   |	LIMITED
X
X{,package_name} ::=
X	empty
X   |	{,package_name} , package_name
X
X[package_simple_name]  ::=  [simple_name]
X
X
X-- 8.1
X
Xidentifier:type_mark  ::= identifier_list : type_mark
X--
X-- identifier_list in the two above rule must contain only one
X-- identifier.
X
Xidentifier:EXCEPTION  ::= identifier_list : EXCEPTION
X--
X-- identifier_list in the two above rule must contain only one
X-- identifier.
X
X
X
X-- 9.1
X
X[TYPE]  ::=
X	empty
X   |	TYPE
X
X[IS{entry_declaration}{representation_clause}END[task_simple_name]]  ::=
X	empty
X   |    IS
X	    {entry_declaration}
X	    {representation_clause}
X	END [task_simple_name]
X
X[task_simple_name]  ::=
X	[simple_name]
X
X{entry_declaration}  ::=
X	{pragma}
X   |	{entry_declaration} entry_declaration {pragma}
X
X{representation_clause}  ::=
X	empty
X   |	{representation_clause} representation_clause {pragma}
X
Xentry_name[actual_parameter_part]  ::=  {pragma} name
X
X[(discrete_range)][formal_part]  ::=
X	[formal_part]
X   |	( discrete_range ) [formal_part]
X
X[(entry_index)][formal_part]  ::=
X	[formal_part]
X   |	( entry_index ) [formal_part]
X
X[entry_simple_name]  ::=  [simple_name]	
X
X[DO__sequence_of_statements__END[entry_simple_name]]  ::=
X	empty
X   |	DO
X	  sequence_of_statements
X	END [entry_simple_name]
X
X{OR__select_alternative}  ::=
X	empty
X   |	{OR__select_alternative} OR select_alternative
X
X[WHEN__condition=>]selective_wait_alternative  ::=
X	selective_wait_alternative
X   |	WHEN condition => selective_wait_alternative
X
Xaccept_statement[sequence_of_statements]  ::=
X	{pragma} accept_statement [sequence_of_statements]
X
Xdelay_statement[sequence_of_statements]  ::=
X	{pragma} delay_statement [sequence_of_statements]
X
XTERMINATE;   ::=  {pragma} TERMINATE ; {pragma}
X
X[sequence_of_statements]  ::=
X	{pragma}
X   |	sequence_of_statements
X
X{,task_name}  ::=
X	empty
X   |	{,task_name} , task_name
X
X
X
X-- 10.1
X
X{compilation_unit}  ::=
X	{pragma}
X   |	{compilation_unit} compilation_unit {pragma}
X 
Xpackage_body__|__subprogram_body   ::=  package_body
X--
X-- "subprogram_body" is already contained in the class "library_unit".
X
X{with_clause{use_clause}}  ::=
X	empty
X   |	{with_clause{use_clause}} with_clause use_clause_list 
X
X
Xuse_clause_list  ::=
X	{pragma}
X   |	use_clause_list use_clause {pragma}
X 
X{,unit_simple_name}  ::=
X	empty
X   |	{,unit_simple_name} , unit_simple_name
X
X
X
X-- 11.1
X
X{|exception_choice}  ::=
X	empty
X   |	{|exception_choice} '|' exception_choice
X
X[exception_name]  ::=
X	[expanded_name]
X
X
X
X-- 12.1
X
X{generic_parameter_declaration}  ::=
X	empty
X   |	{generic_parameter_declaration} generic_parameter_declaration
X
X[IN[OUT]]  ::=
X	[IN]
X   |	IN OUT
X
X[IS<>]  ::=
X	empty
X   |	IS name
X   |	IS <>
X 
XPROCEDURE__identifier__IS  ::=  subprogram_specification IS
X--
X-- To avoid conflicts, the more general "subprogram_specification" is used.
X
X[generic_actual_part]  ::=
X	empty
X   |	generic_actual_part
X
X{,generic_association}  ::=
X	empty
X   |	{,generic_association} , generic_association
X
X[generic_formal_parameter=>]generic_actual_parameter  ::=
X	generic_actual_parameter
X   |	generic_formal_parameter => generic_actual_parameter
X
Xexpression__|__variable_name__|__subprogram_name__|__entry_name__|__type_mark
X				::=  expression
X--
X-- The above alternatives are included under "expression".
X
X
X-- 13.1
X
XFOR__type_simple_name__USE  ::=
X	FOR simple_name USE
X--
X-- The "simple_name" must be a "type_simple_name".
X
X[alignment_clause]  ::=
X	{pragma}
X   |	{pragma} alignment_clause {pragma}
X
X{component_clause}  ::=
X	empty
X   |	{component_clause} component_clause {pragma}
X
Xtype_mark'record_aggregate  ::=  qualified_expression
X--
X-- The qualified expression must contain a record aggregate.
X
X-----------------------------------------------------------------------------
X
X                            end
X
X
X
*-*-END-of-ada.doc-*-*
echo x - ada.note
sed 's/^X//' >ada.note <<'*-*-END-of-ada.note-*-*'
XFrom umn-cs!jwabik@ub.D.UMN.EDU Fri Sep  4 08:45:16 1987
XReturn-Path: <umn-cs!jwabik@ub.D.UMN.EDU>
XReceived: by shamash.shamash.UUCP (3.2/SMI-3.2)
X	id AA01185; Fri, 4 Sep 87 08:45:13 CDT
XReceived: by umn-cs.cs.umn.edu (5.51/4.7)
X	id AA10858; Fri, 4 Sep 87 08:31:29 CDT
XReceived: by ub.D.UMN.EDU (5.51/9.7)
X	id AA14727; Fri, 4 Sep 87 08:32:45 CDT
XDate: Fri, 4 Sep 87 08:32:45 CDT
XFrom: umn-cs!jwabik@ub.D.UMN.EDU (Jeff Wabik)
XMessage-Id: <8709041332.AA14727@ub.D.UMN.EDU>
XTo: umn-cs!shamash!jwabik
XStatus: R
X
X>From hermix!fischer@rand-unix.ARPA Thu Sep  3 13:20:44 1987
XReceived: from rand-unix.rand.org (RAND-UNIX.ARPA) by ub.D.UMN.EDU with SMTP (5.51/9.7)
X	id AA26121; Thu, 3 Sep 87 13:20:35 CDT
XReceived: by rand-unix.rand.org; Thu, 3 Sep 87 10:37:06 PDT
XMessage-Id: <8709031737.AA24314@rand-unix.rand.org>
XFrom: Herm Fischer <hermix!fischer@rand-unix.ARPA>
XReply-To: hermix!fischer@rand-unix.ARPA
XTo: jwabik@ub.d.umn.edu
XSubject: ada grammar
XDate: Thu Sep  3 10:05:57 1987
X
XJeff,
X
Xfollowing two messages are  a shar file of the public domain version of
Xthe ada grammar plus a second message which replaces the lex.
X
XThe version we used here gets pretty deep into the yacc/lex process, replacing
Xthe lexer stack, etc.  Let me know how you do with these, and if you
Xneed more, we can look at the specific stuff done here...
X
X  Herm
X
X
X
*-*-END-of-ada.note-*-*
echo x - release
sed 's/^X//' >release <<'*-*-END-of-release-*-*'
XThanks for your response to my posting to comp.lang.ada.  The YACC and LEX
Xfor Ada are much too large to send as one piece, so I've broken the mailing 
Xdown into three pieces:
X
X	1)  a README, an "ada.doc" and a distribution list;
X	2)  The Ada YACC specs
X	3)  The Ada LEX specs
X
X
XIf you don't get all three of these very very soon, let me know so I can
Xremail them.  
X
XHappy hacking!
X
X	-Jeff
*-*-END-of-release-*-*
exit

jwabik@shamash.UUCP (09/26/87)

Here is the Ada YACC:

/*--------------------------------------------------------------------------*/
/*									    */
/*			 A LALR(1) grammar for ANSI Ada*		    */
/*									    */
/*			 Adapted for YACC (UNIX) Inputs 		    */
/*									    */
/*                                                                          */
/*                             Herman Fischer                               */
/*                           Litton Data Systems                            */
/*                       8000 Woodley Ave., ms 44-30                        */
/*                              Van Nuys, CA                                */
/*                                                                          */
/*                              818/902-5139                                */
/*                           HFischer@eclb.arpa                             */
/*                        {cepu,trwrb}!litvax!fischer                       */
/*                                                                          */
/*                             March 26, 1984                               */
/*									    */
/*                   A Contribution to the Public Domain                    */
/*                                   for                                    */
/*            Research, Development, and Training Purposes Only             */
/*                                                                          */
/*       Any Corrections or Problems are to be Reported to the Author       */
/*                                                                          */
/*                                                                          */
/*                                                                          */
/*                                                                          */
/*  Mods to the original: Jeff Wabik, Control Data Corporation		    */
/*  September, 1987:  Mainly reformatted to make the YACC readable          */
/*  { umn-cs!shamash!jwabik }					    	    */
/*  Disclaim:  CDC is not responsible.					    */
/*                                                                          */
/*  Note that Herm Fischer's new address, effective 9/23/87, is:            */
/*  { hermix!fischer@rand-unix.ARPA }					    */
/*  { {ihnp4,decvax,trwrb,seismo,etc.}!hermix!fischer }			    */
/*                                                                          */
/*                                                                          */
/*                                                                          */
/*                                                                          */
/*                              adapted from                                */
/*                              the grammar                                 */
/*                                  by:                                     */
/*									    */
/*            Gerry Fisher                         Philippe Charles         */
/*                                                                          */
/*    Computer Sciences Corporation     &             Ada  Project          */
/*         4045 Hancock Street                     New York University      */
/*         San Diego, CA 92121                      251 Mercer Street       */
/*                                               New York, New York 10012   */
/*									    */
/*									    */
/*    This grammar is organized in the same order as the syntax summary     */
/* in appendix E of the ANSI Ada Reference Manual.   All reserved words     */
/* are	 written  in  upper  case  letters.    The  lexical  categories     */
/* NUMERIC_LITERAL, STRING_LITERAL, etc, are viewed as terminals.   The     */
/* rules  for  pragmas as  stated in  chapter 2,  section 8,  have been     */
/* incorporated in the grammar.   Comments are included wherever we had     */
/* to deviate from the syntax given in appendix E. Different symbols	    */
/* used here (to comply with yacc requirements) are of note:		    */
/*	{,something}	is denoted ...something..			    */
/*	{something}	is denoted ..something..			    */
/*	[something]	is denoted .something.				    */
/* Constructs involving                                                     */
/* meta brackets, e.g., ...IDENTIFIER.. are represented by a nonterminal    */
/* formed  by  concatenating  the  construct symbols ( as ...IDENTIFIER..   */
/* in the example)   for  which  the  rules are given at the end.  When     */
/* reading  this  grammar,  it	is  important to  note that all symbols     */
/* appearing  in the  rules are  separated by  one or  more  blanks.  A     */
/* string  such  as   'IDENTIFIER_type_mark   is  actually  a   single      */
/* nonterminal symbol defined at the end of the rules.  The '/*' symbol     */
/* is used  to indicate that the rest of  the  line is a comment,  just     */
/* as in yacc programs.                                                     */
/*                                                                          */
/*     This grammar is presented here in a form suitable for input to a     */
/* yacc parser generator.  It has  been  processed  by the Bell System      */
/* III lex/yacc combination, and tested against over 400 ACVC tests.        */
/*									    */
/* *Ada is a registered trade mark of the  Department of  Defense  (Ada     */
/* Joint Program  Office).						    */
/*									    */
/*--------------------------------------------------------------------------*/


/*%terminals -----------------------------------------------------------    */

%{ 

#include <stdio.h>
#include <ctype.h>

extern char yytext[];
extern int yylineno;

%}


%union {
	char *y_str;
	int y_num;
};

%token ABORT_ ABS_ ACCEPT_  ACCESS_ ALL_  AND_ ARRAY_
%token AT_ BEGIN_  BODY_ CASE_  CONSTANT_
%token DECLARE_ DELAY_ DELTA_ DIGITS_ DO_ ELSE_ ELSIF_
%token END_  ENTRY_ EXCEPTION_ EXIT_ FOR_
%token FUNCTION_ GENERIC_  GOTO_ IF_ IN_  IS_ LIMITED_
%token LOOP_ MOD_  NEW_ NOT_  NULL_ OF_ OR_
%token OTHERS_ OUT_  PACKAGE_ PRAGMA_  PRIVATE_
%token PROCEDURE_  RAISE_  RANGE_ RECORD_ REM_
%token RENAMES_ RETURN_ REVERSE_  SELECT_  SEPARATE_
%token SUBTYPE_	TASK_ TERMINATE_	THEN_
%token TYPE_ USE_ WHEN_ WHILE_ WITH_ XOR_

%token IDENTIFIER NUMERIC_LITERAL STRING_LITERAL CHARACTER_LITERAL
%token ARROW_ DBLDOT_ EXP_ ASSIGN_ NOTEQL_ GTEQL_ LTEQ_ L_LBL_ R_LBL_ BOX_

%start compilation

%%


/* 2.8 */
prag		: PRAGMA_ IDENTIFIER .arg_ascs ';' 
		;

arg_asc		: expr
   		| IDENTIFIER ARROW_ expr  
		;

/* 3.1 */
basic_d  	: object_d
		| ty_d	       
		| subty_d
		| subprg_d       
		| pkg_d
		| task_d	       
		| gen_d
		| excptn_d       
		| gen_inst
		| renaming_d     
		| number_d
		| error ';' 
		;

/* 3.2 */
object_d  	: idents ':' subty_ind ._ASN_expr. ';'
		| idents ':'  CONSTANT_ subty_ind ._ASN_expr. ';'
		| idents ':'  c_arr_def ._ASN_expr. ';'
		| idents ':'  CONSTANT_ c_arr_def ._ASN_expr. ';' 
		;

number_d  	: idents ':' CONSTANT_ ASSIGN_ expr ';' 
		;

idents	 	: IDENTIFIER ...ident..	
		;

/* 3.3.1 */
ty_d  		: full_ty_d
	        | incomplete_ty_d
		| priv_ty_d  
		;

full_ty_d  	: TYPE_ IDENTIFIER            IS_ ty_def ';'
   		| TYPE_ IDENTIFIER discr_part IS_ ty_def ';' 
		;

ty_def	 	: enum_ty_def		
		| integer_ty_def
		| real_ty_def			
		| array_ty_def
		| rec_ty_def 		
		| access_ty_def
		| derived_ty_def 
		;

/* 3.3.2 */
subty_d  	: SUBTYPE_ IDENTIFIER IS_ subty_ind ';' 
		;

subty_ind  	: ty_mk .constrt. 	
		;

ty_mk  		: expanded_n 
		;

constrt  	: rng_c
		| fltg_point_c  
		| fixed_point_c
		| aggr 
		;

/* 3.4 */
derived_ty_def	: NEW_ subty_ind 
		;


/* 3.5 */
rng_c  		: RANGE_ rng 
		;

rng  		: name
	        | sim_expr DBLDOT_ sim_expr	
		;

/* 3.5.1 */
enum_ty_def     : '(' enum_lit_spec ...enum_lit_spec.. ')' 
		;


enum_lit_spec   : enum_lit 
		;

enum_lit  	: IDENTIFIER  
		| CHARACTER_LITERAL 
		;

/* 3.5.4 */
integer_ty_def	: rng_c 
		;

/* 3.5.6 */
real_ty_def	: fltg_point_c  
		| fixed_point_c 
		;

/* 3.5.7 */
fltg_point_c  	: fltg_accuracy_def .rng_c. 
		;

fltg_accuracy_def	: DIGITS_ sim_expr 
		;

/* 3.5.9 */
fixed_point_c	: fixed_accuracy_def .rng_c. 
		;

fixed_accuracy_def	: DELTA_ sim_expr 
		;

/* 3.6 */
array_ty_def	: uncnstrnd_array_def
		|  c_arr_def 
		;

uncnstrnd_array_def : ARRAY_ '(' idx_subty_def ...idx_subty_def.. ')' OF_
					 subty_ind 
		;


c_arr_def	: ARRAY_ idx_c OF_ subty_ind 
		;


idx_subty_def   : name  RANGE_ BOX_ 
		;


idx_c  		: '(' dscr_rng ...dscr_rng.. ')' 
		;

dscr_rng	: rng
   		| name rng_c	
		;

/* 3.7 */
rec_ty_def 	: RECORD_ cmpons END_ RECORD_ 
		;

cmpons		: ..prag.. ..cmpon_d.. cmpon_d ..prag..
		|	..prag.. ..cmpon_d.. variant_part ..prag..
		|    ..prag.. NULL_ ';' ..prag.. 
		;

cmpon_d  	: idents ':' cmpon_subty_def ._ASN_expr. ';'  
		;

cmpon_subty_def	:  subty_ind 
		;

/* 3.7.1 */
discr_part  	: '(' discr_spec ...discr_spec.. ')' 
		;

discr_spec  	: idents ':' ty_mk ._ASN_expr. 
		;

/* 3.7.2 */
/*discr_c	: '(' discr_asc ... discr_asc.. ')' ;                */

/*discr_asc	: .discr_sim_n ..or_discrim_sim_n.. ARROW. expressi */
/*	 	;							     */

/*"discr_c" is included under "aggr"		     */


/* 3.7.3 */
variant_part  	: CASE_ sim_n IS_ ..prag.. variant ..variant..  END_ CASE_ ';' 
		;

variant  	: WHEN_ choice ..or_choice.. ARROW_ cmpons 
		;

choice		: sim_expr
	        | name rng_c
	        | sim_expr DBLDOT_ sim_expr
	        | OTHERS_ 
		;

/* 3.8 */
access_ty_def 	: ACCESS_ subty_ind 
		;

/* 3.8.1 */
incomplete_ty_d : TYPE_ IDENTIFIER ';'
	        | TYPE_ IDENTIFIER discr_part ';'  
		;

/* 3.9 */
decl_part	: ..basic_decl_item..
	        | ..basic_decl_item.. body ..later_decl_item.. 
		;

basic_decl_item : basic_d
		| rep_cl  
  		| use_cl	
		;

later_decl_item : body
	        | subprg_d	
	        | pkg_d
	        | task_d	
	        | gen_d
	        | use_cl		
	        | gen_inst   
		;

body  		: proper_body 	
		| body_stub  
		;

proper_body  	: subprg_body  
		| pkg_body  	
		| task_body	 
		;

/* 4.1 */

name  		: sim_n
	        | CHARACTER_LITERAL  
	        | op_symbol
	        | idxed_cmpon
	        | selected_cmpon 
	        | attribute 
	        ;


sim_n  		: IDENTIFIER  
		;

prefix		: name  
		;

/* 4.1.1 */
idxed_cmpon  	: prefix aggr  
		;

/* 4.1.2 */

/* slice  :  prefix '(' dscr_rng ')' ;       */
/*						   */
/* included under "idxed_cmpon".		   */


/* 4.1.3 */

selected_cmpon  : prefix '.' selector  
		;

selector  	: sim_n
	        |    CHARACTER_LITERAL  
	        |  op_symbol  
	        |  ALL_  
		;

/* 4.1.4 */

attribute  	: prefix '\'' attribute_designator 
		;
/*  This can be an attribute, idxed cmpon, slice, or subprg call. */
attribute_designator : sim_n
   		| DIGITS_
   		| DELTA_
   		| RANGE_	  
		;

/* 4.3 */
aggr  		: '(' cmpon_asc ...cmpon_asc.. ')' 
		;

cmpon_asc       : expr
	        | choice ..or_choice.. ARROW_ expr
	        | sim_expr DBLDOT_ sim_expr
	        | name rng_c 
		;

/* 4.4 */

expr  		: rel..AND__rel..  
		| rel..AND__THEN__rel..
		| rel..OR__rel.. 
		| rel..OR__ELSE__rel..
		| rel..XOR__rel..  
		;

rel  		: sim_expr .relal_op__sim_expr.
   		| sim_expr.NOT.IN__rng_or_sim_expr.NOT.IN__ty_mk 
		;

sim_expr  	: .unary_add_op.term..binary_add_op__term.. 
		;

term  		:  factor..mult_op__factor..  
		;

factor		:  pri ._EXP___pri.  
		|	ABS_ pri  
		|	NOT_ pri  
		;

pri  		: NUMERIC_LITERAL    
		|  NULL_
   		|	allocator  
   		|  qualified_expr
   		|	name
   		|	aggr 
		;

/* "'(' expr ')'" is included under "aggr".  */


/* 4.5 */

/* logical_op  	: AND_  
		| OR_  
		| XOR_  ;	*/
/*						*/
/* This is an unused syntactic class.		*/


relal_op 	:  '='  
		|  NOTEQL_  
		|  '<'  
		|  LTEQ_  
		|  '>'  
		|  GTEQL_  
		;


binary_add_op  	:  '+'  
		|  '-'  
		|  '&' 
		;


unary_add_op  	:  '+'  
		|  '-'  
		;


mult_op  	:  '*'  
		|  '/'  
		|  MOD_  
		|  REM_  
		;


/* highest_precedence_op	:  EXP_	 
		|   ABS_   
		|   NOT_   
		;	 */
/*								  */
/* This is an unused syntactic class.				  */



/* 4.6 */
/* ty_cnvr  	:  ty_mk '(' expr ')' ;     */
/*							  */
/* The class "ty_cnvr" is included under "name".  */


/* 4.7	*/
qualified_expr	: ty_mkaggr_or_ty_mkPexprP_ 
		;



/* 4.8 */
allocator  	: NEW_ ty_mk
   		| NEW_ ty_mk aggr
   		| NEW_ ty_mk '\'' aggr  
		;

/* 5.1 */
seq_of_stmts	: ..prag.. stmt ..stmt..  
		;


stmt  		: ..label.. sim_stmt  
		| ..label.. compound_stmt
   		| error    ';'  
		;

sim_stmt  	:null_stmt
   		| assignment_stmt   
   		| exit_stmt
   		| return_stmt	  
   		| goto_stmt
   		| delay_stmt	  
   		| abort_stmt
   		| raise_stmt	  
   		| code_stmt
   		| name ';' 
		;

/* Procedure and ent call stmts are included under "name".   */


compound_stmt  	: if_stmt   
		|  case_stmt
   		|	loop_stmt	  
   		|  block_stmt
   		|	accept_stmt  
   		|	select_stmt  
		;

label  		:  L_LBL_ sim_n R_LBL_  
		;

null_stmt  	:  NULL_ ';'  
		;

/* 5.2 */
assignment_stmt :  name ASSIGN_ expr ';' 
		;

/* 5.3 */

if_stmt  	: IF_ cond THEN_ seq_of_stmts
		    ..ELSIF__cond__THEN__seq_of_stmts..
		    .ELSE__seq_of_stmts.
		    END_ IF_ ';' 
	        ;

cond  		:  expr 
		;


/* 5.4 */
case_stmt	: CASE_ expr IS_ case_stmt_alt..case_stmt_alt..  END_ CASE_ ';' 
		;

case_stmt_alt  	: WHEN_ choice ..or_choice.. ARROW_ seq_of_stmts 
		;

/* 5.5	*/
loop_stmt	: .sim_nC.  /*simple name colon */
		     .iteration_scheme. LOOP_
			 seq_of_stmts
		     END_ LOOP_ .sim_n. ';' 
	        ;

iteration_scheme: WHILE_ cond
   		| FOR_ loop_prm_spec 
		;

loop_prm_spec   : IDENTIFIER IN_ .REVERSE. dscr_rng 
		;

/* 5.6 */
block_stmt  	: .sim_nC. .DECLARE__decl_part.  
			BEGIN_
			   seq_of_stmts
			   .EXCEPTION__excptn_handler..excptn_handler...
			END_ .sim_n. ';' 
		;

/* 5.7 */
exit_stmt	: EXIT_ .expanded_n. .WHEN__cond. ';' 
		;

/* 5.8 */
return_stmt  	:  RETURN_ .expr. ';' 
		;

/* 5.9 */
goto_stmt  	:  GOTO_ expanded_n ';' 
		;

/* 6.1 */
subprg_d  	:  subprg_spec ';'  
		;

subprg_spec  	: PROCEDURE_ IDENTIFIER 
   	     	| FUNCTION_ designator .fml_part. RETURN_ ty_mk  
		;

designator  	:  IDENTIFIER
		|  op_symbol
		;


op_symbol  	:  STRING_LITERAL 
		;

fml_part  	: '(' prm_spec .._.prm_spec.. ')' 
		;

prm_spec  	: idents ':' mode ty_mk ._ASN_expr.  
		;

mode  		:  .IN.  
		|  IN_ OUT_  
		|  OUT_   
		;

/* 6.3 */
subprg_body  	: subprg_spec IS_ .decl_part.
		  BEGIN_
		     seq_of_stmts
		     .EXCEPTION__excptn_handler..excptn_handler...
		  END_ .designator. ';' 
		;

/* 6.4 */
/* procedure_call_stmt	: procedure_n .act_prm_part. ';' 
		;                        */

/* func_call  	: func_n .act_prm.  
		;    */

/* act_prm_part : '(' prm_asc ... prm_asc .._paren 
		;                  */

/* prm_asc	: .fml_prm ARROW. act_prm	
		;   */

/* fml_prm  	: sim_n  
		;  */

/* act_prm  	: expr  
	    	|  name  
		|  ty_mk '(' name ')'
		;  */

/* "procedure_call_stmt" and "func_call" are included under "name".*/



/* 7.1 */

pkg_d  	  	: pkg_spec ';'  
		;

pkg_spec  	: PACKAGE_ IDENTIFIER IS_ ..basic_decl_item..
	    	  .PRIVATE..basic_decl_item...  END_ .sim_n.   
		;


pkg_body  	: PACKAGE_ BODY_ sim_n IS_
		     .decl_part.
		     .BEGIN__seq_of_stmts.EXCEPTION__excptn_handler..excptn_handler...
		  END_ .sim_n. ';'   
		;

/* 7.4	*/
priv_ty_d  	: TYPE_ IDENTIFIER IS_ .LIMITED. PRIVATE_ ';'
      		| TYPE_ IDENTIFIER discr_part IS_ .LIMITED. PRIVATE_ ';' ;

/* defer_const_d: idents : CONSTANT_ ty_mk ';'       
		;  */

/* 8.4 */
use_cl  	:  USE_ expanded_n ...expanded_n.. ';'  
		;

/* 8.5 */
renaming_d  	: idents ':' ty_mk      RENAMES_ name ';'
   		|    idents ':' EXCEPTION_      RENAMES_ expanded_n ';'
   		|    PACKAGE_ IDENTIFIER        RENAMES_ expanded_n ';'
   		|    subprg_spec  RENAMES_ name ';'   
		;

/* idents in the two above rule must contain only one */
/* IDENTIFIER.						       */

/* 9.1 */
task_d  	:  task_spec ';'  
		;

task_spec  	: TASK_ .TYPE. IDENTIFIER .IS..ent_d_..rep_cl_END.sim_n.
	        ;

task_body  	: TASK_ BODY_ sim_n IS_ .decl_part.
		  BEGIN_
		     seq_of_stmts
		  .EXCEPTION__excptn_handler..excptn_handler...
		  END_ .sim_n. ';' 
		;

/* 9.5 */
ent_d  		: ENTRY_ IDENTIFIER .fml_part. ';'
   		| ENTRY_ IDENTIFIER '(' dscr_rng ')' .fml_part. ';'  
		;

ent_call_stmt  	: ..prag.. name ';' 
		;

accept_stmt  	: ACCEPT_ sim_n .Pent_idx_P..fml_part.
		  .DO__seq_of_stmts__END.sim_n.. ';' 
		;

ent_idx  	: expr   
		;

/* 9.6 */
delay_stmt  	: DELAY_ sim_expr ';' 
		;

/* 9.7 */
select_stmt  	:	selec_wait
   		|	condal_ent_call	
   		|  timed_ent_call  
		;

/* 9.7.1 */
selec_wait	: SELECT_ select_alt 
		  ..OR__select_alt..  
		  .ELSE__seq_of_stmts.
        	  END_ SELECT_ ';' 
		;


select_alt  	: .WHEN__condARROW.selec_wait_alt  
		;

selec_wait_alt  :  accept_alt
   		|	delay_alt  
   		|  terminate_alt  
		;

accept_alt  	: accept_stmt.seq_of_stmts.  
		;

delay_alt  	: delay_stmt.seq_of_stmts.  
		;

terminate_alt  	:  TERM_stmt   
		;

/* 9.7.2 */
condal_ent_call	: SELECT_
			ent_call_stmt
			.seq_of_stmts.
		    ELSE_
			seq_of_stmts
		    END_ SELECT_ ';' 
		;

/* 9.7.3 */
timed_ent_call  : SELECT_ ent_call_stmt .seq_of_stmts.
		  OR_ delay_alt END_ SELECT_ ';' 
		;


/* 9.10  */

abort_stmt  	: ABORT_ name ...name.. ';'  
		;

/* 10.1 */

compilation 	: ..compilation_unit..   
		;

compilation_unit: context_cl library_unit
   		| context_cl secondary_unit 
		;

library_unit  	: subprg_d	
		| pkg_d
   		| gen_d	
   		| gen_inst
   		| subprg_body     
		;

secondary_unit	: library_unit_body  
		| subunit	
		;

library_unit_body  : pkg_body_or_subprg_body  
		;

/* 10.1.1  */
context_cl      : ..with_cl..use_cl.... 
		;

with_cl  	: WITH_ sim_n ...sim_n.. ';'  
		;

/* 10.2 */
body_stub  	: subprg_spec IS_ SEPARATE_ ';'
   		| PACKAGE_ BODY_ sim_n IS_ SEPARATE_ ';'
   		| TASK_ BODY_ sim_n    IS_ SEPARATE_ ';'   
		;


subunit  	: SEPARATE_ '(' expanded_n ')' proper_body  
		;

/* 11.1 */

excptn_d  	: idents ':' EXCEPTION_ ';' 
		;

/* 11.2 */

excptn_handler	: WHEN_ excptn_choice ..or_excptn_choice.. ARROW_
	    	  seq_of_stmts  
		;


excptn_choice   : expanded_n  
		| OTHERS_	
		;


/* 11.3 */
raise_stmt  	: RAISE_ .expanded_n. ';' 
		;

/* 12.1 */
gen_d  		: gen_spec ';'  
		;

gen_spec  	: gen_fml_part subprg_spec
   		| gen_fml_part pkg_spec  
		;


gen_fml_part    : GENERIC_ ..gen_prm_d..  
		;


gen_prm_d  	: idents ':' .IN.OUT.. ty_mk ._ASN_expr. ';'
   		| TYPE_ IDENTIFIER IS_ gen_ty_def ';'
   		| priv_ty_d
   		| WITH_ subprg_spec .IS_BOX_. ';' ;
/* 		| WITH_ subprg_spec .IS_ name. ';'  */
/*						     */
/* This rule is included in the previous one.	     */


gen_ty_def	: '(' BOX_ ')'  
		|  RANGE_ BOX_  
		|  DIGITS_ BOX_  
		|  DELTA_ BOX_
   		| array_ty_def	       
   		|  access_ty_def	   
		;

/* 12.3  */
gen_inst  	: PACKAGE_ IDENTIFIER IS_ NEW_ expanded_n .gen_act_part. ';'
   		| PROCEDURE__ident__IS_ NEW_ expanded_n .gen_act_part. ';'
   		| FUNCTION_  designator IS_ NEW_ expanded_n .gen_act_part. ';'  
		;

gen_act_part  	: '(' gen_asc ...gen_asc.. ')'              
		;


gen_asc	     	: .gen_fml_prmARROW.gen_act_prm 
		;

gen_fml_prm  	: sim_n  
	        | op_symbol  
		;

gen_act_prm 	: expr_or_name_or_subprg_n_or_ent_n_or_ty_mk
	 	;

/* 13.1 */

rep_cl  	: ty_rep_cl  
		| address_cl  
		;

ty_rep_cl  	: length_cl
   		| enum_rep_cl
   		| rec_rep_cl	    
		;

/* 13.2 */
length_cl  	: FOR_ attribute USE_ sim_expr ';' 
		;

/* 13.3 */
enum_rep_cl  	: FOR__ty_sim_n__USE_ aggr ';' 
		;

/* 13.4  */
rec_rep_cl	: FOR__ty_sim_n__USE_ RECORD_ .algt_cl. 
		  ..cmpon_cl..  END_ RECORD_ ';'   
		;

algt_cl  	:     AT_ MOD_ sim_expr ';' 
		;

cmpon_cl  	: name AT_ sim_expr RANGE_ rng ';' 
		;

/* 13.5 */
address_cl  	: FOR_ sim_n USE_ AT_ sim_expr ';'  
		;

/* 13.8 */

code_stmt  	: ty_mk_rec_aggr ';' 
		;


/*----------------------------------------------------------------------*/

/* The following rules define semantically qualified symbols under more
/* general categories.

ty_n_or_subty_n : expanded_n 
		;

/* An "expanded_n" is used for names that can be written using only*/
/* selectors.							      */

/*     ... these have been replaced logically to reduce the number    */
/*         of YACC_ nonterminal "rules"                                */

/* The following rules expand the concatenated constructs and define the */
/* specially added syntactical classes. 				 */


/* 2.1 */

	
..prag..	: /* empty */
   		| ..prag.. prag  
		;

.arg_ascs 	: /* empty */
   		| '(' arg_ascs ')' 
		;

arg_ascs 	: arg_asc
		| arg_ascs ',' arg_asc 
		;


/* "name" is included under "expr"	*/
/* 3.1 */
/*  "defer_const_d" is included under "object_d".*/

._ASN_expr.	: /* empty */
   		| ASSIGN_ expr  
		;

...ident..  	: /* empty */
   		| ...ident.. ',' IDENTIFIER   
		;

.constrt.  	: /* empty */
   		| constrt   
		;

/* "idx_c" and "discr_c" are included under	 */
/* the class "aggr".						 */

expanded_n  	: IDENTIFIER
	   	| expanded_n '.' IDENTIFIER   
		;

/*  This expansion generalizes "rng" so that it may include ty and */
/*  subty names.						       */

...enum_lit_spec.. : /* empty */
   		| ...enum_lit_spec.. ',' enum_lit_spec 
		;

.rng_c.  	: /* empty */
   		| rng_c	
		;

...idx_subty_def.. : /* empty */
   		| ...idx_subty_def.. ',' idx_subty_def                
		;


/* To avoid conflicts, the more general class "name" is used.	   */
...dscr_rng.. : /* empty */
   		| ...dscr_rng.. ',' dscr_rng  
		;

/* A_ dscr subty ind given as a ty mk is included under rng*/
..cmpon_d.. 	: /* empty */
		| ..cmpon_d.. cmpon_d ..prag..    
		;

...discr_spec..	: /* empty */
   		|    ...discr_spec.. ';' discr_spec  
		;

/* Pragmas that can appear between two consecutive variants are picked	*/
/* up in the cmpons part of the variants themselves.		*/

..variant..  	: /* empty */
   		|	..variant.. variant  
		;

..or_choice.. 	: /* empty */
   		|    ..or_choice.. '|' choice  
		;

/* The "sim_expr" by itself may be a "dscr_rng" or a  */
/* "cmpon_sim_n".					     */

/* A_ body is the only later_decl_item that is not also a	   */
/* basic_decl_item.	    It is therefore used as the dividing   */
/* point between the two lists of decl items.			   */

..basic_decl_item.. : ..prag..
		| ..basic_decl_item.. basic_decl_item ..prag.. 
		;

..later_decl_item.. : ..prag..
   		| ..later_decl_item.. later_decl_item ..prag..  
		;

/* 4.1 */
/* "slice" is included under "idxed_cmpon".  */
/* The def of "name" includes "func_call".				*/
/* A_ prmless func call is recognized as a sim name or a	*/
/* selected cmpon.	A_ func call with prms is recognized	*/
/* as an idxed cmpon.						*/

/* Reserved word attribute designators are included in the rules as a	     */
/* convenience.  Alternativly, since an attribute designator is always preced*/
/* by an apostrophe, as noted in the RR_ 4.1.4, such usage may be detected    */
/* during lexical analysis thus obviating the need for special rules.	     */
/*									     */
/* The univ static expr of an attribute designator is reduced     */
/* as an "idxed_cmpon".						     */

...cmpon_asc..	: /* empty */
		| ...cmpon_asc.. ',' cmpon_asc 
		;

/* Component ascs are generalized to include dscr rngs. 	   */
/* Thus, an "aggr" can be used for slices and idx and discr  */
/* constrts.							   */

rel..AND__rel.. : rel AND_ rel
		|rel..AND__rel.. AND_ rel	 
		;

rel..OR__rel..  : rel OR_ rel
		| rel..OR__rel.. OR_ rel 
		;

rel..XOR__rel.. : rel
		| ..XOR__rel..  
		;

..XOR__rel..    : rel XOR_ rel
		| ..XOR__rel.. XOR_ rel	
		;

rel..AND__THEN__rel..  : rel AND_ THEN_ rel
		| rel..AND__THEN__rel.. AND_ THEN_ rel  
		;

rel..OR__ELSE__rel.. : rel OR_ ELSE_ rel
		| rel..OR__ELSE__rel.. OR_ ELSE_ rel  
		;

.relal_op__sim_expr.  : /* empty */
		| relal_op sim_expr  
		;

sim_expr.NOT.IN__rng_or_sim_expr.NOT.IN__ty_mk	: sim_expr .NOT. IN_ rng 
		;

/* The "ty_mk" is included under "rng"  */

.NOT.  :
       /* empty */
| NOT_    ;

.unary_add_op.term..binary_add_op__term..  : term
		| unary_add_op term
		| .unary_add_op.term..binary_add_op__term..  binary_add_op term 
		;

factor..mult_op__factor.. : factor
		| factor..mult_op__factor.. mult_op factor 
		;

._EXP___pri.  	: /* empty */
   		| EXP_ pri 
		;

/* "stringsit" is included under "name" as "op_symbol".  */
/* "func_call" is included under "name".			    */
/* "ty_cnvr" is included under "name".			    */

ty_mkaggr_or_ty_mkPexprP_  : prefix '\'' aggr 
		;

/* The "prefix must be a "ty_mk".  The "PexprP_" is an "aggr". */
/* Here the "qualified_expr" can be given exactly  */
/* We use the fact that the constrt must be an idx or discr  */
/* constrt.								 */

/* 5.1 */


..stmt..  	: ..prag..
		| ..stmt.. stmt ..prag.. 
		;

..label..   	: /* empty */
		| ..label.. label  
		;

..ELSIF__cond__THEN__seq_of_stmts..  : /* empty */
		| ..ELSIF__cond__THEN__seq_of_stmts..  ELSIF_ cond THEN_
		    seq_of_stmts   
	        ;

.ELSE__seq_of_stmts. : /* empty */
		| ELSE_ seq_of_stmts    
		;

case_stmt_alt..case_stmt_alt.. : ..prag..  case_stmt_alt ..case_stmt_alt..  
		;

..case_stmt_alt.. : /* empty */
		| ..case_stmt_alt.. case_stmt_alt 
		;

.sim_nC.	: /* empty */
		| sim_n ':' 
		;

.sim_n. 	: /* empty */
		| sim_n  
		;

.iteration_scheme. : /* empty */
		| iteration_scheme  
		;

.REVERSE. 	: /* empty */
		| REVERSE_   
		;

.DECLARE__decl_part. : /* empty */
   		| DECLARE_ decl_part		
		;

.EXCEPTION__excptn_handler..excptn_handler... : /* empty */
		| EXCEPTION_ ..prag.. excptn_handlers	 
		;

excptn_handlers	: excptn_handler
		| excptn_handlers excptn_handler   
		;

.expanded_n.  	: /* empty */
		| expanded_n  
		;

.WHEN__cond.  	: /* empty */
   		|	WHEN_ cond	
		;

.expr.		: /* empty */
   		| expr   
		;

/* 6.1 */

.fml_part.  	: /* empty */
   		| fml_part  
		;

.._.prm_spec..  : /* empty */
		| .._.prm_spec.. ';' prm_spec  
		;

.IN.  		: /* empty */
		| IN_	  
		;

.decl_part.	: decl_part	 
		;
/* A_ "decl_part" may be empty.		*/

.designator.  	: /* empty */
		| designator    
		;

/* 7.1	*/

.PRIVATE..basic_decl_item... : /* empty */
		| PRIVATE_ ..basic_decl_item.. 
		;

.BEGIN__seq_of_stmts.EXCEPTION__excptn_handler..excptn_handler...  : /* empty */
		| BEGIN_ seq_of_stmts
	          .EXCEPTION__excptn_handler..excptn_handler...  
	        ;

.LIMITED.  	: /* empty */
		| LIMITED_    
		;

...expanded_n.. : /* empty */
		| ...expanded_n.. ',' expanded_n  
		;

/* 9.1 */

.TYPE.		: /* empty */
		| TYPE_   
		;

.IS..ent_d_..rep_cl_END.sim_n.  : /* empty */
		| IS_ ..ent_d..  ..rep_cl..  END_ .sim_n.	      
		;


..ent_d..  	: ..prag..
   		|	..ent_d.. ent_d ..prag..	
		;

..rep_cl..  	: /* empty */
   		| ..rep_cl.. rep_cl ..prag..	
		;

.Pent_idx_P..fml_part. : .fml_part.
   		|    '(' ent_idx ')' .fml_part.  
		;

.DO__seq_of_stmts__END.sim_n.. : /* empty */
   		| DO_ seq_of_stmts END_ .sim_n.  
		;

..OR__select_alt..  : /* empty */
   		| ..OR__select_alt.. OR_ select_alt	
   		;

.WHEN__condARROW.selec_wait_alt  : selec_wait_alt
		| WHEN_ cond ARROW_ selec_wait_alt  
		;

accept_stmt.seq_of_stmts.  : ..prag.. accept_stmt .seq_of_stmts.  
		;

delay_stmt.seq_of_stmts.  : ..prag.. delay_stmt .seq_of_stmts. 
		;

TERM_stmt   	: ..prag.. TERMINATE_ ';' ..prag..  
		;

.seq_of_stmts.	: ..prag..
		| seq_of_stmts	
		;

...name..	: /* empty */
		| ...name.. ',' name  
		;

/* 10.1 */

..compilation_unit.. : ..prag..
		| ..compilation_unit.. compilation_unit ..prag.. 
		;

pkg_body_or_subprg_body   :  pkg_body  
		;

/* "subprg_body" is already contained in the class "library_unit". */

..with_cl..use_cl.... : /* empty */
		| ..with_cl..use_cl.... with_cl use_cls 
		;

use_cls  	: ..prag..
		| use_cls use_cl ..prag..  
		;

...sim_n..  	: /* empty */
		| ...sim_n.. ',' sim_n  
		;

/* 11.1  */

..or_excptn_choice.. : /* empty */
		| ..or_excptn_choice.. '|' excptn_choice 
		;

/* 12.1 */

..gen_prm_d..  	: /* empty */
		| ..gen_prm_d.. gen_prm_d 
		;

.IN.OUT..  	: .IN.
		| IN_ OUT_	 
		;

.IS_BOX_.	: /* empty */
		| IS_ name
		| IS_ BOX_ 
		;

PROCEDURE__ident__IS_ : subprg_spec IS_ 
		;

/* To avoid conflicts, the more general "subprg_spec" is used.  */
.gen_act_part.  : /* empty */
   		| gen_act_part 
		;

...gen_asc.. 	: /* empty */
		| ...gen_asc.. ',' gen_asc 
		;

.gen_fml_prmARROW.gen_act_prm  : gen_act_prm
		| gen_fml_prm ARROW_ gen_act_prm  
		;

expr_or_name_or_subprg_n_or_ent_n_or_ty_mk : expr  
		;

/* The above alts are included under "expr". */


/* 13.1 */

FOR__ty_sim_n__USE_  : FOR_ sim_n USE_	
		;

/* The "sim_n" must be a "ty_sim_n". */
.algt_cl.  	: ..prag..
		| ..prag.. algt_cl ..prag..   
		;

..cmpon_cl..  	: /* empty */
		| ..cmpon_cl.. cmpon_cl ..prag..  
		;

ty_mk_rec_aggr  :  qualified_expr      
		;

jwabik@shamash.UUCP (09/26/87)

%{
/*------------------------------------------------------------------------*/
/* Lexical input for LEX for LALR(1) Grammar for ANSI Ada                 */
/*                                                                        */
/*              Herman Fischer                                            */
/*            Litton Data Systems                                         */
/*              March 26, 1984                                            */
/*                                                                        */
/* Rewrite:  To a version that a non-supercomputer can handle (8^) by:	  */
/*           Jeff Wabik, Control Data Corporation, September 1987	  */ 
/*	     { umn-cs!shamash!jwabik }				 	  */
/*                                                                        */
/*------------------------------------------------------------------------*/
#include "y.tab.h"
#include <stdio.h>
#include <ctype.h>

#define Token(a)	(int)a

%}

StringLetter		([^\n']|'')
WS			([\t\n ])
Word			([^\n^ ^\t']|'')

%START IDENT Z

%%
"--".*  ECHO;       		/* ignore comments to end-of-line */
[\ \t\n]		ECHO;  	/* ignore spaces and tabs */
"=>"    		{ECHO; BEGIN Z; return(ARROW_);}
".."    		{ECHO; BEGIN Z; return(DBLDOT_);}
"**"    		{ECHO; BEGIN Z; return(EXP_);}
":="    		{ECHO; BEGIN Z; return(ASSIGN_);}
"/="    		{ECHO; BEGIN Z; return(NOTEQL_);}
">="    		{ECHO; BEGIN Z; return(GTEQL_);}
"<="    		{ECHO; BEGIN Z; return(LTEQ_);}
"<<"    		{ECHO; BEGIN Z; return(L_LBL_);}
">>"    		{ECHO; BEGIN Z; return(R_LBL_);}
"<>"    		{ECHO; BEGIN Z; return(BOX_);}
"&"     		{ECHO; BEGIN Z; return('&'); }
"("     		{ECHO; BEGIN Z; return('('); }
")"     		{ECHO; BEGIN IDENT; return(')'); }
"*"     		{ECHO; BEGIN Z; return('*'); }
"+"     		{ECHO; BEGIN Z; return('+'); }
","     		{ECHO; BEGIN Z; return(','); }
"-"     		{ECHO; BEGIN Z; return('-'); }
"."     		{ECHO; BEGIN Z; return('.'); }
"/"     		{ECHO; BEGIN Z; return('/'); }
":"     		{ECHO; BEGIN Z; return(':'); }
";"     		{ECHO; BEGIN Z; return(';'); }
"<"     		{ECHO; BEGIN Z; return('<'); }
"="     		{ECHO; BEGIN Z; return('='); }
">"     		{ECHO; BEGIN Z; return('>'); }
"|"     		{ECHO; BEGIN Z; return('|'); }
<IDENT>\'  		{ECHO; BEGIN Z; return('\'');}   /* type mark only */


[a-z_A-Z][a-z_A-Z0-9]*  	{ ECHO; BEGIN IDENT; return(LookUp(yytext));}

[0-9][0-9_]*([.][0-9_]+)?([Ee][-+]?[0-9_]+)?  
				{ ECHO; BEGIN Z; return(NUMERIC_LITERAL);}

[0-9][0-9_]*#[0-9a-fA-F_]+([.][0-9a-fA-F_]+)?#([Ee][-+]?[0-9_]+)? 
				{ ECHO; BEGIN Z; return(NUMERIC_LITERAL);}


\"([^"]*(\"\")*)*\" 		{ECHO; BEGIN Z; return(STRING_LITERAL);}

<Z>\'([^']|\'\')\'    		{ECHO; BEGIN Z; return(CHARACTER_LITERAL);}


.       			{ECHO; 
				 printf("Syntax error \"%s\" at line %d.\n\t",
					 yytext,yylineno); }
%%

typedef struct token_struct {
   char *token;
   int tokval;
} TOKEN;

yywrap() {
	return(1);
}

LookUp(key) 
char *key; 
/*
	 Compare what was just read in by LEX to the literal form
	 of the reserved word..  If its OK, return the TOKEN of the 
	 reserved word, else return the IDENTIFIER token.
*/
{
	 TOKEN *tokpnt;
	 extern TOKEN tokens[];
	 extern unsigned num_tokens;
	 int TokenCmp();
	 extern char *MakeUpper();

	 if ((tokpnt = (TOKEN *)bsearch(MakeUpper(key), tokens,num_tokens,
	      sizeof(TOKEN), TokenCmp)) != NULL)
	    return(tokpnt->tokval);
	 else {
	    yylval.y_str = (char *) calloc(strlen(yytext)+1,sizeof(char));
	    strcpy(yylval.y_str,yytext);
	    return(IDENTIFIER);
	 }
}

int TokenCmp(str,tab_ele)
char str[];
TOKEN *tab_ele;
{
	 return(strcmp(str,tab_ele->token));
}

char *MakeUpper(str)
char str[];
{

	 register int i;
	 static char up_str[256];

	 for (i=0; str[i] != '\0'; i++)
	    if (islower(str[i]))
	       up_str[i] = toupper(str[i]);
	    else
	       up_str[i] = str[i];
	 up_str[i] = '\0';
	 return up_str;
}

TOKEN tokens[] = {
   "ABORT", Token(ABORT_),
   "ABS", Token(ABS_),
   "ACCEPT", Token(ACCEPT_),
   "ACCESS", Token(ACCESS_),
   "ALL", Token(ALL_),
   "AND", Token(AND_),
   "ARRAY", Token(ARRAY_),
   "AT", Token(AT_),
   "BEGIN", Token(BEGIN_),
   "BODY", Token(BODY_),
   "CASE", Token(CASE_),
   "CONSTANT", Token(CONSTANT_),
   "DECLARE", Token(DECLARE_),
   "DELAY", Token(DELAY_),
   "DELTA", Token(DELTA_),
   "DIGITS", Token(DIGITS_),
   "DO", Token(DO_),
   "ELSE", Token(ELSE_),
   "ELSIF", Token(ELSIF_),
   "END", Token(END_),
   "ENTRY", Token(ENTRY_),
   "EXCEPTION", Token(EXCEPTION_),
   "EXIT", Token(EXIT_),
   "FOR", Token(FOR_),
   "FUNCTION", Token(FUNCTION_),
   "GENERIC", Token(GENERIC_),
   "GOTO", Token(GOTO_),
   "IF", Token(IF_),
   "IN", Token(IN_),
   "IS", Token(IS_),
   "LIMITED", Token(LIMITED_),
   "LOOP", Token(LOOP_),
   "MOD", Token(MOD_),
   "NEW", Token(NEW_),
   "NOT", Token(NOT_),
   "NULL", Token(NULL_),
   "OF", Token(OF_),
   "OR", Token(OR_),
   "OTHERS", Token(OTHERS_),
   "OUT", Token(OUT_),
   "PACKAGE", Token(PACKAGE_),
   "PRAGMA", Token(PRAGMA_),
   "PRIVATE", Token(PRIVATE_),
   "PROCEDURE", Token(PROCEDURE_),
   "RAISE", Token(RAISE_),
   "RANGE", Token(RANGE_),
   "RECORD", Token(RECORD_),
   "REM", Token(REM_),
   "RENAMES", Token(RENAMES_),
   "RETURN", Token(RETURN_),
   "REVERSE", Token(REVERSE_),
   "SELECT", Token(SELECT_),
   "SEPARATE", Token(SEPARATE_),
   "SUBTYPE", Token(SUBTYPE_),
   "TASK", Token(TASK_),
   "TERMINATE", Token(TERMINATE_),
   "THEN", Token(THEN_),
   "TYPE", Token(TYPE_),
   "USE", Token(USE_),
   "WHEN", Token(WHEN_),
   "WHILE", Token(WHILE_),
   "WITH", Token(WITH_),
   "XOR", Token(XOR_),
};

unsigned num_tokens = sizeof(tokens)/sizeof(TOKEN);

jwabik@shamash.UUCP (09/28/87)

Just a followup.  After sitting in queue one site away for several
days, my informants tell me that my 3-part YACC & LEX posting made it
to the world.  A few things:

	1)  In my posting I said something like:

		"I fixed the LEX so that it is now correctly case
		 sensitive."

	    Of course, I typoed..  Make the following change:
	       
		"I fixed the lEX so that it is now correctly case
		 blind."


	2)  I've still been getting many requests in my mailbox.  
	    If you didn't get the goodies via MAIL or NEWS, please
	    contact me and I'll get them there somehow.

   
   -Jeff


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Jeff A. Wabik (HQM207B)			      { umn-cs \
Control Data Corporation              UUCP:             -> !shamash!jwabik }
Bloomington, MN	55440			      { meccts /

Disclaimer of the day:  Of course my employer has no idea what I'm doing .. 
Moral of the day:       Live long and program.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=