ada.editor/src/org/netbeans/modules/ada/editor/parser/resources/Ada95ASTParser.cup
author Andrea Lucarelli <raster@netbeans.org>
Sun, 22 Aug 2010 23:37:11 +0200
branchrelease68
changeset 16367 d2820c029d3a
parent 15779 367c7fdb5d23
permissions -rw-r--r--
Add JVM compiler support.
     1 /*
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3  *
     4  * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
     5  *
     6  * The contents of this file are subject to the terms of either the GNU
     7  * General Public License Version 2 only ("GPL") or the Common
     8  * Development and Distribution License("CDDL") (collectively, the
     9  * "License"). You may not use this file except in compliance with the
    10  * License. You can obtain a copy of the License at
    11  * http://www.netbeans.org/cddl-gplv2.html
    12  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    13  * specific language governing permissions and limitations under the
    14  * License.  When distributing the software, include this License Header
    15  * Notice in each file and include the License file at
    16  * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    17  * particular file as subject to the "Classpath" exception as provided
    18  * by Sun in the GPL Version 2 section of the License file that
    19  * accompanied this code. If applicable, add the following below the
    20  * License Header, with the fields enclosed by brackets [] replaced by
    21  * your own identifying information:
    22  * "Portions Copyrighted [year] [name of copyright owner]"
    23  *
    24  * If you wish your version of this file to be governed by only the CDDL
    25  * or only the GPL Version 2, indicate your decision by adding
    26  * "[Contributor] elects to include this software in this distribution
    27  * under the [CDDL or GPL Version 2] license." If you do not indicate a
    28  * single choice of license, a recipient has the option to distribute
    29  * your version of this file under either the CDDL, the GPL Version 2 or
    30  * to extend the choice of license to its licensees as provided above.
    31  * However, if you add GPL Version 2 code and therefore, elected the GPL
    32  * Version 2 license, then the option applies only if the new code is
    33  * made subject to such option by the copyright holder.
    34  *
    35  * Contributor(s):
    36  *
    37  * Portions Copyrighted 2008 Sun Microsystems, Inc.
    38  */
    39 package org.netbeans.modules.ada.editor.parser;
    40 
    41 import java.util.*;
    42 import org.netbeans.modules.ada.editor.lexer.Ada95ASTLexer;
    43 import org.netbeans.modules.ada.editor.ast.*;
    44 import org.netbeans.modules.ada.editor.ast.nodes.*;
    45 
    46 parser code {:
    47     protected final static Integer PUBLIC = new Integer(BodyDeclaration.Modifier.PUBLIC);
    48     protected final static Integer PRIVATE = new Integer(BodyDeclaration.Modifier.PRIVATE);
    49     protected final static Integer TAGGED = new Integer(BodyDeclaration.Modifier.TAGGED);
    50     protected final static Integer LIMITED = new Integer(BodyDeclaration.Modifier.LIMITED);
    51     protected final static Integer ABSTRACT = new Integer(BodyDeclaration.Modifier.ABSTRACT);
    52 
    53     private ErrorStrategy defaultStrategy = new DefaultErrorStrategy();;
    54     private ErrorStrategy errorStrategy = defaultStrategy;
    55 
    56     private ParserErrorHandler errorHandler = null;
    57 
    58     public void setErrorHandler (ParserErrorHandler handler) {
    59         this.errorHandler = handler;
    60     }
    61 
    62     public ParserErrorHandler getErrorHandler () {
    63         return this.errorHandler;
    64     }
    65 
    66 
    67     public Dispatch createDispatch(NameBase dispatcher, NameBase property) {
    68         Dispatch dispatch = null;
    69 	if (property instanceof Variable) {
    70 	   dispatch = new FieldAccess(dispatcher.getStartOffset(), property.getEndOffset(), dispatcher, (Variable)property);
    71 	} else if (property instanceof TypeName) {
    72 	   dispatch = new TypeAccess(dispatcher.getStartOffset(), property.getEndOffset(), dispatcher, (TypeName)property);
    73 	} else {
    74 	   throw new IllegalArgumentException();
    75 	}
    76         return dispatch;
    77     }
    78 
    79 
    80     public List setModifier(List items, int modifier) {
    81         List list = new LinkedList();
    82         for (Iterator iter = items.iterator(); iter.hasNext();) {
    83             final Object next = iter.next();
    84             if (next instanceof TypeDeclaration) {
    85                 ((TypeDeclaration)next).setModifier(modifier);
    86                 list.add(next);
    87             } else if (next instanceof MethodDeclaration) {
    88                 ((MethodDeclaration)next).setModifier(modifier);
    89                 list.add(next);
    90             } else if (next instanceof FieldsDeclaration) {
    91                 ((FieldsDeclaration)next).setModifier(modifier);
    92                 list.add(next);
    93             } else {
    94                 list.add(next);
    95             }
    96         }
    97         return list;
    98     }
    99 
   100     interface ErrorStrategy {
   101         public boolean errorRecovery(boolean debug) throws Exception;
   102     }
   103 
   104     class DefaultErrorStrategy implements ErrorStrategy {
   105 
   106         public boolean errorRecovery(boolean debug) throws Exception {
   107             return Ada95ASTParser.super.error_recovery(debug);
   108         }
   109     }
   110 
   111     /**
   112      * Attempt to recover from a syntax error.  This returns false if recovery fails,
   113      * true if it succeeds.
   114      * @param debug should we produce debugging messages as we parse.
   115      */
   116     @Override
   117     protected boolean error_recovery(boolean debug) throws java.lang.Exception {
   118         return errorStrategy.errorRecovery(debug);
   119     }
   120 
   121     /**
   122      * Report a non fatal error (or warning).  This method takes a message
   123      * string and an additional object (to be used by specializations implemented in subclasses).
   124      * The super class prints the message to System.err.
   125      * @param message an error message.
   126      * @param info    an extra object reserved for use by specialized subclasses.
   127      */
   128     @Override
   129     public void report_error(String message, Object info) {
   130         System.out.print("report_eror"  + message);
   131     }	
   132 
   133     /**
   134      * This method is called when a syntax error has been detected and recovery is about to be invoked.
   135      * The super class just emit a "Syntax error" error message.
   136      * @param cur_token the current lookahead Symbol.
   137      */
   138     @Override
   139     public void syntax_error(java_cup.runtime.Symbol cur_token) {
   140         java_cup.runtime.Symbol symbol = (java_cup.runtime.Symbol)stack.peek();
   141         int state = symbol.parse_state;
   142         short[] rowOfProbe = action_tab[state];
   143         if (errorHandler != null) {
   144             errorHandler.handleError(ParserErrorHandler.Type.SYNTAX_ERROR, rowOfProbe, cur_token, symbol);
   145         }
   146      }
   147 
   148     /**
   149      * This method is called when a syntax error has been detected during action.
   150      * @param message an error message.
   151      */
   152     public void message_error(String message) {
   153         java_cup.runtime.Symbol symbol = (java_cup.runtime.Symbol)stack.peek();
   154         if (errorHandler != null) {
   155             errorHandler.handleError(ParserErrorHandler.Type.SYNTAX_ERROR, symbol, message);
   156         }
   157      }
   158 
   159      /**
   160      * Report a fatal error.  This method takes a message string and an additional object
   161      * (to be used by specializations implemented in subclasses).
   162      * The super class reports the error then throws an exception.
   163      * @param message an error message.
   164      * @param info    an extra object reserved for use by specialized subclasses.
   165      */
   166     @Override
   167     public void report_fatal_error(String message, Object info) throws Exception {
   168         if (errorHandler != null) {
   169             errorHandler.handleError(ParserErrorHandler.Type.FATAL_PARSER_ERROR, null, cur_token, null);
   170         }
   171     }
   172 
   173     @Override
   174     protected int error_sync_size() {
   175         return 1;
   176     }
   177 
   178 :}
   179 
   180 
   181 /*********************************************************
   182  *                                                       *
   183  * Ada 95 (LALR) AST Parser, based on:                   *
   184  *                                                       *
   185  * 1. Ada Reference Manual                               *
   186  *    ISO/IEC 8652:1995(E)                               *
   187  *    with Technical Corrigendum 1                       *
   188  *    Language and Standard Libraries                    *
   189  *    Copyright © 1992,1993,1994,1995 Intermetrics, Inc. *
   190  *    Copyright © 2000 The MITRE Corporation, Inc.       *
   191  * 2. http://www.adaic.com/standards/95lrm/grammar9x.y   *
   192  *                                                       *
   193  * Author: Andrea Lucarelli                              *
   194  * Parser Generator: JavCup                              *
   195  *                                                       *
   196  *********************************************************/
   197 
   198 /*************************
   199  * JavaCup Terminals     *
   200  *************************/
   201 
   202 //
   203 // Ada 95 keywords
   204 //
   205 terminal ABORT;
   206 terminal ABS;
   207 terminal ABSTRACT;
   208 terminal ACCESS;
   209 terminal ACCEPT;
   210 terminal ALIASED;
   211 terminal ALL;
   212 terminal AND;
   213 terminal ARRAY;
   214 terminal AT;
   215 terminal BEGIN;
   216 terminal BODY;
   217 terminal CONSTANT;
   218 terminal CASE;
   219 terminal DECLARE;
   220 terminal DELAY;
   221 terminal DELTA;
   222 terminal DIGITS;
   223 terminal DO;
   224 terminal ELSE;
   225 terminal ELSIF;
   226 terminal END;
   227 terminal ENTRY;
   228 terminal EXCEPTION;
   229 terminal EXIT;
   230 terminal FOR;
   231 terminal FUNCTION;
   232 terminal GENERIC;
   233 terminal GOTO;
   234 terminal IF;
   235 terminal IN;
   236 terminal IS;
   237 terminal LIMITED;
   238 terminal LOOP;
   239 terminal MOD;
   240 terminal NEW;
   241 terminal NOT;
   242 terminal NULL;
   243 terminal OF;
   244 terminal OR;
   245 terminal OTHERS;
   246 terminal OUT;
   247 terminal PACKAGE;
   248 terminal PRAGMA;
   249 terminal PRIVATE;
   250 terminal PROCEDURE;
   251 terminal PROTECTED;
   252 terminal RETURN;
   253 terminal REVERSE;
   254 terminal RAISE;
   255 terminal RANGE;
   256 terminal RECORD;
   257 terminal REM;
   258 terminal RENAMES;
   259 terminal REQUEUE;
   260 terminal SELECT;
   261 terminal SEPARATE;
   262 terminal SUBTYPE;
   263 terminal TAGGED;
   264 terminal TASK;
   265 terminal TERMINATE;
   266 terminal THEN;
   267 terminal TYPE;
   268 terminal UNTIL;
   269 terminal USE;
   270 terminal WHEN;
   271 terminal WHILE;
   272 terminal WITH;
   273 terminal XOR;
   274 
   275 // 2.2 Lexical Elements, Separators, and Delimiters
   276 
   277 //
   278 // delimiters
   279 //
   280 terminal AMP;
   281 terminal TICK;
   282 terminal LPAREN;
   283 terminal RPAREN;
   284 terminal STAR;
   285 terminal PLUS;
   286 terminal COMMA;
   287 terminal MINUS;
   288 terminal DOT;
   289 terminal SLASH;
   290 terminal COLON;
   291 terminal SEMICOLON;
   292 terminal GT;
   293 terminal EQ;
   294 terminal LT;
   295 terminal BAR;
   296 
   297 //
   298 // compound delimiters
   299 //
   300 terminal ARROW;
   301 terminal DOT_DOT;
   302 terminal EXPON;
   303 terminal ASSIGNMENT;
   304 terminal INEQ;
   305 terminal GTEQ;
   306 terminal LTEQ;
   307 terminal LTLT;
   308 terminal GTGT;
   309 terminal BOX;
   310 
   311 //
   312 // others tokens
   313 //
   314 // ??? terminal String OPERATOR_SYMBOL;
   315 terminal String CHAR_LITERAL;    // 2.1 Character Set
   316 terminal String IDENTIFIER;      // 2.3 Identifiers
   317 terminal String DECIMAL_LITERAL; // 2.4.1 Decimal Literals
   318 terminal String BASED_LITERAL;   // 2.4.2 Based Literals
   319 terminal String STRING_LITERAL;  // 2.6 String Literals
   320 
   321 
   322 /*************************
   323  * JavaCup Non terminals *
   324  *************************/
   325 
   326 // 3.1 Declarations
   327 non terminal Statement               declaration;
   328 non terminal List                    fields_declaration;
   329 non terminal Statement               type_declaration;
   330 non terminal Statement               subprog_declaration;
   331 non terminal Identifier              defining_identifier;
   332 
   333 // 3.11 Declarative Parts
   334 non terminal List                    declarative_items_opt;
   335 non terminal List                    declarative_item_list;
   336 non terminal Statement               declarative_item;
   337 non terminal List                    declarative_part;
   338 non terminal List                    declarative_item_or_body_s1;
   339 non terminal List                    private_part;
   340 non terminal Statement               proper_body;
   341 non terminal Statement               task_body;
   342 
   343 // 3.2.1 Type Declarations
   344 non terminal Expression              type_definition;
   345 
   346 // 3.2.2 Subtype Declarations
   347 non terminal Statement               subtype_declaration;
   348 non terminal TypeName                subtype_indication;
   349 
   350 // 3.3.1 Object Declarations
   351 non terminal List                    object_declaration;
   352 non terminal List                    defining_identifier_list;
   353 non terminal Variable.Kind           object_qualifier_opt;
   354 
   355 // 3.3.2 Number Declarations
   356 non terminal List                    number_declaration;
   357 
   358 // 4.1 Names
   359 non terminal Identifier              name;
   360 non terminal Identifier              simple_name;
   361 
   362 // 4.1.3 Selected Components
   363 non terminal Identifier              selected_component;
   364 
   365 // 4.4 Expressions
   366 non terminal Expression              expression;
   367 non terminal Expression              relation;
   368 non terminal Expression              simple_expression;
   369 non terminal Expression              term;
   370 non terminal Expression              factor;
   371 non terminal Expression              primary;
   372 
   373 // 4.5 Operators and Expression Evaluation
   374 non terminal InfixExpression.OperatorType logical_operator;
   375 non terminal InfixExpression.OperatorType relational_operator;
   376 non terminal InfixExpression.OperatorType binary_adding_operator;
   377 non terminal UnaryOperation.Operator      unary_adding_operator;
   378 non terminal InfixExpression.OperatorType multiplying_operator;
   379 
   380 // 4.7 Qualified Expressions
   381 non terminal Expression              qualified_expression;
   382 
   383 // 5.1 Simple and Compound Statements - Sequences of Statements
   384 non terminal List                    sequence_of_statements;
   385 non terminal Statement               simple_statement;
   386 non terminal Statement               compound_statement;
   387 non terminal Statement               null_statement;
   388 
   389 // 5.2 Assignment Statements
   390 non terminal Statement               assignment_statement;
   391 
   392 // 5.3 If Statements
   393 non terminal IfStatement             if_statement;
   394 non terminal List[]                  cond_clause_s;
   395 non terminal Expression              condition;
   396 non terminal Block                   else_opt;
   397 
   398 // 5.4 Case Statements
   399 non terminal CaseStatement           case_statement;
   400 non terminal List                    alternative_s;
   401 non terminal CaseWhen                alternative;
   402 
   403 // 5.5 Loop Statements
   404 non terminal LoopStatement           loop_statement;
   405 non terminal Block                   basic_loop;
   406 non terminal Expression              iteration;
   407 
   408 // 5.6 Block Statements
   409 non terminal BlockStatement          block_statement;
   410 non terminal Block                   block_declarative;
   411 non terminal Block                   block_body;
   412 
   413 // 5.7 Exit Statements
   414 non terminal Statement               exit_statement;
   415 non terminal Expression              name_opt;
   416 
   417 // 5.8 Goto Statements
   418 non terminal Statement               goto_statement;
   419 
   420 // 6.1 Subprogram Declarations
   421 non terminal SubprogramSpecification subprogram_specification;
   422 non terminal SubprogramSpecification generic_subp_inst;
   423 non terminal MethodDeclaration       subprogram_body;
   424 non terminal List                    param_s;
   425 non terminal List                    formal_part_opt;
   426 non terminal List                    formal_part;
   427 non terminal List                    param;
   428 non terminal FormalParameter.Mode    mode;
   429 non terminal Identifier              designator;
   430 non terminal Identifier              operator_symbol;
   431 
   432 // 6.5 Return Statements
   433 non terminal Statement               return_statement;
   434 
   435 // 7.1 Package Specifications and Declarations
   436 non terminal Statement               package_declaration;
   437 non terminal Statement               package_specification;
   438 			        
   439 // 7.2 Package Bodies	        
   440 non terminal Statement               package_body;
   441 non terminal Statement               body;
   442 
   443 // 7.3 Private Types and Private Extensions
   444 non terminal PrivateType             private_type_declaration;
   445 non terminal Integer                 tagged_opt;
   446 non terminal Integer                 limited_opt;
   447 
   448 // 8.4 Use Clauses
   449 non terminal Statement               use_clause;
   450 non terminal List                    package_name_list;
   451 non terminal List                    subtype_mark_list;
   452 
   453 // 8.5 Renaming Declarations
   454 non terminal Statement               renaming_declaration;
   455 non terminal Statement               rename_unit;
   456 
   457 // 9.4 Protected Units and Protected Objects
   458 non terminal Statement               protected_body;
   459 
   460 // 9.6 Delay Statements, Duration, and Time
   461 non terminal Statement               delay_statement;
   462 
   463 // 9.8 Abort of a Task - Abort of a Sequence of Statements
   464 non terminal Statement               abort_statement;
   465 non terminal List                    task_name_list;
   466 
   467 // 10.1.1 Compilation Units - Library Units
   468 non terminal Program                 compilation;
   469 non terminal List                    compilation_units;
   470 non terminal Statement               compilation_unit;
   471 non terminal Statement               unit;
   472 
   473 // 10.1.2 Context Clauses - With Clauses
   474 non terminal Statement               context_clause;
   475 non terminal Statement               with_clause;
   476 non terminal List                    library_unit_name_list;
   477 
   478 // 10.1.3 Subunits of Compilation Units
   479 non terminal Statement               body_stub;
   480 
   481 // 11.3 Raise Statements
   482 non terminal Statement               raise_statement;
   483 
   484 // 12.1 Generic Declarations
   485 non terminal Statement               generic_declaration;
   486 
   487 // 13.8 Machine Code Insertions
   488 non terminal Statement               code_statement;
   489 
   490 
   491 // TBD sections
   492 non terminal Identifier                   compound_name;
   493 non terminal Identifier                   compound_name_opt;
   494 non terminal TypeName                     object_subtype_def;
   495 non terminal Expression                   init_opt;
   496 non terminal Statement                    type_decl;
   497 non terminal Expression                   type_completion;
   498 non terminal NameBase                     subtype_mark;
   499 non terminal List                         handled_stmt_s;
   500 non terminal Statement                    statement;
   501 non terminal Statement                    subunit;
   502 non terminal Identifier                   id_opt;
   503 non terminal Statement                    unlabeled;
   504 non terminal Expression                   literal;
   505 non terminal Expression                   parenthesized_primary;
   506 non terminal Expression                   when_opt;
   507 non terminal Statement                    procedure_call_statement;
   508 non terminal String                       used_char;
   509 non terminal Expression                   choice_s;
   510 non terminal Identifier                   label_opt;
   511 non terminal Identifier                   attribute;
   512 non terminal Identifier                   indexed_component; // TODO: must be change it
   513 non terminal Expression                   value_s;
   514 non terminal Expression                   discrete_range;
   515 non terminal Expression                   range;
   516 non terminal InfixExpression.OperatorType short_circuit;
   517 non terminal InfixExpression.OperatorType membership;
   518 non terminal String                       attribute_id;
   519 
   520 // TBD RM sections and types
   521 non terminal     pragma;
   522 non terminal     pragma_arg_s;
   523 non terminal     pragma_arg;
   524 non terminal     pragma_s;
   525 non terminal     task_decl;
   526 non terminal     prot_decl;
   527 non terminal     exception_decl;
   528 non terminal     discrim_part_opt;
   529 non terminal     discrim_part;
   530 non terminal     enumeration_type;
   531 non terminal     integer_type;
   532 non terminal     real_type;
   533 non terminal     array_type;
   534 non terminal     record_type;
   535 non terminal     access_type;
   536 non terminal     derived_type;
   537 non terminal     constraint;
   538 non terminal     range_constraint;
   539 non terminal     decimal_digits_constraint;
   540 non terminal     range_constr_opt;
   541 non terminal     record_def;
   542 non terminal     enum_id_s;
   543 non terminal     enum_id;
   544 non terminal     range_spec;
   545 non terminal     range_spec_opt;
   546 non terminal     float_type;
   547 non terminal     fixed_type;
   548 non terminal     unconstr_array_type;
   549 non terminal     constr_array_type;
   550 non terminal     index_s;
   551 non terminal     index;
   552 non terminal     component_subtype_def;
   553 non terminal     aliased_opt;
   554 non terminal     iter_index_constraint;
   555 non terminal     iter_discrete_range_s;
   556 non terminal     comp_list;
   557 non terminal     comp_decl_s;
   558 non terminal     comp_decl;
   559 non terminal     variant_part_opt;
   560 non terminal     variant_part;
   561 non terminal     discrim_spec_s;
   562 non terminal     discrim_spec;
   563 non terminal     access_opt;
   564 non terminal     variant_s;
   565 non terminal     variant;
   566 non terminal     choice;
   567 non terminal     discrete_with_range;
   568 non terminal     prot_opt;
   569 non terminal     rep_spec;
   570 non terminal     declarative_item_or_body;
   571 non terminal     value;
   572 non terminal     comp_assoc;
   573 non terminal     aggregate;
   574 non terminal     value_s_2;
   575 non terminal     allocator;
   576 non terminal     label;
   577 non terminal     requeue_stmt;
   578 non terminal     accept_stmt;
   579 non terminal     select_stmt;
   580 non terminal     iter_part;
   581 non terminal     reverse_opt;
   582 non terminal     except_handler_part_opt;
   583 non terminal     except_handler_part;
   584 non terminal     generic_package_instantiation;
   585 non terminal     body_opt;
   586 non terminal     generic_formal_part;
   587 non terminal     task_spec;
   588 non terminal     task_def;
   589 non terminal     entry_decl_s;
   590 non terminal     rep_spec_s;
   591 non terminal     task_private_opt;
   592 non terminal     prot_spec;
   593 non terminal     prot_def;
   594 non terminal     prot_op_decl_s;
   595 non terminal     prot_private_opt;
   596 non terminal     prot_elem_decl_s;
   597 non terminal     prot_op_decl;
   598 non terminal     entry_decl;
   599 non terminal     prot_elem_decl;
   600 non terminal     prot_op_body_s;
   601 non terminal     prot_op_body;
   602 non terminal     entry_body;
   603 non terminal     entry_body_part;
   604 non terminal     accept_hdr;
   605 non terminal     entry_call;
   606 non terminal     entry_name;
   607 non terminal     select_wait;
   608 non terminal     async_select;
   609 non terminal     timed_entry_call;
   610 non terminal     cond_entry_call;
   611 non terminal     guarded_select_alt;
   612 non terminal     or_select;
   613 non terminal     select_alt;
   614 non terminal     stmts_opt;
   615 non terminal     delay_or_entry_alt;
   616 non terminal     private_opt;
   617 non terminal     exception_handler;
   618 non terminal     except_choice_s;
   619 non terminal     except_choice;
   620 non terminal     generic_formal;
   621 non terminal     generic_discrim_part_opt;
   622 non terminal     generic_type_def;
   623 non terminal     subp_default;
   624 non terminal     generic_derived_type;
   625 non terminal     generic_inst;
   626 non terminal     attrib_def;
   627 non terminal     record_type_spec;
   628 non terminal     address_spec;
   629 non terminal     align_opt;
   630 non terminal     comp_loc_s;
   631 
   632 /*************************
   633  * JavaCup precedence    *
   634  *************************/
   635 
   636 // TODO: must be complete
   637 precedence left OR;
   638 precedence left XOR;
   639 precedence left AND;
   640 
   641 precedence left SEMICOLON;
   642 
   643 precedence left ELSIF;
   644 precedence left ELSE;
   645 precedence left END;
   646 
   647 precedence right NOT;
   648 
   649 precedence nonassoc ASSIGNMENT;
   650 
   651 
   652 ///////////////////////////////////////////////////////////////////////////////
   653 // start with root symbol 
   654 //
   655 start with compilation;
   656 
   657 /*****************
   658  *               *
   659  * Ada 95 syntax *
   660  *               *
   661  *****************/
   662 
   663 ///////////////////////////////////////////////////////////////////////////////
   664 // 2.8 Pragmas
   665 //
   666 pragma  ::= PRAGMA IDENTIFIER SEMICOLON
   667 	| PRAGMA simple_name LPAREN pragma_arg_s RPAREN SEMICOLON
   668 	;
   669 
   670 pragma_arg_s ::= pragma_arg
   671 	| pragma_arg_s COMMA pragma_arg
   672 	;
   673 
   674 pragma_arg ::= expression
   675 	| simple_name ARROW expression
   676 	;
   677 
   678 pragma_s ::=
   679 	| pragma_s pragma
   680 	;
   681 
   682 ///////////////////////////////////////////////////////////////////////////////
   683 // 3.1 Declarations
   684 //
   685 fields_declaration ::=
   686 object_declaration:statement
   687 {:
   688 	RESULT = statement;
   689 :}
   690 | number_declaration:statement
   691 {:
   692 	RESULT = statement;
   693 :}
   694 ;
   695 
   696 type_declaration ::=
   697 type_decl:statement
   698 {:
   699 	RESULT = statement;
   700 :}
   701 | subtype_declaration:statement
   702 {:
   703 	RESULT = statement;
   704 :}
   705 ;
   706 
   707 declaration ::=
   708 task_decl
   709 | prot_decl
   710 | exception_decl
   711 | renaming_declaration:statement
   712 {:
   713 	RESULT = statement;
   714 :}
   715 | generic_declaration:statement
   716 {:
   717 	RESULT = statement;
   718 :}
   719 | body_stub:statement
   720 {:
   721 	RESULT = statement;
   722 :}
   723 | error:theError SEMICOLON // error statement
   724 {:
   725     ASTError error = new ASTError(theErrorleft, theErrorright);
   726     RESULT = error;
   727 :}
   728 ;
   729 
   730 defining_identifier ::=
   731 IDENTIFIER:id
   732 {:
   733     Identifier identifier = new Identifier(idleft, idright, id);
   734     RESULT = identifier;
   735 :}
   736 ;
   737 
   738 ///////////////////////////////////////////////////////////////////////////////
   739 // 3.3.1 Object Declarations
   740 //
   741 object_declaration ::= 
   742 defining_identifier_list:identifierList COLON object_qualifier_opt:varKind object_subtype_def:subtype init_opt:init SEMICOLON
   743 {:
   744     List list = new LinkedList();
   745     for (Object identifier : identifierList) {
   746         Variable variable = new Variable (((Identifier)identifier).getStartOffset(), ((Identifier)identifier).getEndOffset(), (Identifier)identifier, varKind, subtype);
   747         list.add(new ASTNode[] {variable, init});
   748     }
   749     RESULT = list;
   750 :}
   751 ;
   752 
   753 defining_identifier_list ::= 
   754 defining_identifier:identifier
   755 {:
   756     List identifierList = new LinkedList();
   757     identifierList.add(identifier);
   758     RESULT = identifierList;
   759 :}
   760 | defining_identifier_list:identifierList COMMA defining_identifier:identifier
   761 {:
   762     identifierList.add(identifier);
   763     RESULT = identifierList;
   764 :}
   765 ;
   766 
   767 object_qualifier_opt ::=
   768 {:
   769     RESULT = Variable.Kind.DEFAULT;
   770 :}
   771 | ALIASED
   772 {:
   773     RESULT = Variable.Kind.ALIASED;
   774 :}
   775 | CONSTANT
   776 {:
   777     RESULT = Variable.Kind.CONSTANT;
   778 :}
   779 | ALIASED CONSTANT
   780 {:
   781     RESULT = Variable.Kind.ALIASED_CONSTANT;
   782 :}
   783 ;
   784 
   785 object_subtype_def ::= 
   786 subtype_indication:subtype
   787 {:
   788     RESULT = subtype;
   789 :}
   790 | array_type:array
   791 ;
   792 
   793 init_opt ::=
   794 {:
   795     RESULT = null;
   796 :}
   797 | ASSIGNMENT expression:expr
   798 {:
   799     RESULT = expr;
   800 :}
   801 ;
   802 
   803 ///////////////////////////////////////////////////////////////////////////////
   804 // 3.3.2 Number Declarations
   805 //
   806 number_declaration ::= 
   807 defining_identifier_list:identifierList COLON CONSTANT ASSIGNMENT expression:init SEMICOLON
   808 {:
   809     List list = new LinkedList();
   810     for (Object identifier : identifierList) {
   811         Variable variable = new Variable (((Identifier)identifier).getStartOffset(), ((Identifier)identifier).getEndOffset(), (Identifier)identifier, Variable.Kind.CONSTANT);
   812         list.add(new ASTNode[] {variable, init});
   813     }
   814     RESULT = list;
   815 :}
   816 ;
   817 
   818 type_decl ::= 
   819 TYPE:token defining_identifier:identifier discrim_part_opt type_completion:typeCompletion SEMICOLON:end
   820 {:
   821     TypeDeclaration type = new TypeDeclaration (tokenleft, endright, identifier, typeCompletion);
   822     RESULT = type;
   823 :}
   824 ;
   825 
   826 discrim_part_opt ::=
   827 	| discrim_part
   828 	| LPAREN BOX RPAREN
   829 	;
   830 
   831 type_completion ::=
   832 // empty
   833 {:
   834     RESULT = null;
   835 :}
   836 | IS type_definition:typeDef
   837 {:
   838     RESULT = typeDef;
   839 :}
   840 ;
   841 
   842 type_definition ::=
   843 enumeration_type 
   844 | integer_type
   845 | real_type
   846 | array_type
   847 | record_type
   848 | access_type
   849 | derived_type
   850 | private_type_declaration:privateType
   851 {:
   852     RESULT = privateType;
   853 :}
   854 ;
   855 
   856 ///////////////////////////////////////////////////////////////////////////////
   857 // 3.2.2 Subtype Declarations
   858 //
   859 subtype_declaration ::=
   860 SUBTYPE:token defining_identifier:identifier IS subtype_indication:subtypeIndication SEMICOLON:end
   861 {:
   862     SubtypeDeclaration type = new SubtypeDeclaration (tokenleft, endright, identifier, subtypeIndication);
   863     RESULT = type;
   864 :}
   865 ;
   866 
   867 subtype_indication ::= 
   868 name:name constraint
   869 {:
   870     TypeName type = new TypeName (nameleft, nameright, name);
   871     RESULT = type;
   872 :}
   873 | name:name
   874 {:    
   875     TypeName type = new TypeName (nameleft, nameright, name);
   876     RESULT = type;
   877 :}
   878 ;
   879 
   880 constraint ::= range_constraint
   881 	| decimal_digits_constraint
   882 	;
   883 
   884 decimal_digits_constraint ::= DIGITS expression range_constr_opt
   885 	;
   886 
   887 derived_type ::= NEW subtype_indication
   888 	| NEW subtype_indication WITH PRIVATE
   889 	| NEW subtype_indication WITH record_def
   890 	| ABSTRACT NEW subtype_indication WITH PRIVATE
   891 	| ABSTRACT NEW subtype_indication WITH record_def
   892 	;
   893 
   894 range_constraint ::= RANGE range
   895 	;
   896 
   897 range ::=
   898 simple_expression:simple_expression1 DOT_DOT simple_expression:simple_expression2
   899 {:
   900     Range range = new Range (simple_expression1left, simple_expression2right, simple_expression1, simple_expression2);
   901     RESULT = range;
   902 :}
   903 | name:name TICK RANGE:end
   904 {:
   905     Range range = new Range (nameleft, endright, name, name);
   906     RESULT = range;
   907 :}
   908 | name:name TICK RANGE LPAREN expression:expression RPAREN:end
   909 {:
   910     Range range = new Range (nameleft, endright, name, expression);
   911     RESULT = range;
   912 :}
   913 ;
   914 
   915 enumeration_type ::= LPAREN enum_id_s RPAREN
   916         ;
   917 
   918 enum_id_s ::= enum_id
   919 	| enum_id_s COMMA enum_id
   920 	;
   921 
   922 enum_id ::= IDENTIFIER
   923 	| CHAR_LITERAL
   924 	;
   925 
   926 integer_type ::= range_spec
   927 	| MOD expression
   928 	;
   929 	
   930 
   931 range_spec ::= range_constraint
   932 	;
   933 
   934 range_spec_opt ::=
   935 	| range_spec
   936 	;
   937 
   938 real_type ::= float_type
   939 	| fixed_type
   940 	;
   941 
   942 float_type ::= DIGITS expression range_spec_opt
   943 	;
   944 
   945 fixed_type ::= DELTA expression range_spec
   946 	| DELTA expression DIGITS expression range_spec_opt
   947 	;
   948 
   949 array_type ::= unconstr_array_type
   950 	| constr_array_type
   951 	;
   952 
   953 unconstr_array_type ::= ARRAY LPAREN index_s RPAREN OF component_subtype_def
   954 	;
   955 
   956 constr_array_type ::= ARRAY iter_index_constraint OF component_subtype_def
   957 	;
   958 
   959 component_subtype_def ::= aliased_opt subtype_indication
   960 	;
   961 
   962 aliased_opt ::= 
   963 	| ALIASED
   964 	;
   965 
   966 index_s ::= index
   967 	| index_s COMMA index
   968 	;
   969 
   970 index ::= name RANGE BOX
   971 	;
   972 
   973 iter_index_constraint ::= LPAREN iter_discrete_range_s RPAREN
   974 	;
   975 
   976 iter_discrete_range_s ::= discrete_range
   977 	| iter_discrete_range_s COMMA discrete_range
   978 	;
   979 
   980 discrete_range ::=
   981 name range_constr_opt
   982 | range:range
   983 {:
   984     RESULT = range;
   985 :}
   986 ;
   987 
   988 range_constr_opt ::=
   989 	| range_constraint
   990 	;
   991 
   992 record_type ::= tagged_opt limited_opt record_def
   993 	;
   994 
   995 record_def ::= RECORD pragma_s comp_list END RECORD
   996 	| NULL RECORD
   997 	;
   998 
   999 tagged_opt ::=
  1000 {:
  1001     RESULT = 0;
  1002 :}
  1003 | TAGGED
  1004 {:
  1005     RESULT = Ada95ASTParser.TAGGED;
  1006 :}
  1007 | ABSTRACT TAGGED
  1008 {:
  1009     RESULT = Ada95ASTParser.TAGGED + Ada95ASTParser.ABSTRACT;
  1010 :}
  1011 ;
  1012 
  1013 comp_list ::= comp_decl_s variant_part_opt
  1014 	| variant_part pragma_s
  1015 	| NULL SEMICOLON pragma_s
  1016 	;
  1017 
  1018 comp_decl_s ::= comp_decl
  1019 	| comp_decl_s pragma_s comp_decl
  1020 	;
  1021 
  1022 variant_part_opt ::= pragma_s
  1023 	| pragma_s variant_part pragma_s
  1024 	;
  1025 
  1026 comp_decl ::= 
  1027 defining_identifier_list COLON component_subtype_def init_opt SEMICOLON
  1028 | error:theError SEMICOLON
  1029 {:
  1030     ASTError error = new ASTError(theErrorleft, theErrorright);
  1031     RESULT = error;
  1032 :}
  1033 ;
  1034 
  1035 discrim_part ::= LPAREN discrim_spec_s RPAREN
  1036 	;
  1037 
  1038 discrim_spec_s ::= discrim_spec
  1039 	| discrim_spec_s SEMICOLON discrim_spec
  1040 	;
  1041 
  1042 discrim_spec ::= 
  1043 defining_identifier_list COLON access_opt subtype_mark init_opt
  1044 | error:theError  // error statement
  1045 {:
  1046     ASTError error = new ASTError(theErrorleft, theErrorright);
  1047     RESULT = error;
  1048 :}
  1049 ;
  1050 
  1051 access_opt ::=
  1052 	| ACCESS
  1053 	;
  1054 
  1055 variant_part ::= CASE simple_name IS pragma_s variant_s END CASE SEMICOLON
  1056 	;
  1057 
  1058 variant_s ::= variant
  1059 	| variant_s variant
  1060 	;
  1061 
  1062 variant ::= WHEN choice_s ARROW pragma_s comp_list
  1063 	;
  1064 
  1065 choice_s ::= choice
  1066 	| choice_s BAR choice
  1067 	;
  1068 
  1069 choice ::= expression
  1070 	| discrete_with_range
  1071 	| OTHERS
  1072 	;
  1073 
  1074 discrete_with_range ::= name range_constraint
  1075 	| range
  1076 	;
  1077 
  1078 access_type ::= ACCESS subtype_indication
  1079 	| ACCESS CONSTANT subtype_indication
  1080 	| ACCESS ALL subtype_indication
  1081 	| ACCESS prot_opt PROCEDURE formal_part_opt
  1082 	| ACCESS prot_opt FUNCTION formal_part_opt RETURN subtype_mark
  1083 	;
  1084 
  1085 prot_opt ::=
  1086 	| PROTECTED
  1087 	;
  1088 
  1089 ///////////////////////////////////////////////////////////////////////////////
  1090 // 3.11 Declarative Parts
  1091 //
  1092 declarative_part ::=
  1093 {:
  1094     RESULT = new LinkedList();
  1095 :}
  1096 | declarative_item_or_body_s1:statement
  1097 {:
  1098     RESULT = statement;
  1099 :}
  1100 ;
  1101 
  1102 declarative_items_opt ::=
  1103 // empty
  1104 {:
  1105     RESULT = new LinkedList();
  1106 :}
  1107 | declarative_item_list:declaritiveItemList
  1108 {:
  1109     RESULT = declaritiveItemList;
  1110 :}
  1111 ;
  1112 
  1113 declarative_item_list ::=
  1114 declarative_item:declaritiveItem
  1115 {:
  1116     List declaritiveItemList = new LinkedList();
  1117     declaritiveItemList.add(declaritiveItem);
  1118     RESULT = declaritiveItemList;
  1119 :}
  1120 | declarative_item_list:declaritiveItemList declarative_item:declaritiveItem
  1121 {:
  1122     declaritiveItemList.add(declaritiveItem);
  1123     RESULT = declaritiveItemList;
  1124 :}
  1125 ;
  1126 
  1127 declarative_item ::=
  1128 fields_declaration:list
  1129 {:
  1130     FieldsDeclaration fieldsDeclaration = new FieldsDeclaration(listleft, listright, list);
  1131     RESULT = fieldsDeclaration;
  1132 :}
  1133 | type_declaration:statement
  1134 {:
  1135     RESULT = statement;
  1136 :}
  1137 | subprog_declaration:statement
  1138 {:
  1139     RESULT = statement;
  1140 :}
  1141 | package_declaration:statement
  1142 {:
  1143     RESULT = statement;
  1144 :}
  1145 | declaration:statement // todo: to be split
  1146 {:
  1147     RESULT = statement;
  1148 :}
  1149 | use_clause:statement
  1150 {:
  1151     RESULT = statement;
  1152 :}
  1153 | rep_spec
  1154 | pragma
  1155 ;
  1156 
  1157 declarative_item_or_body_s1 ::=
  1158 declarative_item_or_body:declaritiveItem
  1159 {:
  1160     List declaritiveItemList = new LinkedList();
  1161     declaritiveItemList.add(declaritiveItem);
  1162     RESULT = declaritiveItemList;
  1163 :}
  1164 | declarative_item_or_body_s1:declaritiveItemList declarative_item_or_body:declaritiveItem
  1165 {:
  1166     declaritiveItemList.add(declaritiveItem);
  1167     RESULT = declaritiveItemList;
  1168 :}
  1169 ;
  1170 
  1171 declarative_item_or_body ::=
  1172 body:statement
  1173 {:
  1174     RESULT = statement;
  1175 :}
  1176 | declarative_item:statement
  1177 {:
  1178     RESULT = statement;
  1179 :}
  1180 ;
  1181 
  1182 body ::=
  1183 subprogram_body:statement
  1184 {:
  1185     RESULT = statement;
  1186 :}
  1187 | package_body:statement
  1188 {:
  1189     RESULT = statement;
  1190 :}
  1191 | task_body:statement
  1192 {:
  1193     RESULT = statement;
  1194 :}
  1195 | protected_body:statement
  1196 {:
  1197     RESULT = statement;
  1198 :}
  1199 ;
  1200 
  1201 proper_body ::=
  1202 subprogram_body:statement
  1203 {:
  1204     RESULT = statement;
  1205 :}
  1206 | package_body:statement
  1207 {:
  1208     RESULT = statement;
  1209 :}
  1210 | task_body:statement
  1211 {:
  1212     RESULT = statement;
  1213 :}
  1214 | protected_body:statement
  1215 {:
  1216     RESULT = statement;
  1217 :}
  1218 ;
  1219 
  1220 name ::=
  1221 simple_name:simple_name // direct_name
  1222 {:
  1223     RESULT = simple_name;
  1224 :}
  1225 | operator_symbol:operator_symbol // direct_name
  1226 {:
  1227     RESULT = operator_symbol;
  1228 :}
  1229 | indexed_component:indexed_component
  1230 {:
  1231     RESULT = indexed_component;
  1232 :}
  1233 | selected_component:selected_component
  1234 {:
  1235     RESULT = selected_component;
  1236 :}
  1237 | attribute:attribute
  1238 {:
  1239     RESULT = attribute;
  1240 :}
  1241 ;
  1242 
  1243 subtype_mark ::=
  1244 simple_name:name
  1245 {:
  1246     TypeName typeName = new TypeName (nameleft, nameright, name);
  1247     RESULT = typeName;
  1248 :}
  1249 | subtype_mark:name TICK attribute_id:id
  1250 {:
  1251     ((TypeName)name).setAttributeId(id);
  1252     RESULT = name;
  1253 :}
  1254 | subtype_mark:subtype_mark DOT simple_name:simple_name
  1255 {:
  1256     Dispatch dispatch;
  1257     TypeName typeName = new TypeName (simple_nameleft, simple_nameright, simple_name);
  1258     if (subtype_mark instanceof TypeName) {
  1259         PackageName packageName = new PackageName (subtype_markleft, subtype_markright, ((TypeName)subtype_mark).getTypeName());
  1260         dispatch = parser.createDispatch(packageName, typeName);
  1261     } else {
  1262         dispatch = parser.createDispatch(subtype_mark, typeName);
  1263     }
  1264 
  1265     RESULT = dispatch;
  1266 :}
  1267 ;
  1268 
  1269 simple_name ::=
  1270 IDENTIFIER:id
  1271 {:
  1272     Identifier identifier = new Identifier (idleft, idright, id);
  1273     RESULT = identifier;
  1274 :}
  1275 ;
  1276 
  1277 // TODO: must be create a list of identifiers
  1278 compound_name ::=
  1279 simple_name:simple_name
  1280 {:
  1281     RESULT = simple_name;
  1282 :}
  1283 | compound_name:compound_name DOT simple_name:simple_name
  1284 {:
  1285     RESULT = simple_name;
  1286 :}
  1287 ;
  1288 
  1289 library_unit_name_list ::=
  1290 compound_name:compound_name
  1291 {:
  1292     List nameList = new LinkedList();
  1293     PackageName packageName = new PackageName(compound_nameleft, compound_nameright, compound_name);
  1294     nameList.add(packageName);
  1295     RESULT = nameList;
  1296 :}
  1297 | library_unit_name_list:nameList COMMA compound_name:compoundName
  1298 {:
  1299     nameList.add(compoundName);
  1300     RESULT = nameList;
  1301 :}
  1302 ;
  1303 
  1304 used_char ::=
  1305 CHAR_LITERAL:charLiteral
  1306 {:
  1307     RESULT = charLiteral;
  1308 :}
  1309 ;
  1310 
  1311 indexed_component ::=
  1312 name:name LPAREN value_s:index RPAREN:end
  1313 {:
  1314     RESULT = name;
  1315 :}
  1316 ;
  1317 
  1318 value_s ::= value
  1319 	| value_s COMMA value
  1320 	;
  1321 
  1322 value ::= expression
  1323 | comp_assoc
  1324 | discrete_with_range
  1325 | error:theError /* error statement */
  1326 {:
  1327     ASTError error = new ASTError(theErrorleft, theErrorright);
  1328     RESULT = error;
  1329 :}
  1330 ;
  1331 
  1332 ///////////////////////////////////////////////////////////////////////////////
  1333 // 4.1.3 Selected Components
  1334 //
  1335 selected_component ::=
  1336 name:name DOT simple_name:simple_name
  1337 {:
  1338     Identifier identifier = new Identifier (nameleft, simple_nameright, name.getName() + "." + simple_name.getName());
  1339     RESULT = identifier;
  1340 :}
  1341 | name:name DOT used_char:used_char
  1342 {:
  1343     Identifier identifier = new Identifier (nameleft, used_charright, name.getName() + "." + used_char);
  1344     RESULT = identifier;
  1345 :}
  1346 | name:name DOT operator_symbol:operator
  1347 {:
  1348     Identifier identifier = new Identifier (nameleft, operatorright, name.getName() + "." + operator.getName());
  1349     RESULT = identifier;
  1350 :}
  1351 | name:name DOT ALL:all
  1352 {:
  1353     Identifier identifier = new Identifier (nameleft, allright, name.getName() + "." + "all");
  1354     RESULT = identifier;
  1355 :}
  1356 ;
  1357 
  1358 attribute ::=
  1359 name:name TICK attribute_id
  1360 {:
  1361     RESULT = name;
  1362 :}
  1363 ;
  1364 
  1365 attribute_id ::=
  1366 IDENTIFIER
  1367 | DIGITS
  1368 | DELTA
  1369 | ACCESS
  1370 ;
  1371 
  1372 literal ::=
  1373 DECIMAL_LITERAL:dec
  1374 {:
  1375     Scalar scalar = new Scalar(decleft, decright, dec, Scalar.Type.INT);
  1376     RESULT = scalar;
  1377 :}
  1378 | BASED_LITERAL:dec
  1379 {:
  1380     Scalar scalar = new Scalar(decleft, decright, dec, Scalar.Type.INT);
  1381     RESULT = scalar;
  1382 :}
  1383 | used_char:usedChar
  1384 {:
  1385     Scalar scalar = new Scalar(usedCharleft, usedCharright, usedChar, Scalar.Type.STRING);
  1386     RESULT = scalar;
  1387 :}
  1388 | NULL:token
  1389 {:
  1390     Scalar scalar = new Scalar(tokenleft, tokenright, "null", Scalar.Type.SYSTEM);
  1391     RESULT = scalar;
  1392 :}
  1393 ;
  1394 
  1395 aggregate ::= LPAREN comp_assoc RPAREN
  1396 	| LPAREN value_s_2 RPAREN
  1397 	| LPAREN expression WITH value_s RPAREN
  1398 	| LPAREN expression WITH NULL RECORD RPAREN
  1399 	| LPAREN NULL RECORD RPAREN
  1400 	;
  1401 
  1402 value_s_2 ::= value COMMA value
  1403 	| value_s_2 COMMA value
  1404 	;
  1405 
  1406 comp_assoc ::= choice_s ARROW expression
  1407 	;
  1408 
  1409 
  1410 ///////////////////////////////////////////////////////////////////////////////
  1411 // 4.5 Operators and Expression Evaluation
  1412 //
  1413 logical_operator ::=
  1414 AND
  1415 {:
  1416     RESULT = InfixExpression.OperatorType.BOOL_AND;
  1417 :}
  1418 | OR
  1419 {:
  1420     RESULT = InfixExpression.OperatorType.BOOL_OR;
  1421 :}
  1422 | XOR
  1423 {:
  1424     RESULT = InfixExpression.OperatorType.BOOL_XOR;
  1425 :}
  1426 ;
  1427 
  1428 short_circuit ::=
  1429 AND THEN
  1430 {:
  1431     RESULT = InfixExpression.OperatorType.BOOL_OR;
  1432 :}
  1433 | OR ELSE
  1434 {:
  1435     RESULT = InfixExpression.OperatorType.BOOL_AND;
  1436 :}
  1437 ;
  1438 
  1439 relational_operator ::=
  1440 EQ
  1441 {:
  1442     RESULT = InfixExpression.OperatorType.IS_EQUAL;
  1443 :}
  1444 | INEQ
  1445 {:
  1446     RESULT = InfixExpression.OperatorType.IS_NOT_EQUAL;
  1447 :}
  1448 | GT
  1449 {:
  1450     RESULT = InfixExpression.OperatorType.RGREATER;
  1451 :}
  1452 | LTEQ
  1453 {:
  1454     RESULT = InfixExpression.OperatorType.IS_SMALLER_OR_EQUAL;
  1455 :}
  1456 | LT
  1457 {:
  1458     RESULT = InfixExpression.OperatorType.LGREATER;
  1459 :}
  1460 | GTEQ
  1461 {:
  1462     RESULT = InfixExpression.OperatorType.IS_GREATER_OR_EQUAL;
  1463 :}
  1464 ;
  1465 
  1466 membership ::=
  1467 IN
  1468 {:
  1469     RESULT = InfixExpression.OperatorType.IN;
  1470 :}
  1471 | NOT IN
  1472 {:
  1473     RESULT = InfixExpression.OperatorType.NOT_IN;
  1474 :}
  1475 ;
  1476 
  1477 unary_adding_operator ::=
  1478 PLUS
  1479 {:
  1480     RESULT = UnaryOperation.Operator.PLUS;
  1481 :}
  1482 | MINUS
  1483 {:
  1484     RESULT = UnaryOperation.Operator.MINUS;
  1485 :}
  1486 ;
  1487 
  1488 binary_adding_operator ::= 
  1489 PLUS
  1490 {:
  1491     RESULT = InfixExpression.OperatorType.PLUS;
  1492 :}
  1493 | MINUS
  1494 {:
  1495     RESULT = InfixExpression.OperatorType.MINUS;
  1496 :}
  1497 | AMP
  1498 {:
  1499     RESULT = InfixExpression.OperatorType.STRING_AND;
  1500 :}
  1501 ;
  1502 
  1503 multiplying_operator ::=
  1504 STAR
  1505 {:
  1506     RESULT = InfixExpression.OperatorType.MUL;
  1507 :}
  1508 | SLASH
  1509 {:
  1510     RESULT = InfixExpression.OperatorType.DIV;
  1511 :}
  1512 | MOD
  1513 {:
  1514     RESULT = InfixExpression.OperatorType.MOD;
  1515 :}
  1516 | REM
  1517 {:
  1518     RESULT = InfixExpression.OperatorType.REM;
  1519 :}
  1520 ;
  1521 
  1522 ///////////////////////////////////////////////////////////////////////////////
  1523 // 4.4 Expressions
  1524 //
  1525 expression ::=
  1526 relation:relation
  1527 {:
  1528     RESULT = relation;
  1529 :}
  1530 | expression:expression logical_operator:logical_operator relation:relation
  1531 {:
  1532     InfixExpression infixExpression = new InfixExpression(expressionleft, relationright, expression, logical_operator, relation);
  1533     RESULT = infixExpression;
  1534 :}
  1535 | expression:expression short_circuit:short_circuit relation:relation
  1536 {:
  1537     InfixExpression infixExpression = new InfixExpression(expressionleft, relationright, expression, short_circuit, relation);
  1538     RESULT = infixExpression;
  1539 :}
  1540 ;
  1541 
  1542 relation ::=
  1543 simple_expression:simple_expression
  1544 {:
  1545     RESULT = simple_expression;
  1546 :}
  1547 | simple_expression:simple_expression1 relational_operator:relational_operator simple_expression:simple_expression2
  1548 {:
  1549     InfixExpression infixExpression = new InfixExpression(simple_expression1left, simple_expression2right, simple_expression1, relational_operator, simple_expression2);
  1550     RESULT = infixExpression;
  1551 :}
  1552 | simple_expression:simple_expression membership:membership range:range
  1553 {:
  1554     InfixExpression infixExpression = new InfixExpression(simple_expressionleft, rangeright, simple_expression, membership, range);
  1555     RESULT = infixExpression;
  1556 :}
  1557 | simple_expression:simple_expression membership:membership name:name
  1558 {:
  1559     InfixExpression infixExpression = new InfixExpression(simple_expressionleft, nameright, simple_expression, membership, name);
  1560     RESULT = infixExpression;
  1561 :}
  1562 ;
  1563 
  1564 simple_expression ::=
  1565 unary_adding_operator:unary_adding_operator term:term
  1566 {:
  1567     UnaryOperation unaryOperation = new UnaryOperation(unary_adding_operatorleft, termright, term, unary_adding_operator);
  1568     RESULT = unaryOperation;
  1569 :}
  1570 | term:term
  1571 {:
  1572     RESULT = term;
  1573 :}
  1574 | simple_expression:simple_expression binary_adding_operator:binary_adding_operator term:term
  1575 {:
  1576     InfixExpression infixExpression = new InfixExpression(simple_expressionleft, termright, simple_expression, binary_adding_operator, term);
  1577     RESULT = infixExpression;
  1578 :}
  1579 ;
  1580 
  1581 term ::=
  1582 factor:factor
  1583 {:
  1584     RESULT = factor;
  1585 :}
  1586 | term:term multiplying_operator:multiplying_operator factor:factor
  1587 {:
  1588     InfixExpression infixExpression = new InfixExpression(termleft, factorright, term, multiplying_operator, factor);
  1589     RESULT = infixExpression;
  1590 :}
  1591 ;
  1592 
  1593 factor ::=
  1594 primary:primary
  1595 {:
  1596     RESULT = primary;
  1597 :}
  1598 | NOT:token primary:primary
  1599 {:
  1600     UnaryOperation unaryOperation = new UnaryOperation(tokenleft, primaryright, primary, UnaryOperation.Operator.NOT);
  1601     RESULT = unaryOperation;
  1602 :}
  1603 | ABS:token primary:primary
  1604 {:
  1605     UnaryOperation unaryOperation = new UnaryOperation(tokenleft, primaryright, primary, UnaryOperation.Operator.ABS);
  1606     RESULT = unaryOperation;
  1607 :}
  1608 | primary:primary1 EXPON primary:primary2
  1609 {:
  1610     InfixExpression infixExpression = new InfixExpression(primary1left, primary2right, primary1, InfixExpression.OperatorType.EXPON, primary2);
  1611     RESULT = infixExpression;
  1612 :}
  1613 ;
  1614 
  1615 primary ::=
  1616 literal:literal
  1617 {:
  1618     RESULT = literal;
  1619 :}
  1620 | name:name
  1621 {:
  1622 // TODO: must be modified for manage all primery types
  1623     Variable variable = new Variable (nameleft, nameright, name);
  1624     RESULT = variable;
  1625 :}
  1626 | allocator
  1627 | qualified_expression:qualified_expression
  1628 {:
  1629     RESULT = qualified_expression;
  1630 :}
  1631 | parenthesized_primary:parenthesized_primary
  1632 {:
  1633     RESULT = parenthesized_primary;
  1634 :}
  1635 ;
  1636 
  1637 parenthesized_primary ::=
  1638 aggregate
  1639 | LPAREN expression:expression RPAREN
  1640 {:
  1641     RESULT = expression;
  1642 :}
  1643 ;
  1644 
  1645 qualified_expression ::=
  1646 name:name TICK parenthesized_primary:expr
  1647 {:
  1648     RESULT = new QualifiedExpression (nameleft, exprright, name, expr);
  1649 :}
  1650 ;
  1651 
  1652 allocator ::= NEW name
  1653 	| NEW qualified_expression
  1654 	;
  1655 
  1656 ///////////////////////////////////////////////////////////////////////////////
  1657 // 5.1 Simple and Compound Statements - Sequences of Statements
  1658 //
  1659 sequence_of_statements ::=
  1660 statement:statement
  1661 {:
  1662     List list = new LinkedList();
  1663     list.add(statement);
  1664     RESULT = list;
  1665 :}
  1666 | sequence_of_statements:list statement:statement
  1667 {:
  1668     list.add(statement);
  1669     RESULT = list;
  1670 :}
  1671 ;
  1672 
  1673 statement ::=
  1674 unlabeled:statement
  1675 {:
  1676     RESULT = statement;
  1677 :}
  1678 | label statement:statement
  1679 {:
  1680     RESULT = statement;
  1681 :}
  1682 ;
  1683 
  1684 unlabeled ::=
  1685 simple_statement:statement
  1686 {:
  1687     RESULT = statement;
  1688 :}
  1689 | compound_statement:statement
  1690 {:
  1691     RESULT = statement;
  1692 :}
  1693 | pragma
  1694 ;
  1695 
  1696 simple_statement ::=
  1697 null_statement:statement
  1698 {:
  1699     RESULT = statement;
  1700 :}
  1701 | assignment_statement:statement
  1702 {:
  1703     RESULT = statement;
  1704 :}
  1705 | exit_statement:statement
  1706 {:
  1707     RESULT = statement;
  1708 :}
  1709 | return_statement:statement
  1710 {:
  1711     RESULT = statement;
  1712 :}
  1713 | goto_statement:statement
  1714 {:
  1715     RESULT = statement;
  1716 :}
  1717 | procedure_call_statement:statement
  1718 {:
  1719     RESULT = statement;
  1720 :}
  1721 | delay_statement:statement
  1722 {:
  1723     RESULT = statement;
  1724 :}
  1725 | abort_statement:statement
  1726 {:
  1727     RESULT = statement;
  1728 :}
  1729 | raise_statement:statement
  1730 {:
  1731     RESULT = statement;
  1732 :}
  1733 | code_statement:statement
  1734 {:
  1735     RESULT = statement;
  1736 :}
  1737 | requeue_stmt
  1738 | error:theError SEMICOLON /* error statement */
  1739 {:
  1740     ASTError error = new ASTError(theErrorleft, theErrorright);
  1741     RESULT = error;
  1742 :}
  1743 ;
  1744 
  1745 compound_statement ::=
  1746 if_statement:statement
  1747 {:
  1748     RESULT = statement;
  1749 :}
  1750 | case_statement:statement
  1751 {:
  1752     RESULT = statement;
  1753 :}
  1754 | loop_statement:statement
  1755 {:
  1756     RESULT = statement;
  1757 :}
  1758 | block_statement:statement
  1759 {:
  1760     RESULT = statement;
  1761 :}
  1762 | accept_stmt
  1763 | select_stmt
  1764 ;
  1765 
  1766 label ::= LTLT IDENTIFIER GTGT
  1767 	;
  1768 
  1769 null_statement ::= 
  1770 NULL:token SEMICOLON:end
  1771 {:
  1772     RESULT = new NullStatement(tokenleft, endright);
  1773 :}
  1774 ;
  1775 
  1776 ///////////////////////////////////////////////////////////////////////////////
  1777 // 5.2 Assignment Statements
  1778 //
  1779 assignment_statement ::=
  1780 name:name ASSIGNMENT expression:expression SEMICOLON
  1781 {:
  1782     Variable variable = new Variable (nameleft, nameright, name);
  1783     Assignment assignment = new Assignment(nameleft, expressionright, variable, expression);
  1784     RESULT = assignment;
  1785 :}
  1786 ;
  1787 
  1788 ///////////////////////////////////////////////////////////////////////////////
  1789 // 5.3 If Statements
  1790 //
  1791 if_statement ::= 
  1792 IF:token cond_clause_s:condList else_opt:iffalse END IF SEMICOLON:end
  1793 {:
  1794     Expression innerCondition = null;
  1795     Expression firstCondition = null;
  1796     Statement trueStatement = null;
  1797     Statement falseStatement = iffalse;
  1798 
  1799     for (int i=1 ; i < condList[0].size() ; i++) {
  1800         innerCondition = (Expression)condList[0].get(i);
  1801         trueStatement = (Statement)condList[1].get(i);
  1802         int start = ((Integer)condList[2].get(i)).intValue();
  1803         falseStatement = new IfStatement(start, endright, innerCondition, trueStatement, falseStatement);
  1804     }
  1805 
  1806     firstCondition = (Expression)condList[0].get(0);
  1807     trueStatement = (Statement)condList[1].get(0);
  1808     int start = ((Integer)condList[2].get(0)).intValue();
  1809     IfStatement ifStatement = new IfStatement(tokenleft, endright, firstCondition, trueStatement, falseStatement);		
  1810 
  1811     RESULT = ifStatement;
  1812 :}
  1813 ;
  1814 
  1815 cond_clause_s ::= 
  1816 condition:condition THEN:token sequence_of_statements:iftrue
  1817 {:
  1818     List listConditions = new LinkedList();
  1819     List listStatements = new LinkedList();
  1820     List listTokens = new LinkedList();
  1821 
  1822     Block block = new Block(iftrueleft, iftrueright, iftrue);
  1823     listConditions.add(condition);
  1824     listStatements.add(block);
  1825     listTokens.add(new Integer(tokenleft));
  1826 
  1827     List[] returnList = new List[] { listConditions, listStatements, listTokens };
  1828 	
  1829     RESULT = returnList;
  1830 :}
  1831 | cond_clause_s:condList ELSIF:token condition:condition THEN sequence_of_statements:iftrue
  1832 {:
  1833     Block block = new Block(iftrueleft, iftrueright, iftrue);
  1834     ((LinkedList)condList[0]).addFirst(condition);
  1835     ((LinkedList)condList[1]).addFirst(block);
  1836     ((LinkedList)condList[2]).addFirst(new Integer(tokenleft));
  1837 
  1838     RESULT = condList;
  1839 :}
  1840 ;
  1841 
  1842 condition ::=
  1843 expression:expression
  1844 {:
  1845     RESULT = expression;
  1846 :}
  1847 ;
  1848 
  1849 else_opt ::=
  1850 /* empty */
  1851 {:
  1852     RESULT = null;
  1853 :}
  1854 | ELSE sequence_of_statements:statements
  1855 {:
  1856     Block block = new Block(statementsleft, statementsright, statements);
  1857     RESULT = block;
  1858 :}
  1859 ;
  1860 
  1861 ///////////////////////////////////////////////////////////////////////////////
  1862 // 5.4 Case Statements
  1863 //
  1864 case_statement ::=
  1865 CASE:token expression:expr IS pragma_s alternative_s:whenList END CASE SEMICOLON:end
  1866 {:
  1867     Block whenBlock = new Block(whenListleft, whenListright, whenList);
  1868     CaseStatement caseStatement = new CaseStatement(tokenleft, endright, expr, whenBlock);
  1869     RESULT = caseStatement;
  1870 :}
  1871 ;
  1872 
  1873 alternative_s ::=
  1874 /* empty */
  1875 {:
  1876     RESULT = new LinkedList();
  1877 :}
  1878 | alternative_s:whenList alternative:when
  1879 {:
  1880     whenList.add (when);
  1881     RESULT = whenList;
  1882 :}
  1883 ;
  1884 
  1885 alternative ::=
  1886 WHEN:token choice_s:expr ARROW sequence_of_statements:statements
  1887 {:
  1888     CaseWhen caseWhen = new CaseWhen(tokenleft, statementsright, expr, statements);
  1889     RESULT = caseWhen;
  1890 :}
  1891 ;
  1892 
  1893 ///////////////////////////////////////////////////////////////////////////////
  1894 // 5.5 Loop Statements
  1895 //
  1896 loop_statement ::=
  1897 label_opt:label iteration:iteration basic_loop:statement id_opt SEMICOLON:end
  1898 {:
  1899     int start = (label == null) ? iterationleft : labelleft;
  1900     LoopStatement loopStatement = new LoopStatement(start, endright, label, iteration, statement);
  1901     RESULT = loopStatement;
  1902 :}
  1903 ;
  1904 
  1905 label_opt ::=
  1906 /* empty */
  1907 {:
  1908     RESULT = null;
  1909 :}
  1910 | IDENTIFIER:id COLON
  1911 {:
  1912     Identifier identifier = new Identifier (idleft, idright, id);
  1913     RESULT = identifier;
  1914 :}
  1915 ;
  1916 
  1917 iteration ::=
  1918 /* empty */
  1919 {:
  1920     RESULT = null;
  1921 :}
  1922 | WHILE condition:condition
  1923 {:
  1924     RESULT = condition;
  1925 :}
  1926 | iter_part reverse_opt discrete_range:condition
  1927 {:
  1928     RESULT = condition;
  1929 :}
  1930 ;
  1931 
  1932 iter_part ::=
  1933 FOR IDENTIFIER IN
  1934 ;
  1935 
  1936 reverse_opt ::=
  1937 | REVERSE
  1938 ;
  1939 
  1940 basic_loop ::=
  1941 LOOP sequence_of_statements:statements END LOOP
  1942 {:
  1943     Block loopBlock = new Block(statementsleft, statementsright, statements);
  1944     RESULT = loopBlock;
  1945 :}
  1946 ;
  1947 
  1948 
  1949 ///////////////////////////////////////////////////////////////////////////////
  1950 
  1951 id_opt ::=
  1952 // empty
  1953 {:
  1954     RESULT = null;
  1955 :}
  1956 | designator:designator
  1957 {:
  1958     RESULT = designator;
  1959 :}
  1960 ;
  1961 
  1962 ///////////////////////////////////////////////////////////////////////////////
  1963 // 5.6 Block Statements
  1964 //
  1965 block_statement ::=
  1966 label_opt:label block_declarative:declarations block_body:body END id_opt SEMICOLON:end
  1967 {:
  1968     int start = (label == null) ? declarationsleft : labelleft;
  1969     BlockStatement blockStatement = new BlockStatement (start, endleft, label, declarations, body);
  1970     RESULT = blockStatement;
  1971 :}
  1972 ;
  1973 
  1974 block_declarative ::=
  1975 {:
  1976     RESULT = null;
  1977 :}
  1978 | DECLARE:token declarative_part:declarativePart
  1979 {:
  1980     Block declarations = new Block(tokenright, declarativePartleft, declarativePart);
  1981     RESULT = declarations;
  1982 :}
  1983 ;
  1984 
  1985 block_body ::=
  1986 BEGIN:token handled_stmt_s:statements
  1987 {:
  1988     Block body = new Block(tokenright, statementsright, statements);
  1989     RESULT = body;
  1990 :}
  1991 ;
  1992 
  1993 handled_stmt_s ::=
  1994 sequence_of_statements:statements except_handler_part_opt
  1995 {:
  1996     RESULT = statements;
  1997 :}
  1998 ; 
  1999 
  2000 except_handler_part_opt ::=
  2001 	| except_handler_part
  2002 	;
  2003 
  2004 ///////////////////////////////////////////////////////////////////////////////
  2005 // 5.7 Exit Statements
  2006 //
  2007 exit_statement ::= 
  2008 EXIT:token name_opt:loopName when_opt:whenCondition SEMICOLON:end
  2009 {:
  2010     RESULT = new ExitStatement(tokenleft, endright, loopName, whenCondition); 
  2011 :}
  2012 ;
  2013 
  2014 name_opt ::=
  2015 {:
  2016     RESULT = null;
  2017 :}
  2018 | name:name
  2019 {:
  2020     RESULT = name;
  2021 :}
  2022 ;
  2023 
  2024 when_opt ::=
  2025 {:
  2026     RESULT = null;
  2027 :}
  2028 | WHEN condition:cond
  2029 {:
  2030     RESULT = cond;
  2031 :}
  2032 ;
  2033 
  2034 ///////////////////////////////////////////////////////////////////////////////
  2035 // 6.5 Return Statements
  2036 //
  2037 return_statement ::= 
  2038 RETURN:token SEMICOLON:end
  2039 {:
  2040     RESULT = new ReturnStatement(tokenleft, endright);
  2041 :}
  2042 | RETURN:token expression:expr SEMICOLON:end
  2043 {:
  2044     RESULT = new ReturnStatement(tokenleft, endright, expr);
  2045 :}
  2046 ;
  2047 
  2048 ///////////////////////////////////////////////////////////////////////////////
  2049 // 5.8 Goto Statements
  2050 //
  2051 goto_statement ::= 
  2052 GOTO:token name:labelName SEMICOLON:end
  2053 {:
  2054     RESULT = new GotoStatement(tokenleft, endright, labelName);
  2055 :}
  2056 ;
  2057 
  2058 ///////////////////////////////////////////////////////////////////////////////
  2059 // 6.1 Subprogram Declarations
  2060 //
  2061 subprog_declaration ::=
  2062 subprogram_specification:subprog SEMICOLON:end
  2063 {:
  2064     RESULT = new MethodDeclaration(subprogleft, endright, 0/*modifier*/, subprog);
  2065 :}
  2066 | generic_subp_inst:subprog SEMICOLON:end
  2067 {:
  2068     RESULT = new MethodDeclaration(subprogleft, endright, 0/*modifier*/, subprog);
  2069 :}
  2070 | subprogram_specification:subprog IS ABSTRACT SEMICOLON:end
  2071 {:
  2072     RESULT = new MethodDeclaration(subprogleft, endright, Ada95ASTParser.ABSTRACT, subprog);
  2073 :}
  2074 ;
  2075 
  2076 subprogram_specification ::=
  2077 PROCEDURE:procedure compound_name:compound_name formal_part_opt:formal_part
  2078 {:
  2079     SubprogramSpecification subprogramSpecification = new SubprogramSpecification(procedureleft, formal_partright, compound_name, formal_part);
  2080     RESULT = subprogramSpecification;
  2081 :}
  2082 | FUNCTION:function designator:designator formal_part_opt:formal_part RETURN name:subtype_mark
  2083 {:
  2084     SubprogramSpecification subprogramSpecification = new SubprogramSpecification(functionleft, subtype_markright, designator, formal_part, subtype_mark);
  2085     RESULT = subprogramSpecification;
  2086 :}
  2087 | FUNCTION:function designator:designator  /* for generic inst and generic rename */
  2088 {:
  2089     SubprogramSpecification subprogramSpecification = new SubprogramSpecification(functionleft, designatorright, designator);
  2090     RESULT = subprogramSpecification;
  2091 :}
  2092 ;
  2093 
  2094 designator ::=
  2095 compound_name:name
  2096 {:
  2097     RESULT = name;
  2098 :}
  2099 | operator_symbol:name
  2100 {:
  2101     RESULT = name;
  2102 :}
  2103 ;
  2104 
  2105 formal_part_opt ::=
  2106 // empty
  2107 {:
  2108 	List list = new LinkedList();
  2109 	RESULT = list;
  2110 :}
  2111 | formal_part:list
  2112 {:
  2113 	RESULT = list;
  2114 :}
  2115 ;
  2116 
  2117 formal_part ::=
  2118 LPAREN param_s:list RPAREN
  2119 {:
  2120 	RESULT = list;
  2121 :}
  2122 ;
  2123 
  2124 param_s ::=
  2125 param:parameter
  2126 {:
  2127     List list = new LinkedList();
  2128     list.addAll(parameter);
  2129     RESULT = list;
  2130 :}
  2131 | param_s:list SEMICOLON param:parameter
  2132 {:
  2133     list.addAll(parameter);
  2134     RESULT = list;
  2135 :}
  2136 ;
  2137 
  2138 param ::=
  2139 defining_identifier_list:identifierList COLON mode:mode subtype_mark:subtype init_opt:init
  2140 {:
  2141     List list = new LinkedList();
  2142     for (Object item : identifierList) {
  2143         Identifier identifier = (Identifier)item;
  2144         Variable variable = new Variable (identifier.getStartOffset(), identifier.getEndOffset(), identifier);
  2145 	    int end = init == null ? subtyperight : initright;
  2146         FormalParameter parameter = new FormalParameter(identifierListleft, end, variable, mode, subtype, init);
  2147     	list.add(parameter);
  2148     }
  2149     RESULT = list;
  2150 :}
  2151 | error:theError SEMICOLON /* error statement */
  2152 {:
  2153     List list = new LinkedList();
  2154     ASTError error = new ASTError(theErrorleft, theErrorright);
  2155     list.add(error);
  2156     RESULT = list;
  2157 :}
  2158 ;
  2159 
  2160 mode ::=
  2161 // empty
  2162 {:
  2163     RESULT = FormalParameter.Mode.IN;
  2164 :}
  2165 | IN
  2166 {:
  2167     RESULT = FormalParameter.Mode.IN;
  2168 :}
  2169 | OUT
  2170 {:
  2171     RESULT = FormalParameter.Mode.OUT;
  2172 :}
  2173 | IN OUT
  2174 {:
  2175     RESULT = FormalParameter.Mode.IN_OUT;
  2176 :}
  2177 | ACCESS
  2178 {:
  2179     RESULT = FormalParameter.Mode.ACCESS;
  2180 :}
  2181 ;
  2182 
  2183 // TODO: manage the overload operators ex: "+" "and" ecc.
  2184 operator_symbol ::=
  2185 STRING_LITERAL:string_literal
  2186 {:
  2187     Identifier identifier = new Identifier (string_literalleft, string_literalright, string_literal);
  2188     RESULT = identifier;
  2189 :}
  2190 ;
  2191 
  2192 subprogram_body ::=
  2193 subprogram_specification:subprog IS
  2194 declarative_part:declarativePart block_body:body END id_opt:id_opt SEMICOLON:end
  2195 {:
  2196     if (id_opt != null && !id_opt.getName().equalsIgnoreCase (subprog.getSubprogramName().getName())) {
  2197         this.parser.message_error("mispelling of " + subprog.getSubprogramName().getName());
  2198     } else {
  2199         Block declarations = new Block(subprogright, bodyleft, declarativePart);
  2200         body.setEndOffset(endright);
  2201         SubprogramBody subprogramBody = new SubprogramBody(subprogleft, endright, subprog, declarations, body, id_opt);
  2202         MethodDeclaration methodDeclaration = new MethodDeclaration(subprogleft, endright, 0/*modifier*/, subprogramBody);
  2203         RESULT = methodDeclaration;
  2204     }
  2205 :}
  2206 ;
  2207 
  2208 ///////////////////////////////////////////////////////////////////////////////
  2209 // 6.4 Subprogram Calls
  2210 //
  2211 procedure_call_statement ::=
  2212 name SEMICOLON
  2213 ;
  2214 
  2215 
  2216 ///////////////////////////////////////////////////////////////////////////////
  2217 // 7.1 Package Specifications and Declarations
  2218 //
  2219 package_declaration ::= 
  2220 package_specification:statement SEMICOLON
  2221 {:
  2222     RESULT = statement;
  2223 :}
  2224 | generic_package_instantiation SEMICOLON
  2225 ;
  2226 
  2227 package_specification ::= 
  2228 PACKAGE:declarationStart compound_name:package_name IS:blockStart
  2229   declarative_items_opt:declarativeItems private_part:privateDeclarativeItems
  2230 END:declarationEnd compound_name_opt:package_name_end
  2231 {:
  2232     if (package_name_end != null && !package_name_end.getName().equalsIgnoreCase (package_name.getName())) {
  2233         this.parser.message_error("mispelling of " + package_name);
  2234     }
  2235     else {
  2236         declarativeItems.addAll (privateDeclarativeItems);
  2237         // Add private part on block statements
  2238         Block block = new Block(blockStartleft, declarationEndright, declarativeItems);
  2239         PackageSpecification packageSpecification = new PackageSpecification(declarationStartleft, declarationEndright, package_name, package_name_end, block);
  2240         RESULT = packageSpecification;
  2241     }
  2242 :}
  2243 ;
  2244 
  2245 private_part ::=
  2246 {:
  2247     RESULT = new LinkedList();
  2248 :}
  2249 | PRIVATE declarative_items_opt:declarativeItems
  2250 {:
  2251     RESULT = this.parser.setModifier (declarativeItems, Ada95ASTParser.PRIVATE);
  2252 :}
  2253 ;
  2254 
  2255 compound_name_opt ::=
  2256 // empty
  2257 | compound_name:compound_name
  2258 {:
  2259     RESULT = compound_name;
  2260 :}
  2261 ;
  2262 
  2263 ///////////////////////////////////////////////////////////////////////////////
  2264 // 7.2 Package Bodies
  2265 //
  2266 package_body ::=
  2267 PACKAGE:declarationStart BODY compound_name:package_name IS:blockStart
  2268   declarative_part:declarativePart body_opt END compound_name_opt:package_name_end SEMICOLON:declarationEnd
  2269 {:
  2270     if (package_name_end != null && !package_name_end.getName().equalsIgnoreCase (package_name.getName())) {
  2271         this.parser.message_error("mispelling of " + package_name);
  2272     }
  2273     else {
  2274 
  2275         List list = this.parser.setModifier (declarativePart, Ada95ASTParser.PRIVATE);
  2276         Block block = new Block(blockStartleft, declarationEndright, list);
  2277 
  2278         PackageBody packageBody = new PackageBody(declarationStartleft, declarationEndright, package_name, package_name_end, block);
  2279         RESULT = packageBody;
  2280     }
  2281 :}
  2282 ;
  2283 
  2284 body_opt ::=
  2285 	| block_body
  2286 	;
  2287 
  2288 ///////////////////////////////////////////////////////////////////////////////
  2289 // 7.3 Private Types and Private Extensions
  2290 //
  2291 private_type_declaration ::=
  2292 tagged_opt:tagged limited_opt:limited PRIVATE:privateKeyword
  2293 {:
  2294     PrivateType privateType = new PrivateType(taggedleft, privateKeywordright, tagged + limited + Ada95ASTParser.PRIVATE);
  2295     RESULT = privateType;
  2296 :}
  2297 ;
  2298 
  2299 limited_opt ::=
  2300 {:
  2301     RESULT = 0;
  2302 :}
  2303 | LIMITED
  2304 {:
  2305     RESULT = Ada95ASTParser.LIMITED;
  2306 :}
  2307 ;
  2308 
  2309 ///////////////////////////////////////////////////////////////////////////////
  2310 // 8.4 Use Clauses
  2311 //
  2312 use_clause ::= 
  2313 USE:token package_name_list:packageList SEMICOLON:end
  2314 {:
  2315     RESULT = new Use(tokenleft, endright, packageList);
  2316 :}
  2317 | USE:token TYPE subtype_mark_list:subTypeList SEMICOLON:end
  2318 {:
  2319     RESULT = new UseType(tokenleft, endright, subTypeList);
  2320 :}
  2321 ;
  2322 
  2323 package_name_list ::=
  2324 name:name
  2325 {:
  2326     List idList = new LinkedList();
  2327     PackageName packageName = new PackageName(nameleft, nameright, name);
  2328     idList.add(packageName);
  2329     RESULT = idList;
  2330 :}
  2331 | package_name_list:idList COMMA name:name
  2332 {:
  2333     PackageName packageName = new PackageName(nameleft, nameright, name);
  2334     idList.add(packageName);
  2335     RESULT = idList;
  2336 :}
  2337 ;
  2338 
  2339 subtype_mark_list ::=
  2340 name:name
  2341 {:
  2342     List idList = new LinkedList();
  2343     TypeName typeName = new TypeName(nameleft, nameright, name);
  2344     idList.add(typeName);
  2345     RESULT = idList;
  2346 :}
  2347 | subtype_mark_list:idList COMMA name:name
  2348 {:
  2349     TypeName typeName = new TypeName(nameleft, nameright, name);
  2350     idList.add(typeName);
  2351     RESULT = idList;
  2352 :}
  2353 ;
  2354 
  2355 
  2356 ///////////////////////////////////////////////////////////////////////////////
  2357 // 8.5 Renaming Declarations
  2358 //
  2359 renaming_declaration ::=
  2360 defining_identifier_list COLON object_qualifier_opt subtype_indication RENAMES name SEMICOLON
  2361 | defining_identifier_list COLON EXCEPTION RENAMES name SEMICOLON
  2362 | rename_unit:unit
  2363 {:
  2364     RESULT = unit;
  2365 :}
  2366 ;
  2367 
  2368 rename_unit ::= 
  2369 PACKAGE:token compound_name:name RENAMES name:renames SEMICOLON:end
  2370 {:
  2371     PackageRenames packageRenames = new PackageRenames(tokenleft, endright, name, renames);
  2372     RESULT = packageRenames;
  2373 :}
  2374 | subprogram_specification RENAMES name SEMICOLON:end
  2375 | generic_formal_part PACKAGE compound_name RENAMES name SEMICOLON
  2376 | generic_formal_part subprogram_specification RENAMES name SEMICOLON
  2377 ;
  2378 
  2379 task_decl ::= task_spec SEMICOLON
  2380 	;
  2381 
  2382 task_spec ::= TASK simple_name task_def
  2383 	| TASK TYPE simple_name discrim_part_opt task_def
  2384 	;
  2385 
  2386 task_def ::=
  2387 	| IS entry_decl_s rep_spec_s task_private_opt END id_opt
  2388 	;
  2389 
  2390 task_private_opt ::=
  2391 	| PRIVATE entry_decl_s rep_spec_s
  2392 	;
  2393 
  2394 task_body ::= TASK BODY simple_name IS
  2395 	       declarative_part block_body END id_opt SEMICOLON
  2396 	;
  2397 
  2398 prot_decl ::= prot_spec SEMICOLON
  2399 	;
  2400 
  2401 prot_spec ::= PROTECTED IDENTIFIER prot_def
  2402 	| PROTECTED TYPE simple_name discrim_part_opt prot_def
  2403 	;
  2404 
  2405 prot_def ::= IS prot_op_decl_s prot_private_opt END id_opt
  2406 	;
  2407 
  2408 prot_private_opt ::=
  2409 	| PRIVATE prot_elem_decl_s
  2410 	;
  2411 
  2412 prot_op_decl_s ::= 
  2413 	| prot_op_decl_s prot_op_decl
  2414 	;
  2415 
  2416 prot_op_decl ::= entry_decl
  2417 	| subprogram_specification SEMICOLON
  2418 	| rep_spec
  2419 	| pragma
  2420 	;
  2421 
  2422 prot_elem_decl_s ::= 
  2423 	| prot_elem_decl_s prot_elem_decl
  2424 	;
  2425 
  2426 prot_elem_decl ::= prot_op_decl | comp_decl ;
  2427 
  2428 /////////////////////////////////////////////////////////////////
  2429 // 9.4 Protected Units and Protected Objects
  2430 //
  2431 protected_body ::= 
  2432 PROTECTED BODY simple_name:name IS
  2433 prot_op_body_s END id_opt SEMICOLON
  2434 ;
  2435 
  2436 prot_op_body_s ::= pragma_s
  2437 	| prot_op_body_s prot_op_body pragma_s
  2438 	;
  2439 
  2440 prot_op_body ::= entry_body
  2441 	| subprogram_body
  2442 	| subprogram_specification SEMICOLON
  2443 	;
  2444 
  2445 entry_decl_s ::= pragma_s
  2446 	| entry_decl_s entry_decl pragma_s
  2447 	;
  2448 
  2449 entry_decl ::= ENTRY IDENTIFIER formal_part_opt SEMICOLON
  2450 	| ENTRY IDENTIFIER LPAREN discrete_range RPAREN formal_part_opt SEMICOLON
  2451 	;
  2452 
  2453 entry_body ::= ENTRY IDENTIFIER formal_part_opt WHEN condition entry_body_part
  2454 	| ENTRY IDENTIFIER LPAREN iter_part discrete_range RPAREN 
  2455 		formal_part_opt WHEN condition entry_body_part
  2456 	;
  2457 
  2458 entry_body_part ::= SEMICOLON
  2459 	| IS declarative_part block_body END id_opt SEMICOLON
  2460 	;
  2461 
  2462 rep_spec_s ::=
  2463 	| rep_spec_s rep_spec pragma_s
  2464 	;
  2465 
  2466 entry_call ::= 
  2467 procedure_call_statement:statement
  2468 {:
  2469     RESULT = statement;
  2470 :}
  2471 ;
  2472 
  2473 accept_stmt ::= accept_hdr SEMICOLON
  2474 	| accept_hdr DO handled_stmt_s END id_opt SEMICOLON
  2475 	;
  2476 
  2477 accept_hdr ::= ACCEPT entry_name formal_part_opt
  2478 	;
  2479 
  2480 entry_name ::= simple_name
  2481 	| entry_name LPAREN expression RPAREN
  2482 	;
  2483 
  2484 /////////////////////////////////////////////////////////////////
  2485 // 9.6 Delay Statements, Duration, and Time
  2486 //
  2487 delay_statement ::=
  2488 DELAY:token expression:expr SEMICOLON:end
  2489 {:
  2490     RESULT = new ReturnStatement(tokenleft, endright, expr);
  2491 :}
  2492 | DELAY:token UNTIL expression:expr SEMICOLON:end
  2493 {:
  2494     RESULT = new ReturnStatement(tokenleft, endright, expr);
  2495 :}
  2496 ;
  2497 
  2498 select_stmt ::= select_wait
  2499 	| async_select
  2500 	| timed_entry_call
  2501 	| cond_entry_call
  2502 	;
  2503 
  2504 select_wait ::= SELECT guarded_select_alt or_select else_opt
  2505 	      END SELECT SEMICOLON
  2506 	;
  2507 
  2508 guarded_select_alt ::= select_alt
  2509 	| WHEN condition ARROW select_alt
  2510 	;
  2511 
  2512 or_select ::=
  2513 	| or_select OR guarded_select_alt
  2514 	;
  2515 
  2516 select_alt ::= accept_stmt stmts_opt
  2517 	| delay_statement stmts_opt
  2518 	| TERMINATE SEMICOLON
  2519 	;
  2520 
  2521 delay_or_entry_alt ::= delay_statement stmts_opt
  2522 	| entry_call stmts_opt
  2523 	;
  2524 
  2525 async_select ::= SELECT delay_or_entry_alt
  2526 	       THEN ABORT sequence_of_statements
  2527 	       END SELECT SEMICOLON
  2528 	;
  2529 
  2530 timed_entry_call ::= SELECT entry_call stmts_opt 
  2531 		   OR delay_statement stmts_opt
  2532 	           END SELECT SEMICOLON
  2533 	;
  2534 
  2535 cond_entry_call ::= SELECT entry_call stmts_opt 
  2536 		  ELSE sequence_of_statements
  2537 	          END SELECT SEMICOLON
  2538 	;
  2539 
  2540 stmts_opt ::=
  2541 	| sequence_of_statements
  2542 	;
  2543 
  2544 ///////////////////////////////////////////////////////////////////////////////
  2545 // 9.8 Abort of a Task - Abort of a Sequence of Statements
  2546 //
  2547 abort_statement ::=
  2548 ABORT:token task_name_list:taskList SEMICOLON:end
  2549 {:
  2550     RESULT = new AbortStatement(tokenleft, endright, taskList);
  2551 :}
  2552 ;
  2553 
  2554 task_name_list ::=
  2555 name:name
  2556 {:
  2557     List idList = new LinkedList();
  2558     TaskName taskName = new TaskName(nameleft, nameright, name);
  2559     idList.add(taskName);
  2560     RESULT = idList;
  2561 :}
  2562 | task_name_list:idList COMMA name:name
  2563 {:
  2564     TaskName taskName = new TaskName(nameleft, nameright, name);
  2565     idList.add(taskName);
  2566     RESULT = idList;
  2567 :}
  2568 ;
  2569 
  2570 ///////////////////////////////////////////////////////////////////////////////
  2571 // 10.1.1 Compilation Units - Library Units
  2572 //
  2573 compilation ::=
  2574 compilation_units:units
  2575 {:
  2576     Ada95ASTLexer adaAstLexer = (Ada95ASTLexer) parser.getScanner();
  2577     List comments = adaAstLexer.getCommentList();
  2578     Program program = new Program(unitsleft, unitsright, units, comments);
  2579     RESULT = program;
  2580 :}
  2581 ;
  2582 
  2583 compilation_units ::=
  2584 {:
  2585     RESULT = new LinkedList();
  2586 :}
  2587 | compilation_units:units compilation_unit:unit
  2588 {:
  2589     if(units != null) {
  2590         units.add(unit);
  2591     }
  2592     RESULT = units;
  2593 :}
  2594 | pragma pragma_s  // 10.1.5 - 4
  2595 {:
  2596     RESULT = new LinkedList();
  2597 :}
  2598 ;
  2599 
  2600 compilation_unit ::=
  2601 context_clause private_opt unit:unit pragma_s
  2602 {:
  2603     RESULT = unit;
  2604 :}
  2605 | private_opt unit:unit pragma_s  // 10.1.5 - 5/1
  2606 {:
  2607     RESULT = unit;
  2608 :}
  2609 ;
  2610 
  2611 private_opt ::=
  2612 | PRIVATE
  2613 ;
  2614 
  2615 unit ::= 
  2616 package_declaration:statement
  2617 {:
  2618     RESULT = statement;
  2619 :}
  2620 | package_body:statement
  2621 {:
  2622     RESULT = statement;
  2623 :}
  2624 | subprog_declaration:statement
  2625 {:
  2626     RESULT = statement;
  2627 :}
  2628 | subprogram_body:statement
  2629 {:
  2630     RESULT = statement;
  2631 :}
  2632 | subunit:statement
  2633 {:
  2634     RESULT = statement;
  2635 :}
  2636 | generic_declaration:statement
  2637 {:
  2638     RESULT = statement;
  2639 :}
  2640 | rename_unit
  2641 ;
  2642 
  2643 ///////////////////////////////////////////////////////////////////////////////
  2644 // 10.1.2 Context Clauses - With Clauses
  2645 //
  2646 context_clause ::= 
  2647 with_clause:statement
  2648 {:
  2649     RESULT = statement;
  2650 :}
  2651 | use_clause:statement
  2652 {:
  2653     RESULT = statement;
  2654 :}
  2655 | context_clause with_clause:statement
  2656 {:
  2657     RESULT = statement;
  2658 :}
  2659 | context_clause use_clause:statement
  2660 {:
  2661     RESULT = statement;
  2662 :}
  2663 | context_clause pragma
  2664 ;
  2665 
  2666 with_clause ::= 
  2667 WITH:token library_unit_name_list:packageList SEMICOLON:end
  2668 {:
  2669     RESULT = new With(tokenleft, endright, packageList);
  2670 :}
  2671 ;
  2672 
  2673 ///////////////////////////////////////////////////////////////////////////////
  2674 // 10.1.3 Subunits of Compilation Units
  2675 //
  2676 subunit ::=
  2677 SEPARATE LPAREN compound_name RPAREN
  2678 proper_body:statement
  2679 {:
  2680     RESULT = statement;
  2681 :}
  2682 ;
  2683 
  2684 
  2685 body_stub ::= 
  2686 TASK BODY simple_name IS SEPARATE SEMICOLON
  2687 | PACKAGE BODY compound_name IS SEPARATE SEMICOLON
  2688 | subprogram_specification:subprog IS SEPARATE SEMICOLON
  2689 {:
  2690     RESULT = subprog;
  2691 :}
  2692 | PROTECTED BODY simple_name IS SEPARATE SEMICOLON
  2693 ;
  2694 
  2695 exception_decl ::= defining_identifier_list COLON EXCEPTION SEMICOLON
  2696 	;
  2697 
  2698 except_handler_part ::= EXCEPTION exception_handler
  2699 	| except_handler_part exception_handler
  2700 	;
  2701 
  2702 exception_handler ::= WHEN except_choice_s ARROW sequence_of_statements
  2703 	| WHEN IDENTIFIER COLON except_choice_s ARROW sequence_of_statements
  2704 	;
  2705 
  2706 except_choice_s ::= except_choice
  2707 	| except_choice_s BAR except_choice
  2708 	;
  2709 
  2710 except_choice ::= name
  2711 	| OTHERS
  2712 	;
  2713 
  2714 ///////////////////////////////////////////////////////////////////////////////
  2715 // 11.3 Raise Statements
  2716 //
  2717 raise_statement ::=
  2718 RAISE:token name_opt:exceptionName SEMICOLON:end
  2719 {:
  2720     RESULT = new RaiseStatement(tokenleft, endright, exceptionName); 
  2721 :}
  2722 ;
  2723 
  2724 requeue_stmt ::= REQUEUE name SEMICOLON
  2725 	| REQUEUE name WITH ABORT SEMICOLON
  2726 	;
  2727 
  2728 ///////////////////////////////////////////////////////////////////////////////
  2729 // 12.1 Generic Declarations
  2730 //
  2731 generic_declaration ::= 
  2732 generic_formal_part subprogram_specification SEMICOLON
  2733 | generic_formal_part package_specification:statement SEMICOLON
  2734 {:
  2735     RESULT = statement;
  2736 :}
  2737 ;
  2738 
  2739 generic_formal_part ::= GENERIC
  2740 	| generic_formal_part generic_formal
  2741 	;
  2742 
  2743 generic_formal ::= param SEMICOLON
  2744 	| TYPE simple_name generic_discrim_part_opt IS generic_type_def SEMICOLON
  2745 	| WITH PROCEDURE simple_name 
  2746 	    formal_part_opt subp_default SEMICOLON
  2747 	| WITH FUNCTION designator 
  2748 	    formal_part_opt RETURN name subp_default SEMICOLON
  2749 	| WITH PACKAGE simple_name IS NEW name LPAREN BOX RPAREN SEMICOLON
  2750 	| WITH PACKAGE simple_name IS NEW name SEMICOLON
  2751 	| use_clause
  2752 	;
  2753 
  2754 generic_discrim_part_opt ::=
  2755 	| discrim_part
  2756 	| LPAREN BOX RPAREN
  2757 	;
  2758 
  2759 subp_default ::=
  2760 	| IS name
  2761 	| IS BOX
  2762 	;
  2763 
  2764 generic_type_def ::= LPAREN BOX RPAREN
  2765 	| RANGE BOX
  2766 	| MOD BOX
  2767 	| DELTA BOX
  2768 	| DELTA BOX DIGITS BOX
  2769 	| DIGITS BOX
  2770 	| array_type
  2771 	| access_type
  2772 	| private_type_declaration
  2773 	| generic_derived_type
  2774 	;
  2775 
  2776 generic_derived_type ::= NEW subtype_indication
  2777 	| NEW subtype_indication WITH PRIVATE
  2778 	| ABSTRACT NEW subtype_indication WITH PRIVATE
  2779 	;
  2780 
  2781 generic_subp_inst ::=
  2782 subprogram_specification:subprog IS generic_inst
  2783 {:
  2784     RESULT = subprog;
  2785 :}
  2786 ;
  2787 
  2788 // 12.3
  2789 generic_package_instantiation ::=
  2790 PACKAGE compound_name IS generic_inst
  2791 ;
  2792 
  2793 generic_inst ::= NEW name
  2794 ;
  2795 
  2796 rep_spec ::= attrib_def
  2797 	| record_type_spec
  2798 	| address_spec
  2799 	;
  2800 
  2801 attrib_def ::= FOR subtype_mark USE expression SEMICOLON
  2802 	;
  2803 
  2804 record_type_spec ::= FOR subtype_mark USE RECORD align_opt comp_loc_s END RECORD SEMICOLON
  2805 	;
  2806 
  2807 align_opt ::=
  2808 	| AT MOD expression SEMICOLON
  2809 	;
  2810 
  2811 comp_loc_s ::=
  2812 	| comp_loc_s subtype_mark AT expression RANGE range SEMICOLON
  2813 	;
  2814 
  2815 address_spec ::= FOR subtype_mark USE AT expression SEMICOLON
  2816 	;
  2817 
  2818 ///////////////////////////////////////////////////////////////////////////////
  2819 // 13.8 Machine Code Insertions
  2820 //
  2821 code_statement ::=
  2822 qualified_expression:expr SEMICOLON:end
  2823 {:
  2824     RESULT = new CodeStatement (exprleft, endright, expr);
  2825 :}
  2826 ;