home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gnat-2.06-src.tgz / tar.out / fsf / gnat / ada / par-ch4.adb < prev    next >
Text File  |  1996-09-28  |  70KB  |  2,086 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT COMPILER COMPONENTS                         --
  4. --                                                                          --
  5. --                              P A R . C H 4                               --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.68 $                             --
  10. --                                                                          --
  11. --        Copyright (c) 1992,1993,1994,1995 NYU, All Rights Reserved        --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. --
  22. --                                                                          --
  23. ------------------------------------------------------------------------------
  24.  
  25. separate (Par)
  26. package body Ch4 is
  27.  
  28.    -----------------------
  29.    -- Local Subprograms --
  30.    -----------------------
  31.  
  32.    function P_Aggregate_Or_Paren_Expr                 return Node_Id;
  33.    function P_Allocator                               return Node_Id;
  34.    function P_Record_Or_Array_Component_Association   return Node_Id;
  35.    function P_Factor                                  return Node_Id;
  36.    function P_Primary                                 return Node_Id;
  37.    function P_Relation                                return Node_Id;
  38.    function P_Term                                    return Node_Id;
  39.  
  40.    function P_Binary_Adding_Operator                  return Node_Kind;
  41.    function P_Logical_Operator                        return Node_Kind;
  42.    function P_Multiplying_Operator                    return Node_Kind;
  43.    function P_Relational_Operator                     return Node_Kind;
  44.    function P_Unary_Adding_Operator                   return Node_Kind;
  45.  
  46.    function No_Right_Paren (Expr : Node_Id) return Node_Id;
  47.    --  Function to check for no right paren at end of expression, returns
  48.    --  its argument if no right paren, else flags the paren and returns Error.
  49.  
  50.    procedure Set_Op_Name (Node : Node_Id);
  51.    --  Procedure to set name field (Chars) in operator node
  52.  
  53.    --------------------
  54.    -- No_Right_Paren --
  55.    --------------------
  56.  
  57.    function No_Right_Paren (Expr : Node_Id) return Node_Id is
  58.    begin
  59.       if Token = Tok_Right_Paren then
  60.          Error_Msg_SC ("unexpected right parenthesis");
  61.          Resync_Expression;
  62.          return Error;
  63.       else
  64.          return Expr;
  65.       end if;
  66.    end No_Right_Paren;
  67.  
  68.    ------------------
  69.    -- Set_Op_Name --
  70.    ------------------
  71.  
  72.    procedure Set_Op_Name (Node : Node_Id) is
  73.       type Name_Of_Type is array (N_Op) of Name_Id;
  74.       Name_Of : Name_Of_Type := Name_Of_Type'(
  75.          N_Op_And                    => Name_Op_And,
  76.          N_Op_Or                     => Name_Op_Or,
  77.          N_Op_Xor                    => Name_Op_Xor,
  78.          N_Op_Eq                     => Name_Op_Eq,
  79.          N_Op_Ne                     => Name_Op_Ne,
  80.          N_Op_Lt                     => Name_Op_Lt,
  81.          N_Op_Le                     => Name_Op_Le,
  82.          N_Op_Gt                     => Name_Op_Gt,
  83.          N_Op_Ge                     => Name_Op_Ge,
  84.          N_Op_Add                    => Name_Op_Add,
  85.          N_Op_Subtract               => Name_Op_Subtract,
  86.          N_Op_Concat                 => Name_Op_Concat,
  87.          N_Op_Multiply               => Name_Op_Multiply,
  88.          N_Op_Divide                 => Name_Op_Divide,
  89.          N_Op_Mod                    => Name_Op_Mod,
  90.          N_Op_Rem                    => Name_Op_Rem,
  91.          N_Op_Expon                  => Name_Op_Expon,
  92.          N_Op_Plus                   => Name_Op_Add,
  93.          N_Op_Minus                  => Name_Op_Subtract,
  94.          N_Op_Abs                    => Name_Op_Abs,
  95.          N_Op_Not                    => Name_Op_Not,
  96.  
  97.          --  We don't really need these shift operators, since they never
  98.          --  appear as operators in the source, but the path of least
  99.          --  resistance is to put them in (the aggregate must be complete)
  100.  
  101.          N_Op_Rotate_Left            => Name_Rotate_Left,
  102.          N_Op_Rotate_Right           => Name_Rotate_Right,
  103.          N_Op_Shift_Left             => Name_Shift_Left,
  104.          N_Op_Shift_Right            => Name_Shift_Right,
  105.          N_Op_Shift_Right_Arithmetic => Name_Shift_Right_Arithmetic);
  106.  
  107.    begin
  108.       if Nkind (Node) in N_Op then
  109.          Set_Chars (Node, Name_Of (Nkind (Node)));
  110.       end if;
  111.    end Set_Op_Name;
  112.  
  113.    --------------------------
  114.    -- 4.1  Name (also 6.4) --
  115.    --------------------------
  116.  
  117.    --  NAME ::=
  118.    --    DIRECT_NAME        | EXPLICIT_DEREFERENCE
  119.    --  | INDEXED_COMPONENT  | SLICE
  120.    --  | SELECTED_COMPONENT | ATTRIBUTE
  121.    --  | TYPE_CONVERSION    | FUNCTION_CALL
  122.    --  | CHARACTER_LITERAL
  123.  
  124.    --  DIRECT_NAME ::= IDENTIFIER | OPERATOR_SYMBOL
  125.  
  126.    --  PREFIX ::= NAME | IMPLICIT_DEREFERENCE
  127.  
  128.    --  EXPLICIT_DEREFERENCE ::= NAME . all
  129.  
  130.    --  IMPLICIT_DEREFERENCE ::= NAME
  131.  
  132.    --  INDEXED_COMPONENT ::= PREFIX (EXPRESSION {, EXPRESSION})
  133.  
  134.    --  SLICE ::= PREFIX (DISCRETE_RANGE)
  135.  
  136.    --  SELECTED_COMPONENT ::= PREFIX . SELECTOR_NAME
  137.  
  138.    --  SELECTOR_NAME ::= IDENTIFIER | CHARACTER_LITERAL | OPERATOR_SYMBOL
  139.  
  140.    --  ATTRIBUTE_REFERENCE ::= PREFIX ' ATTRIBUTE_DESIGNATOR
  141.  
  142.    --  ATTRIBUTE_DESIGNATOR ::=
  143.    --    IDENTIFIER [(static_EXPRESSION)]
  144.    --  | access | delta | digits
  145.  
  146.    --  RANGE_ATTRIBUTE_REFERENCE ::= PREFIX ' RANGE_ATTRIBUTE_DESIGNATOR
  147.  
  148.    --  RANGE_ATTRIBUTE_DESIGNATOR ::= range [(static_EXPRESSION)]
  149.  
  150.    --  FUNCTION_CALL ::=
  151.    --    function_NAME
  152.    --  | function_PREFIX ACTUAL_PARAMETER_PART
  153.  
  154.    --  ACTUAL_PARAMETER_PART ::=
  155.    --    (PARAMETER_ASSOCIATION {,PARAMETER_ASSOCIATION})
  156.  
  157.    --  PARAMETER_ASSOCIATION ::=
  158.    --    [formal_parameter_SELECTOR_NAME =>] EXPLICIT_ACTUAL_PARAMETER
  159.  
  160.    --  EXPLICIT_ACTUAL_PARAMETER ::= EXPRESSION | variable_NAME
  161.  
  162.    --  Note: syntactically a procedure call looks just like a function call,
  163.    --  so this routine is in practice used to scan out procedure calls as well.
  164.  
  165.    --  On return, Expr_Form is set to either EF_Name or EF_Simple_Name
  166.  
  167.    --  Error recovery: can raise Error_Resync
  168.  
  169.    --  Note: if on return Token = Tok_Apostrophe, then the apostrophe must be
  170.    --  followed by either a left paren (qualified expression case), or by
  171.    --  range (range attribute case). All other uses of apostrophe (i.e. all
  172.    --  other attributes) are handled in this routine.
  173.  
  174.    --  Error recovery: can raise Error_Resync
  175.  
  176.    function P_Name return Node_Id is
  177.       Scan_State   : Saved_Scan_State;
  178.       Name_Node    : Node_Id;
  179.       Prefix_Node  : Node_Id;
  180.       Ident_Node   : Node_Id;
  181.       Expr_Node    : Node_Id;
  182.       Range_Node   : Node_Id;
  183.       Arg_Node     : Node_Id;
  184.       Arg_List     : List_Id;
  185.       Attr_Follows : Boolean;
  186.       Attr_Name    : Name_Id;
  187.  
  188.    begin
  189.       if Token not in Token_Class_Name then
  190.          Error_Msg_AP ("name expected");
  191.          raise Error_Resync;
  192.       end if;
  193.  
  194.       --  Loop through designators in qualified name
  195.  
  196.       Name_Node := Token_Node;
  197.  
  198.       loop
  199.          Scan; -- past designator
  200.          exit when Token /= Tok_Dot;
  201.          Scan; -- past dot
  202.  
  203.          --  If we do not have another designator after the dot, then join
  204.          --  the normal circuit to handle a dot extension (may be .all or
  205.          --  character literal case). Otherwise loop back to scan the next
  206.          --  designator.
  207.  
  208.          if Token not in Token_Class_Desig then
  209.             goto Scan_Name_Extension_Dot;
  210.          else
  211.             Prefix_Node := Name_Node;
  212.             Name_Node := New_Node (N_Selected_Component, Prev_Token_Ptr);
  213.             Set_Prefix (Name_Node, Prefix_Node);
  214.             Set_Selector_Name (Name_Node, Token_Node);
  215.          end if;
  216.       end loop;
  217.  
  218.       --  We have now scanned out a qualified designator. If the last token is
  219.       --  an operator symbol, then we certainly do not have the Snam case, so
  220.       --  we can just use the normal name extension check circuit
  221.  
  222.       if Prev_Token = Tok_Operator_Symbol then
  223.          goto Scan_Name_Extension;
  224.       end if;
  225.  
  226.       --  We have scanned out a qualified simple name, check for name extension
  227.       --  Note that we know there is no dot here at this stage, so the only
  228.       --  possible cases of name extension are apostrophe and left paren.
  229.  
  230.       if Token = Tok_Apostrophe then
  231.          Save_Scan_State (Scan_State); -- at apostrophe
  232.          Scan; -- past apostrophe
  233.  
  234.          --  If left paren, then this might be a qualified expression, but we
  235.          --  are only in the business of scanning out names, so return with
  236.          --  Token backed up to point to the apostrophe. The treatment for
  237.          --  the range attribute is similar (we do not consider x'range to
  238.          --  be a name in this grammar).
  239.  
  240.          if Token = Tok_Left_Paren or else Token = Tok_Range then
  241.             Restore_Scan_State (Scan_State); -- to apostrophe
  242.             Expr_Form := EF_Simple_Name;
  243.             return Name_Node;
  244.  
  245.          --  Otherwise we have the case of a name extended by an attribute
  246.  
  247.          else
  248.             goto Scan_Name_Extension_Apostrophe;
  249.          end if;
  250.  
  251.       --  Check case of qualified simple name extended by a left parenthesis
  252.  
  253.       elsif Token = Tok_Left_Paren then
  254.          Scan; -- past left paren
  255.          goto Scan_Name_Extension_Left_Paren;
  256.  
  257.       --  Otherwise the qualified simple name is not extended, so return
  258.  
  259.       else
  260.          Expr_Form := EF_Simple_Name;
  261.          return Name_Node;
  262.       end if;
  263.  
  264.       --  Loop scanning past name extensions. A label is used for control
  265.       --  transfer for this loop for ease of interfacing with the finite state
  266.       --  machine in the parenthesis scanning circuit, and also to allow for
  267.       --  passing in control to the appropriate point from the above code.
  268.  
  269.       <<Scan_Name_Extension>>
  270.  
  271.          --  Character literal used as name cannot be extended. Also this
  272.          --  cannot be a call, since the name for a call must be a designator.
  273.          --  Return in these cases, or if there is no name extension
  274.  
  275.          if Token not in Token_Class_Namext
  276.            or else Prev_Token = Tok_Char_Literal
  277.          then
  278.             Expr_Form := EF_Name;
  279.             return Name_Node;
  280.          end if;
  281.  
  282.       --  Merge here when we know there is a name extension
  283.  
  284.       <<Scan_Name_Extension_OK>>
  285.  
  286.          if Token = Tok_Left_Paren then
  287.             Scan; -- past left paren
  288.             goto Scan_Name_Extension_Left_Paren;
  289.  
  290.          elsif Token = Tok_Apostrophe then
  291.             Save_Scan_State (Scan_State); -- at apostrophe
  292.             Scan; -- past apostrophe
  293.             goto Scan_Name_Extension_Apostrophe;
  294.  
  295.          else -- Token = Tok_Dot
  296.             Scan; -- past dot
  297.             goto Scan_Name_Extension_Dot;
  298.          end if;
  299.  
  300.       --  Case of name extended by dot (selection), dot is already skipped
  301.  
  302.       <<Scan_Name_Extension_Dot>>
  303.  
  304.          --  Explicit dereference case
  305.  
  306.          if Token = Tok_All then
  307.             Prefix_Node := Name_Node;
  308.             Name_Node := New_Node (N_Explicit_Dereference, Token_Ptr);
  309.             Set_Prefix (Name_Node, Prefix_Node);
  310.             Scan; -- past ALL
  311.             goto Scan_Name_Extension;
  312.  
  313.          --  Selected component case
  314.  
  315.          elsif Token in Token_Class_Name then
  316.             Prefix_Node := Name_Node;
  317.             Name_Node := New_Node (N_Selected_Component, Prev_Token_Ptr);
  318.             Set_Prefix (Name_Node, Prefix_Node);
  319.             Set_Selector_Name (Name_Node, Token_Node);
  320.             Scan; -- past selector
  321.             goto Scan_Name_Extension;
  322.  
  323.          --  Reserved identifier as selector
  324.  
  325.          elsif Is_Reserved_Identifier then
  326.             Scan_Reserved_Identifier (Force_Msg => False);
  327.             Prefix_Node := Name_Node;
  328.             Name_Node := New_Node (N_Selected_Component, Prev_Token_Ptr);
  329.             Set_Prefix (Name_Node, Prefix_Node);
  330.             Set_Selector_Name (Name_Node, Token_Node);
  331.             Scan; -- past identifier used as selector
  332.             goto Scan_Name_Extension;
  333.  
  334.          --  Here if nothing legal after the dot
  335.  
  336.          else
  337.             Error_Msg_AP ("selector expected");
  338.             raise Error_Resync;
  339.          end if;
  340.  
  341.       --  Here for an apostrophe as name extension. The scan position at the
  342.       --  apostrophe has already been saved, and the apostrophe scanned out.
  343.  
  344.       <<Scan_Name_Extension_Apostrophe>>
  345.  
  346.          --  If range attribute after apostrophe, then return with Token
  347.          --  pointing to the apostrophe. Note that in this case the prefix
  348.          --  need not be a simple name (cases like A.all'range). Similarly
  349.          --  if there is a left paren after the apostrophe, then we also
  350.          --  return with Token pointing to the apostrophe (this is the
  351.          --  qualified expression case).
  352.  
  353.          if Token = Tok_Range or else Token = Tok_Left_Paren then
  354.             Restore_Scan_State (Scan_State); -- to apostrophe
  355.             Expr_Form := EF_Name;
  356.             return Name_Node;
  357.  
  358.          --  Here for cases where attribute designator is an identifier
  359.  
  360.          elsif Token = Tok_Identifier then
  361.             Attr_Name := Token_Name;
  362.  
  363.             if not Is_Attribute_Name (Attr_Name) then
  364.                Error_Msg_N ("unrecognized attribute&", Token_Node);
  365.             end if;
  366.  
  367.             if Style_Check then
  368.                Style.Check_Attribute_Name (False);
  369.             end if;
  370.  
  371.             Delete_Node (Token_Node);
  372.  
  373.          --  Here for case of attribute designator is not an identifier
  374.  
  375.          else
  376.             if Token = Tok_Delta then
  377.                Attr_Name := Name_Delta;
  378.             elsif Token = Tok_Digits then
  379.                Attr_Name := Name_Digits;
  380.             elsif Token = Tok_Access then
  381.                Attr_Name := Name_Access;
  382.             else
  383.                Error_Msg_AP ("attribute designator expected");
  384.                raise Error_Resync;
  385.             end if;
  386.  
  387.             if Style_Check then
  388.                Style.Check_Attribute_Name (True);
  389.             end if;
  390.          end if;
  391.  
  392.          --  We come here with an OK attribute scanned, and the corresponding
  393.          --  Attribute identifier node stored in Ident_Node.
  394.  
  395.          Prefix_Node := Name_Node;
  396.          Name_Node := New_Node (N_Attribute_Reference, Prev_Token_Ptr);
  397.          Scan; -- past attribute designator
  398.          Set_Prefix (Name_Node, Prefix_Node);
  399.          Set_Attribute_Name (Name_Node, Attr_Name);
  400.  
  401.          --  Scan attribute arguments/designator
  402.  
  403.          if Token = Tok_Left_Paren then
  404.             Set_Expressions (Name_Node, New_List);
  405.             Scan; -- past left paren
  406.  
  407.             loop
  408.                Append (P_Expression, Expressions (Name_Node));
  409.                exit when not Comma_Present;
  410.             end loop;
  411.  
  412.             T_Right_Paren;
  413.          end if;
  414.  
  415.          goto Scan_Name_Extension;
  416.  
  417.       --  Here for left parenthesis extending name (left paren skipped)
  418.  
  419.       <<Scan_Name_Extension_Left_Paren>>
  420.  
  421.          --  We now have to scan through a list of items, terminated by a
  422.          --  right parenthesis. The scan is handled by a finite state
  423.          --  machine. The possibilities are:
  424.  
  425.          --   (discrete_range)
  426.  
  427.          --      This is a slice. This case is handled in LP_State_Init.
  428.  
  429.          --   (expression, expression, ..)
  430.  
  431.          --      This is interpreted as an indexed component, i.e. as a
  432.          --      case of a name which can be extended in the normal manner.
  433.          --      This case is handled by LP_State_Name or LP_State_Expr.
  434.  
  435.          --   (..., identifier => expression , ...)
  436.  
  437.          --      If there is at least one occurence of identifier => (but
  438.          --      none of the other cases apply), then we have a call.
  439.  
  440.          --  LP_State_Init handles the scan of the initial argument
  441.  
  442.          <<LP_State_Init>>
  443.  
  444.             --  Test for Id => case
  445.  
  446.             if Token = Tok_Identifier then
  447.                Save_Scan_State (Scan_State); -- at Id
  448.                Scan; -- past Id
  449.  
  450.                if Token = Tok_Arrow then
  451.                   Restore_Scan_State (Scan_State); -- to Id
  452.                   Arg_List := New_List;
  453.                   goto LP_State_Call;
  454.  
  455.                else
  456.                   Restore_Scan_State (Scan_State); -- to Id
  457.                end if;
  458.             end if;
  459.  
  460.             --  Here we have an expression after all
  461.  
  462.             Expr_Node := P_Expression;
  463.  
  464.             --  Check cases of discrete range for a slice
  465.  
  466.             --  First possibility: Simple_expression .. Simple_expression
  467.  
  468.             if Token = Tok_Dot_Dot then
  469.                Check_Simple_Expression (Expr_Node);
  470.                Range_Node := New_Node (N_Range, Token_Ptr);
  471.                Set_Low_Bound (Range_Node, Expr_Node);
  472.                Scan; -- past ..
  473.                Expr_Node := P_Expression;
  474.                Check_Simple_Expression (Expr_Node);
  475.                Set_High_Bound (Range_Node, Expr_Node);
  476.  
  477.             --  Second possibility: Range attribute
  478.  
  479.             elsif Token = Tok_Apostrophe then
  480.                Range_Node := P_Range_Attribute_Reference (Expr_Node);
  481.  
  482.             --  Third possibility: Type_name range Range
  483.  
  484.             elsif Token = Tok_Range then
  485.                if Expr_Form /= EF_Simple_Name then
  486.                   Error_Msg_SC ("subtype mark must precede RANGE");
  487.                   raise Error_Resync;
  488.                end if;
  489.  
  490.                Range_Node := P_Subtype_Indication (Expr_Node);
  491.  
  492.             --  Otherwise we just have an expression. It is true that we might
  493.             --  have a subtype mark without a range constraint but this case
  494.             --  is syntactically indistinguishable from the expression case.
  495.  
  496.             else
  497.                Arg_List := New_List;
  498.                goto LP_State_Expr;
  499.             end if;
  500.  
  501.             --  Fall through here with unmistakable Discrete range scanned,
  502.             --  which means that we definitely have the case of a slice. The
  503.             --  Discrete range is in Range_Node.
  504.  
  505.             if Token = Tok_Comma then
  506.                Error_Msg_SC ("slice cannot have more than one dimension");
  507.                raise Error_Resync;
  508.  
  509.             elsif Token /= Tok_Right_Paren then
  510.                T_Right_Paren;
  511.                raise Error_Resync;
  512.  
  513.             else
  514.                Scan; -- past right paren
  515.                Prefix_Node := Name_Node;
  516.                Name_Node := New_Node (N_Slice, Sloc (Prefix_Node));
  517.                Set_Prefix (Name_Node, Prefix_Node);
  518.                Set_Discrete_Range (Name_Node, Range_Node);
  519.  
  520.                --  If we have a name extension, go scan it
  521.  
  522.                if Token in Token_Class_Namext then
  523.                   goto Scan_Name_Extension_OK;
  524.  
  525.                --  Otherwise return (a slice is a name, but is not a call)
  526.  
  527.                else
  528.                   Expr_Form := EF_Name;
  529.                   return Name_Node;
  530.                end if;
  531.             end if;
  532.  
  533.          --  In LP_State_Expr, we have scanned one or more expressions, and
  534.          --  so we have a call or an indexed component which is a name. On
  535.          --  entry we have the expression just scanned in Expr_Node and
  536.          --  Arg_List contains the list of expressions encountered so far
  537.  
  538.          <<LP_State_Expr>>
  539.             Append (Expr_Node, Arg_List);
  540.  
  541.             if not Comma_Present then
  542.                T_Right_Paren;
  543.                Prefix_Node := Name_Node;
  544.                Name_Node := New_Node (N_Indexed_Component, Sloc (Prefix_Node));
  545.                Set_Prefix (Name_Node, Prefix_Node);
  546.                Set_Expressions (Name_Node, Arg_List);
  547.                goto Scan_Name_Extension;
  548.             end if;
  549.  
  550.             --  Comma present (and scanned out), test for identifier => case
  551.             --  Test for identifer => case
  552.  
  553.             if Token = Tok_Identifier then
  554.                Save_Scan_State (Scan_State); -- at Id
  555.                Scan; -- past Id
  556.  
  557.                if Token = Tok_Arrow then
  558.                   Restore_Scan_State (Scan_State); -- to Id
  559.                   goto LP_State_Call;
  560.  
  561.                --  Otherwise it's just an expression after all, so backup
  562.  
  563.                else
  564.                   Restore_Scan_State (Scan_State); -- to Id
  565.                end if;
  566.             end if;
  567.  
  568.             --  Here we have an expression after all, so stay in this state
  569.  
  570.             Expr_Node := P_Expression;
  571.             goto LP_State_Expr;
  572.  
  573.          --  LP_State_Call corresponds to the situation in which at least
  574.          --  one instance of Id => Expression has been encountered, so we
  575.          --  know that we do not have a name, but rather a call. We enter
  576.          --  it with the scan pointer pointing to the next argument to scan,
  577.          --  and Arg_List containing the list of arguments scanned so far.
  578.  
  579.          <<LP_State_Call>>
  580.  
  581.             --  Test for case of Id => Expression (named parameter)
  582.  
  583.             if Token = Tok_Identifier then
  584.                Save_Scan_State (Scan_State); -- at Id
  585.                Ident_Node := Token_Node;
  586.                Scan; -- past Id
  587.  
  588.                if Token = Tok_Arrow then
  589.                   Arg_Node :=
  590.                     New_Node (N_Parameter_Association, Prev_Token_Ptr);
  591.                   Set_Selector_Name (Arg_Node, Ident_Node);
  592.                   Scan; -- past arrow
  593.                   Set_Explicit_Actual_Parameter (Arg_Node, P_Expression);
  594.                   Append (Arg_Node, Arg_List);
  595.  
  596.                   --  If a comma follows, go back and scan next entry
  597.  
  598.                   if Comma_Present then
  599.                      goto LP_State_Call;
  600.  
  601.                   --  Otherwise we have the end of a call
  602.  
  603.                   else
  604.                      Prefix_Node := Name_Node;
  605.                      Name_Node :=
  606.                        New_Node (N_Function_Call, Sloc (Prefix_Node));
  607.                      Set_Name (Name_Node, Prefix_Node);
  608.                      Set_Parameter_Associations (Name_Node, Arg_List);
  609.                      T_Right_Paren;
  610.  
  611.                      if Token in Token_Class_Namext then
  612.                         goto Scan_Name_Extension_OK;
  613.  
  614.                      --  This is a case of a call which cannot be a name
  615.  
  616.                      else
  617.                         Expr_Form := EF_Name;
  618.                         return Name_Node;
  619.                      end if;
  620.                   end if;
  621.  
  622.                --  Not named parameter: Id started an expression after all
  623.  
  624.                else
  625.                   Restore_Scan_State (Scan_State); -- to Id
  626.                end if;
  627.             end if;
  628.  
  629.             --  Here if entry did not start with Id => which means that it
  630.             --  is a positional parameter, which is not allowed, since we
  631.             --  have seen at least one named parameter already.
  632.  
  633.             Error_Msg_SC
  634.                ("positional parameter association " &
  635.                  "not allowed after named one");
  636.  
  637.             Expr_Node := P_Expression;
  638.  
  639.             --  We go back to scanning out expressions, so that we do not get
  640.             --  multiple error messages when several positional parameters
  641.             --  follow a named parameter.
  642.  
  643.             goto LP_State_Expr;
  644.  
  645.          --  End of treatment for name extensions starting with left paren
  646.  
  647.       --  End of loop through name extensions
  648.  
  649.    end P_Name;
  650.  
  651.    --  This function parses a restricted form of Names which are either
  652.    --  designators, or designators preceded by a sequence of prefixes
  653.    --  that are direct names.
  654.  
  655.    --  Error recovery: cannot raise Error_Resync
  656.  
  657.    function P_Function_Name return Node_Id is
  658.       Designator_Node : Node_Id;
  659.       Prefix_Node     : Node_Id;
  660.       Selector_Node   : Node_Id;
  661.       Dot_Sloc        : Source_Ptr;
  662.  
  663.    begin
  664.       --  Prefix node is set to the gathered prefix so far, Empty means that
  665.       --  no prefix has been scanned. This allows us to build up the result
  666.       --  in the required right recursive manner.
  667.  
  668.       Prefix_Node := Empty;
  669.  
  670.       --  Loop through prefixes
  671.  
  672.       loop
  673.          Designator_Node := Token_Node;
  674.  
  675.          if Token not in Token_Class_Desig then
  676.             return P_Identifier; -- let P_Identifier issue the error message
  677.  
  678.          else -- Token in Token_Class_Desig
  679.             Scan; -- past designator
  680.             exit when Token /= Tok_Dot;
  681.          end if;
  682.  
  683.          --  Here at a dot, with token just before it in Designator_Node
  684.  
  685.          if No (Prefix_Node) then
  686.             Prefix_Node := Designator_Node;
  687.          else
  688.             Selector_Node := New_Node (N_Selected_Component, Dot_Sloc);
  689.             Set_Prefix (Selector_Node, Prefix_Node);
  690.             Set_Selector_Name (Selector_Node, Designator_Node);
  691.             Prefix_Node := Selector_Node;
  692.          end if;
  693.  
  694.          Dot_Sloc := Token_Ptr;
  695.          Scan; -- past dot
  696.       end loop;
  697.  
  698.       --  Fall out of the loop having just scanned a designator
  699.  
  700.       if No (Prefix_Node) then
  701.          return Designator_Node;
  702.       else
  703.          Selector_Node := New_Node (N_Selected_Component, Dot_Sloc);
  704.          Set_Prefix (Selector_Node, Prefix_Node);
  705.          Set_Selector_Name (Selector_Node, Designator_Node);
  706.          return Selector_Node;
  707.       end if;
  708.  
  709.    exception
  710.       when Error_Resync =>
  711.          return Error;
  712.  
  713.    end P_Function_Name;
  714.  
  715.    --  This function parses a restricted form of Names which are either
  716.    --  identifiers, or identifiers preceded by a sequence of prefixes
  717.    --  that are direct names.
  718.  
  719.    --  Error recovery: cannot raise Error_Resync
  720.  
  721.    function P_Qualified_Simple_Name return Node_Id is
  722.       Designator_Node : Node_Id;
  723.       Prefix_Node     : Node_Id;
  724.       Selector_Node   : Node_Id;
  725.       Dot_Sloc        : Source_Ptr;
  726.  
  727.    begin
  728.       --  Prefix node is set to the gathered prefix so far, Empty means that
  729.       --  no prefix has been scanned. This allows us to build up the result
  730.       --  in the required right recursive manner.
  731.  
  732.       Prefix_Node := Empty;
  733.  
  734.       --  Loop through prefixes
  735.  
  736.       loop
  737.          Designator_Node := Token_Node;
  738.  
  739.          if Token = Tok_Identifier then
  740.             Scan; -- past identifier
  741.             exit when Token /= Tok_Dot;
  742.  
  743.          elsif Token not in Token_Class_Desig then
  744.             return P_Identifier; -- let P_Identifier issue the error message
  745.  
  746.          else
  747.             Scan; -- past designator
  748.  
  749.             if Token /= Tok_Dot then
  750.                Error_Msg_SP ("identifier expected");
  751.                return Error;
  752.             end if;
  753.          end if;
  754.  
  755.          --  Here at a dot, with token just before it in Designator_Node
  756.  
  757.          if No (Prefix_Node) then
  758.             Prefix_Node := Designator_Node;
  759.          else
  760.             Selector_Node := New_Node (N_Selected_Component, Dot_Sloc);
  761.             Set_Prefix (Selector_Node, Prefix_Node);
  762.             Set_Selector_Name (Selector_Node, Designator_Node);
  763.             Prefix_Node := Selector_Node;
  764.          end if;
  765.  
  766.          Dot_Sloc := Token_Ptr;
  767.          Scan; -- past dot
  768.       end loop;
  769.  
  770.       --  Fall out of the loop having just scanned an identifier
  771.  
  772.       if No (Prefix_Node) then
  773.          return Designator_Node;
  774.       else
  775.          Selector_Node := New_Node (N_Selected_Component, Dot_Sloc);
  776.          Set_Prefix (Selector_Node, Prefix_Node);
  777.          Set_Selector_Name (Selector_Node, Designator_Node);
  778.          return Selector_Node;
  779.       end if;
  780.  
  781.    exception
  782.       when Error_Resync =>
  783.          return Error;
  784.  
  785.    end P_Qualified_Simple_Name;
  786.  
  787.    --  This procedure differs from P_Qualified_Simple_Name only in that it
  788.    --  raises Error_Resync if any error is encountered. It only returns after
  789.    --  scanning a valid qualified simple name.
  790.  
  791.    --  Error recovery: can raise Error_Resync
  792.  
  793.    function P_Qualified_Simple_Name_Resync return Node_Id is
  794.       Designator_Node : Node_Id;
  795.       Prefix_Node     : Node_Id;
  796.       Selector_Node   : Node_Id;
  797.       Dot_Sloc        : Source_Ptr;
  798.  
  799.    begin
  800.       Prefix_Node := Empty;
  801.  
  802.       --  Loop through prefixes
  803.  
  804.       loop
  805.          Designator_Node := Token_Node;
  806.  
  807.          if Token = Tok_Identifier then
  808.             Scan; -- past identifier
  809.             exit when Token /= Tok_Dot;
  810.  
  811.          elsif Token not in Token_Class_Desig then
  812.             Discard_Junk_Node (P_Identifier); -- to issue the error message
  813.             raise Error_Resync;
  814.  
  815.          else
  816.             Scan; -- past designator
  817.  
  818.             if Token /= Tok_Dot then
  819.                Error_Msg_SP ("identifier expected");
  820.                raise Error_Resync;
  821.             end if;
  822.          end if;
  823.  
  824.          --  Here at a dot, with token just before it in Designator_Node
  825.  
  826.          if No (Prefix_Node) then
  827.             Prefix_Node := Designator_Node;
  828.          else
  829.             Selector_Node := New_Node (N_Selected_Component, Dot_Sloc);
  830.             Set_Prefix (Selector_Node, Prefix_Node);
  831.             Set_Selector_Name (Selector_Node, Designator_Node);
  832.             Prefix_Node := Selector_Node;
  833.          end if;
  834.  
  835.          Dot_Sloc := Token_Ptr;
  836.          Scan; -- past period
  837.       end loop;
  838.  
  839.       --  Fall out of the loop having just scanned an identifier
  840.  
  841.       if No (Prefix_Node) then
  842.          return Designator_Node;
  843.       else
  844.          Selector_Node := New_Node (N_Selected_Component, Dot_Sloc);
  845.          Set_Prefix (Selector_Node, Prefix_Node);
  846.          Set_Selector_Name (Selector_Node, Designator_Node);
  847.          return Selector_Node;
  848.       end if;
  849.  
  850.    end P_Qualified_Simple_Name_Resync;
  851.  
  852.    ----------------------
  853.    -- 4.1  Direct_Name --
  854.    ----------------------
  855.  
  856.    --  Parsed by P_Name and other functions in section 4.1
  857.  
  858.    -----------------
  859.    -- 4.1  Prefix --
  860.    -----------------
  861.  
  862.    --  Parsed by P_Name (4.1)
  863.  
  864.    -------------------------------
  865.    -- 4.1  Explicit Dereference --
  866.    -------------------------------
  867.  
  868.    --  Parsed by P_Name (4.1)
  869.  
  870.    -------------------------------
  871.    -- 4.1  Implicit_Dereference --
  872.    -------------------------------
  873.  
  874.    --  Parsed by P_Name (4.1)
  875.  
  876.    ----------------------------
  877.    -- 4.1  Indexed Component --
  878.    ----------------------------
  879.  
  880.    --  Parsed by P_Name (4.1)
  881.  
  882.    ----------------
  883.    -- 4.1  Slice --
  884.    ----------------
  885.  
  886.    --  Parsed by P_Name (4.1)
  887.  
  888.    -----------------------------
  889.    -- 4.1  Selected_Component --
  890.    -----------------------------
  891.  
  892.    --  Parsed by P_Name (4.1)
  893.  
  894.    ------------------------
  895.    -- 4.1  Selector Name --
  896.    ------------------------
  897.  
  898.    --  Parsed by P_Name (4.1)
  899.  
  900.    ------------------------------
  901.    -- 4.1  Attribute Reference --
  902.    ------------------------------
  903.  
  904.    --  Parsed by P_Name (4.1)
  905.  
  906.    -------------------------------
  907.    -- 4.1  Attribute Designator --
  908.    -------------------------------
  909.  
  910.    --  Parsed by P_Name (4.1)
  911.  
  912.    --------------------------------------
  913.    -- 4.1.4  Range Attribute Reference --
  914.    --------------------------------------
  915.  
  916.    --  RANGE_ATTRIBUTE_REFERENCE ::= PREFIX ' RANGE_ATTRIBUTE_DESIGNATOR
  917.  
  918.    --  RANGE_ATTRIBUTE_DESIGNATOR ::= range [(static_EXPRESSION)]
  919.  
  920.    --  In the grammar, a RANGE attribute is simply a name, but its use is
  921.    --  highly restricted, so in the parser, we do not regard it as a name.
  922.    --  Instead, P_Name returns without scanning the 'RANGE part of the
  923.    --  attribute, and the caller uses the following function to construct
  924.    --  a range attribute in places where it is appropriate.
  925.  
  926.    --  Note that RANGE here is treated essentially as an identifier,
  927.    --  rather than a reserved word.
  928.  
  929.    --  The caller has parsed the prefix, i.e. a name, and Token points to
  930.    --  the apostrophe. The token after the apostrophe is known to be RANGE
  931.    --  at this point. The prefix node becomes the prefix of the attribute.
  932.  
  933.    --  Error_Recovery: Cannot raise Error_Resync
  934.  
  935.    function P_Range_Attribute_Reference
  936.      (Prefix_Node : Node_Id)
  937.       return        Node_Id
  938.    is
  939.       Attr_Node  : Node_Id;
  940.  
  941.    begin
  942.       Attr_Node := New_Node (N_Attribute_Reference, Token_Ptr);
  943.       Set_Prefix (Attr_Node, Prefix_Node);
  944.       Scan; -- past apostrophe
  945.  
  946.       if Style_Check then
  947.          Style.Check_Attribute_Name (True);
  948.       end if;
  949.  
  950.       Set_Attribute_Name (Attr_Node, Name_Range);
  951.       Scan; -- past RANGE
  952.  
  953.       if Token = Tok_Left_Paren then
  954.          Scan; -- past left paren
  955.          Set_Expressions (Attr_Node, New_List (P_Expression));
  956.          T_Right_Paren;
  957.       end if;
  958.  
  959.       return Attr_Node;
  960.    end P_Range_Attribute_Reference;
  961.  
  962.    ---------------------------------------
  963.    -- 4.1.4  Range Attribute Designator --
  964.    ---------------------------------------
  965.  
  966.    --  Parsed by P_Range_Attribute_Reference (4.1.4)
  967.  
  968.    --------------------
  969.    -- 4.3  Aggregate --
  970.    --------------------
  971.  
  972.    --  AGGREGATE ::= RECORD_AGGREGATE | EXTENSION_AGGREGATE | ARRAY_AGGREGATE
  973.  
  974.    --  Parsed by P_Aggregate_Or_Paren_Expr (4.3), except in the case where
  975.    --  an aggregate is known to be required (code statement, extension
  976.    --  aggregate), in which cases this routine performs the necessary check
  977.    --  that we have an aggregate rather than a parenthesized expression
  978.  
  979.    --  Error recovery: can raise Error_Resync
  980.  
  981.    function P_Aggregate return Node_Id is
  982.       Aggr_Sloc : constant Source_Ptr := Token_Ptr;
  983.       Aggr_Node : constant Node_Id    := P_Aggregate_Or_Paren_Expr;
  984.       Expr_Node : Node_Id;
  985.  
  986.    begin
  987.       if Nkind (Aggr_Node) /= N_Aggregate
  988.            and then
  989.          Nkind (Aggr_Node) /= N_Extension_Aggregate
  990.       then
  991.          Error_Msg
  992.            ("aggregate may not have single positional component", Aggr_Sloc);
  993.          return Error;
  994.       else
  995.          return Aggr_Node;
  996.       end if;
  997.    end P_Aggregate;
  998.  
  999.    -------------------------------------------------
  1000.    -- 4.3  Aggregate or Parenthesized Expresssion --
  1001.    -------------------------------------------------
  1002.  
  1003.    --  This procedure parses out either an aggregate or a parenthesized
  1004.    --  expression (these two constructs are closely related, since a
  1005.    --  parenthesized expression looks like an aggregate with a single
  1006.    --  positional component).
  1007.  
  1008.    --  AGGREGATE ::=
  1009.    --    RECORD_AGGREGATE | EXTENSION_AGGREGATE | ARRAY_AGGREGATE
  1010.  
  1011.    --  RECORD_AGGREGATE ::= (RECORD_COMPONENT_ASSOCIATION_LIST)
  1012.  
  1013.    --  RECORD_COMPONENT_ASSOCIATION_LIST ::=
  1014.    --     RECORD_COMPONENT_ASSOCIATION {, RECORD_COMPONENT_ASSOCIATION}
  1015.    --   | null record
  1016.  
  1017.    --  RECORD_COMPONENT_ASSOCIATION ::=
  1018.    --    [COMPONENT_CHOICE_LIST =>] EXPRESSION
  1019.  
  1020.    --  COMPONENT_CHOICE_LIST ::=
  1021.    --    component_SELECTOR_NAME {| component_SELECTOR_NAME}
  1022.    --  | others
  1023.  
  1024.    --  EXTENSION_AGGREGATE ::=
  1025.    --    (ANCESTOR_PART with RECORD_COMPONENT_ASSOCIATION_LIST)
  1026.  
  1027.    --  ANCESTOR_PART ::= EXPRESSION | SUBTYPE_MARK
  1028.  
  1029.    --  ARRAY_AGGREGATE ::=
  1030.    --    POSITIONAL_ARRAY_AGGREGATE | NAMED_ARRAY_AGGREGATE
  1031.  
  1032.    --  POSITIONAL_ARRAY_AGGREGATE ::=
  1033.    --    (EXPRESSION, EXPRESSION {, EXPRESSION})
  1034.    --  | (EXPRESSION {, EXPRESSION}, others => EXPRESSION)
  1035.  
  1036.    --  NAMED_ARRAY_AGGREGATE ::=
  1037.    --    (ARRAY_COMPONENT_ASSOCIATION {, ARRAY_COMPONENT_ASSOCIATION})
  1038.  
  1039.    --  PRIMARY ::= (EXPRESSION);
  1040.  
  1041.    --  Error recovery: can raise Error_Resync
  1042.  
  1043.    function P_Aggregate_Or_Paren_Expr return Node_Id is
  1044.       Aggregate_Node : Node_Id;
  1045.       Expr_List      : List_Id;
  1046.       Assoc_List     : List_Id;
  1047.       Expr_Node      : Node_Id;
  1048.       Pexpr_Node     : Node_Id;
  1049.       Assoc_Node     : Node_Id;
  1050.       Lparen_Sloc    : Source_Ptr;
  1051.       Scan_State     : Saved_Scan_State;
  1052.  
  1053.    begin
  1054.       Lparen_Sloc := Token_Ptr;
  1055.       T_Left_Paren;
  1056.  
  1057.       --  Note: the mechanism used here of rescanning the initial expression
  1058.       --  is distinctly unpleasant, but it saves a lot of fiddling in scanning
  1059.       --  out the discrete choice list.
  1060.  
  1061.       --  Deal with expression and extension aggregate cases first
  1062.  
  1063.       if Token /= Tok_Others then
  1064.          Save_Scan_State (Scan_State); -- at start of expression
  1065.  
  1066.          --  Deal with (NULL RECORD) case
  1067.  
  1068.          if Token = Tok_Null then
  1069.             Scan; -- past NULL
  1070.  
  1071.             if Token = Tok_Record then
  1072.                Aggregate_Node := New_Node (N_Aggregate, Lparen_Sloc);
  1073.                Set_Null_Record_Present (Aggregate_Node, True);
  1074.                Scan; -- past RECORD
  1075.                T_Right_Paren;
  1076.                return Aggregate_Node;
  1077.             else
  1078.                Restore_Scan_State (Scan_State); -- to NULL that must be expr
  1079.             end if;
  1080.          end if;
  1081.  
  1082.          Expr_Node := P_Expression;
  1083.  
  1084.          --  Extension aggregate case
  1085.  
  1086.          if Token = Tok_With then
  1087.             if Ada_83 then
  1088.                Error_Msg_SC ("(Ada 83) extension aggregate not allowed");
  1089.             end if;
  1090.  
  1091.             Note_Feature (Extension_Aggregates, Token_Ptr);
  1092.             Aggregate_Node := New_Node (N_Extension_Aggregate, Lparen_Sloc);
  1093.             Set_Ancestor_Part (Aggregate_Node, Expr_Node);
  1094.             Scan; -- past WITH
  1095.  
  1096.             --  Deal with WITH NULL RECORD case
  1097.  
  1098.             if Token = Tok_Null then
  1099.                Save_Scan_State (Scan_State); -- at NULL
  1100.                Scan; -- past NULL
  1101.  
  1102.                if Token = Tok_Record then
  1103.                   Scan; -- past RECORD
  1104.                   Set_Null_Record_Present (Aggregate_Node, True);
  1105.                   T_Right_Paren;
  1106.                   return Aggregate_Node;
  1107.  
  1108.                else
  1109.                   Restore_Scan_State (Scan_State); -- to NULL that must be expr
  1110.                end if;
  1111.             end if;
  1112.  
  1113.             if Token /= Tok_Others then
  1114.                Save_Scan_State (Scan_State);
  1115.                Expr_Node := P_Expression;
  1116.             end if;
  1117.  
  1118.          --  Expression case
  1119.  
  1120.          elsif Token = Tok_Right_Paren or else Token in Token_Class_Eterm then
  1121.  
  1122.             --  Bump paren count of expression, note that if the paren count
  1123.             --  is already at the maximum, then we leave it alone. This will
  1124.             --  cause some failures in pathalogical conformance tests, which
  1125.             --  we do not shed a tear over!
  1126.  
  1127.             if Expr_Node /= Error then
  1128.                if Paren_Count (Expr_Node) /= Paren_Count_Type'Last then
  1129.                   Set_Paren_Count (Expr_Node, Paren_Count (Expr_Node) + 1);
  1130.                end if;
  1131.             end if;
  1132.  
  1133.             T_Right_Paren; -- past right paren (error message if none)
  1134.             return Expr_Node;
  1135.  
  1136.          --  Normal aggregate case
  1137.  
  1138.          else
  1139.             Aggregate_Node := New_Node (N_Aggregate, Lparen_Sloc);
  1140.          end if;
  1141.  
  1142.       --  Others case
  1143.  
  1144.       else
  1145.          Aggregate_Node := New_Node (N_Aggregate, Lparen_Sloc);
  1146.          Expr_Node := Empty;
  1147.       end if;
  1148.  
  1149.       --  Prepare to scan list of component associations
  1150.  
  1151.       Expr_List  := No_List; -- don't set yet, maybe all named entries
  1152.       Assoc_List := No_List; -- don't set yet, maybe all positional entries
  1153.  
  1154.       --  This loop scans through component associations. On entry to the
  1155.       --  loop, an expression has been scanned at the start of the current
  1156.       --  association unless initial token was OTHERS, in which case
  1157.       --  Expr_Node is set to Empty.
  1158.  
  1159.       loop
  1160.          --  Deal with others association first. This is a named association
  1161.  
  1162.          if No (Expr_Node) then
  1163.             if No (Assoc_List) then
  1164.                Assoc_List := New_List;
  1165.             end if;
  1166.  
  1167.             Append (P_Record_Or_Array_Component_Association, Assoc_List);
  1168.  
  1169.          --  Improper use of WITH
  1170.  
  1171.          elsif Token = Tok_With then
  1172.             Error_Msg_SC ("WITH must be preceded by single expression in " &
  1173.                              "extension aggregate");
  1174.             raise Error_Resync;
  1175.  
  1176.          --  Assume positional case if comma, right paren, or literal or
  1177.          --  identifier or OTHERS follows (the latter cases are missing
  1178.          --  comma cases)
  1179.  
  1180.          elsif Token = Tok_Comma
  1181.            or else Token = Tok_Right_Paren
  1182.            or else Token = Tok_Others
  1183.            or else Token in Token_Class_Lit_Or_Name
  1184.          then
  1185.             if Present (Assoc_List) then
  1186.                Error_Msg_BC
  1187.                   ("""=>"" expected (positional association cannot follow " &
  1188.                    "named association");
  1189.             end if;
  1190.  
  1191.             if No (Expr_List) then
  1192.                Expr_List := New_List;
  1193.             end if;
  1194.  
  1195.             Append (Expr_Node, Expr_List);
  1196.  
  1197.          --  Anything else is assumed to be a named association
  1198.  
  1199.          else
  1200.             Restore_Scan_State (Scan_State); -- to start of expression
  1201.  
  1202.             if No (Assoc_List) then
  1203.                Assoc_List := New_List;
  1204.             end if;
  1205.  
  1206.             Append (P_Record_Or_Array_Component_Association, Assoc_List);
  1207.  
  1208.          --  Here we must have the positional case
  1209.  
  1210.          end if;
  1211.  
  1212.          exit when not Comma_Present;
  1213.  
  1214.          --  If we are at an expression terminator, something is seriously
  1215.          --  wrong, so let's get out now, before we start eating up stuff
  1216.          --  that doesn't belong to us!
  1217.  
  1218.          if Token in Token_Class_Eterm then
  1219.             Error_Msg_AP ("expecting expression or component association");
  1220.             exit;
  1221.          end if;
  1222.  
  1223.          --  Otherwise initiate for reentry to top of loop by scanning an
  1224.          --  initial expression, unless the first token is OTHERS.
  1225.  
  1226.          if Token = Tok_Others then
  1227.             Expr_Node := Empty;
  1228.          else
  1229.             Save_Scan_State (Scan_State); -- at start of expression
  1230.             Expr_Node := P_Expression;
  1231.          end if;
  1232.       end loop;
  1233.  
  1234.       --  All component associations (positional and named) have been scanned
  1235.  
  1236.       T_Right_Paren;
  1237.       Set_Expressions (Aggregate_Node, Expr_List);
  1238.       Set_Component_Associations (Aggregate_Node, Assoc_List);
  1239.       return Aggregate_Node;
  1240.    end P_Aggregate_Or_Paren_Expr;
  1241.  
  1242.    ------------------------------------------------
  1243.    -- 4.3  Record or Array Component Association --
  1244.    ------------------------------------------------
  1245.  
  1246.    --  RECORD_COMPONENT_ASSOCIATION ::=
  1247.    --    [COMPONENT_CHOICE_LIST =>] EXPRESSION
  1248.  
  1249.    --  COMPONENT_CHOICE_LIST =>
  1250.    --    component_SELECTOR_NAME {| component_SELECTOR_NAME}
  1251.    --  | others
  1252.  
  1253.    --  ARRAY_COMPONENT_ASSOCIATION ::=
  1254.    --    DISCRETE_CHOICE_LIST => EXPRESSION
  1255.  
  1256.    --  Note: this routine only handles the named cases, including others.
  1257.    --  Cases where the component choice list is not present have already
  1258.    --  been handled directly.
  1259.  
  1260.    --  Error recovery: can raise Error_Resync
  1261.  
  1262.    function P_Record_Or_Array_Component_Association return Node_Id is
  1263.       Assoc_Node : Node_Id;
  1264.  
  1265.    begin
  1266.       Assoc_Node := New_Node (N_Component_Association, Token_Ptr);
  1267.       Set_Choices (Assoc_Node, P_Discrete_Choice_List);
  1268.       Set_Sloc (Assoc_Node, Token_Ptr);
  1269.       TF_Arrow;
  1270.       Set_Expression (Assoc_Node, P_Expression);
  1271.       return Assoc_Node;
  1272.    end P_Record_Or_Array_Component_Association;
  1273.  
  1274.    -----------------------------
  1275.    -- 4.3.1  Record Aggregate --
  1276.    -----------------------------
  1277.  
  1278.    --  Case of enumeration aggregate is parsed by P_Aggregate (4.3)
  1279.    --  All other cases are parsed by P_Aggregate_Or_Paren_Expr (4.3)
  1280.  
  1281.    ----------------------------------------------
  1282.    -- 4.3.1  Record Component Association List --
  1283.    ----------------------------------------------
  1284.  
  1285.    --  Parsed by P_Aggregate_Or_Paren_Expr (4.3)
  1286.  
  1287.    ----------------------------------
  1288.    -- 4.3.1  Component Choice List --
  1289.    ----------------------------------
  1290.  
  1291.    --  Parsed by P_Aggregate_Or_Paren_Expr (4.3)
  1292.  
  1293.    --------------------------------
  1294.    -- 4.3.1  Extension Aggregate --
  1295.    --------------------------------
  1296.  
  1297.    --  Parsed by P_Aggregate_Or_Paren_Expr (4.3)
  1298.  
  1299.    --------------------------
  1300.    -- 4.3.1  Ancestor Part --
  1301.    --------------------------
  1302.  
  1303.    --  Parsed by P_Aggregate_Or_Paren_Expr (4.3)
  1304.  
  1305.    ----------------------------
  1306.    -- 4.3.1  Array Aggregate --
  1307.    ----------------------------
  1308.  
  1309.    --  Parsed by P_Aggregate_Or_Paren_Expr (4.3)
  1310.  
  1311.    ---------------------------------------
  1312.    -- 4.3.1  Positional Array Aggregate --
  1313.    ---------------------------------------
  1314.  
  1315.    --  Parsed by P_Aggregate_Or_Paren_Expr (4.3)
  1316.  
  1317.    ----------------------------------
  1318.    -- 4.3.1  Named Array Aggregate --
  1319.    ----------------------------------
  1320.  
  1321.    --  Parsed by P_Aggregate_Or_Paren_Expr (4.3)
  1322.  
  1323.    ----------------------------------------
  1324.    -- 4.3.1  Array Component Association --
  1325.    ----------------------------------------
  1326.  
  1327.    --  Parsed by P_Aggregate_Or_Paren_Expr (4.3)
  1328.  
  1329.    ---------------------
  1330.    -- 4.4  Expression --
  1331.    ---------------------
  1332.  
  1333.    --  EXPRESSION ::=
  1334.    --    RELATION {and RELATION} | RELATION {and then RELATION}
  1335.    --  | RELATION {or RELATION}  | RELATION {or else RELATION}
  1336.    --  | RELATION {xor RELATION}
  1337.  
  1338.    --  On return, Expr_Form indicates the categorization of the expression
  1339.  
  1340.    --  Note: if Token = Tok_Apostrophe on return, then Expr_Form is set to
  1341.    --  EF_Simple_Name and the following token is RANGE (range attribute case).
  1342.  
  1343.    --  Error recovery: cannot raise Error_Resync
  1344.  
  1345.    function P_Expression return Node_Id is
  1346.       Logical_Op      : Node_Kind;
  1347.       Prev_Logical_Op : Node_Kind;
  1348.       Op_Location     : Source_Ptr;
  1349.       Node1           : Node_Id;
  1350.       Node2           : Node_Id;
  1351.  
  1352.    begin
  1353.       Node1 := P_Relation;
  1354.  
  1355.       if Token in Token_Class_Logop then
  1356.          Prev_Logical_Op := N_Empty;
  1357.  
  1358.          loop
  1359.             Op_Location := Token_Ptr;
  1360.             Logical_Op := P_Logical_Operator;
  1361.  
  1362.             if Prev_Logical_Op /= N_Empty and then
  1363.                Logical_Op /= Prev_Logical_Op
  1364.             then
  1365.                Error_Msg
  1366.                  ("mixed logical operators in expression", Op_Location);
  1367.                Prev_Logical_Op := N_Empty;
  1368.             else
  1369.                Prev_Logical_Op := Logical_Op;
  1370.             end if;
  1371.  
  1372.             Node2 := Node1;
  1373.             Node1 := New_Node (Logical_Op, Op_Location);
  1374.             Set_Left_Opnd (Node1, Node2);
  1375.             Set_Right_Opnd (Node1, P_Relation);
  1376.             Set_Op_Name (Node1);
  1377.             exit when Token not in Token_Class_Logop;
  1378.          end loop;
  1379.  
  1380.          Expr_Form := EF_Non_Simple;
  1381.       end if;
  1382.  
  1383.       return Node1;
  1384.    end P_Expression;
  1385.  
  1386.    --  This function is identical to the normal P_Expression, except that it
  1387.    --  checks that the expression scan did not stop on a right paren. It is
  1388.    --  called in all contexts where a right parenthesis cannot legitimately
  1389.    --  follow an expression.
  1390.  
  1391.    function P_Expression_No_Right_Paren return Node_Id is
  1392.    begin
  1393.       return No_Right_Paren (P_Expression);
  1394.    end P_Expression_No_Right_Paren;
  1395.  
  1396.    -------------------
  1397.    -- 4.4  Relation --
  1398.    -------------------
  1399.  
  1400.    --  RELATION ::=
  1401.    --    SIMPLE_EXPRESSION [RELATIONAL_OPERATOR SIMPLE_EXPRESSION]
  1402.    --  | SIMPLE_EXPRESSION [not] in RANGE
  1403.    --  | SIMPLE_EXPRESSION [not] in SUBTYPE_MARK
  1404.  
  1405.    --  On return, Expr_Form indicates the categorization of the expression
  1406.  
  1407.    --  Note: if Token = Tok_Apostrophe on return, then Expr_Form is set to
  1408.    --  EF_Simple_Name and the following token is RANGE (range attribute case).
  1409.  
  1410.    --  Error recovery: cannot raise Error_Resync. If an error occurs within an
  1411.    --  expression, then tokens are scanned until either a non-expression token,
  1412.    --  a right paren (not matched by a left paren) or a comma, is encountered.
  1413.  
  1414.    function P_Relation return Node_Id is
  1415.       Node1, Node2 : Node_Id;
  1416.       Optok        : Source_Ptr;
  1417.  
  1418.    begin
  1419.       Node1 := P_Simple_Expression;
  1420.  
  1421.       if Token not in Token_Class_Relop then
  1422.          return Node1;
  1423.  
  1424.       else
  1425.          --  Here we have a relational operator following. If so then scan it
  1426.          --  out. Note that the assignment symbol := is treated as a relational
  1427.          --  operator to improve the error recovery when it is misused for =.
  1428.          --  P_Relational_Operator also parses the IN and NOT IN operations.
  1429.  
  1430.          Optok := Token_Ptr;
  1431.          Node2 := New_Node (P_Relational_Operator, Optok);
  1432.          Set_Left_Opnd (Node2, Node1);
  1433.          Set_Op_Name (Node2);
  1434.  
  1435.          --  Case of IN or NOT IN
  1436.  
  1437.          if Prev_Token = Tok_In then
  1438.             Set_Right_Opnd (Node2, P_Range_Or_Subtype_Mark);
  1439.  
  1440.          --  Case of relational operator (= /= < <= > >=)
  1441.  
  1442.          else
  1443.             Set_Right_Opnd (Node2, P_Simple_Expression);
  1444.          end if;
  1445.  
  1446.          Expr_Form := EF_Non_Simple;
  1447.  
  1448.          if Token in Token_Class_Relop then
  1449.             Error_Msg_SC ("unexpected relational operator");
  1450.             raise Error_Resync;
  1451.          end if;
  1452.  
  1453.          return Node2;
  1454.       end if;
  1455.  
  1456.    --  If any error occurs, then scan to the next expression terminator symbol
  1457.    --  or comma or right paren at the outer (i.e. current) parentheses level.
  1458.    --  The flags are set to indicate a normal simple expression.
  1459.  
  1460.    exception
  1461.       when Error_Resync =>
  1462.          Resync_Expression;
  1463.          Expr_Form := EF_Simple;
  1464.          return Error;
  1465.    end P_Relation;
  1466.  
  1467.    ----------------------------
  1468.    -- 4.4  Simple Expression --
  1469.    ----------------------------
  1470.  
  1471.    --  SIMPLE_EXPRESSION ::=
  1472.    --    [UNARY_ADDING_OPERATOR] TERM {BINARY_ADDING_OPERATOR TERM}
  1473.  
  1474.    --  On return, Expr_Form indicates the categorization of the expression
  1475.  
  1476.    --  Note: if Token = Tok_Apostrophe on return, then Expr_Form is set to
  1477.    --  EF_Simple_Name and the following token is RANGE (range attribute case).
  1478.  
  1479.    --  Error recovery: cannot raise Error_Resync. If an error occurs within an
  1480.    --  expression, then tokens are scanned until either a non-expression token,
  1481.    --  a right paren (not matched by a left paren) or a comma, is encountered.
  1482.  
  1483.    --  Note: P_Simple_Expression is called only internally by higher level
  1484.    --  expression routines. In cases in the grammar where a simple expression
  1485.    --  is required, the approach is to scan an expression, and then post an
  1486.    --  appropriate error message if the expression obtained is not simple. This
  1487.    --  gives better error recovery and treatment.
  1488.  
  1489.    function P_Simple_Expression return Node_Id is
  1490.       Scan_State : Saved_Scan_State;
  1491.       Node1      : Node_Id;
  1492.       Node2      : Node_Id;
  1493.       Tokptr     : Source_Ptr;
  1494.  
  1495.    begin
  1496.       --  Check for cases starting with a name. There are two reasons for
  1497.       --  special casing. First speed things up by catching a common case
  1498.       --  without going through several routine layers. Second the caller must
  1499.       --  be informed via Expr_Form when the simple expression is a name.
  1500.  
  1501.       if Token in Token_Class_Name then
  1502.          Node1 := P_Name;
  1503.  
  1504.          --  Deal with apostrophe cases
  1505.  
  1506.          if Token = Tok_Apostrophe then
  1507.             Save_Scan_State (Scan_State); -- at apostrophe
  1508.             Scan; -- past apostrophe
  1509.  
  1510.             --  If qualified expression, scan it out and fall through
  1511.  
  1512.             if Token = Tok_Left_Paren then
  1513.                Node1 := P_Qualified_Expression (Node1);
  1514.                Expr_Form := EF_Simple;
  1515.  
  1516.             --  If range attribute, then we return with Token pointing to the
  1517.             --  apostrophe. Note: avoid the normal error check on exit. We
  1518.             --  know that the expression really is complete in this case!
  1519.  
  1520.             else -- Token = Tok_Range then
  1521.                Restore_Scan_State (Scan_State); -- to apostrophe
  1522.                Expr_Form := EF_Simple_Name;
  1523.                return Node1;
  1524.             end if;
  1525.          end if;
  1526.  
  1527.          --  If an expression terminator follows, the previous processing
  1528.          --  completely scanned out the expression (a common case), and
  1529.          --  left Expr_Form set appropriately for returning to our caller.
  1530.  
  1531.          if Token in Token_Class_Sterm then
  1532.             null;
  1533.  
  1534.          --  If we do not have an expression terminator, then complete the
  1535.          --  scan of a simple expression. This code duplicates the code
  1536.          --  found in P_Term and P_Factor.
  1537.  
  1538.          else
  1539.             if Token = Tok_Double_Asterisk then
  1540.                if Style_Check then Style.Check_Exponentiation_Operator; end if;
  1541.                Node2 := New_Node (N_Op_Expon, Token_Ptr);
  1542.                Scan; -- past **
  1543.                Set_Left_Opnd (Node2, Node1);
  1544.                Set_Right_Opnd (Node2, P_Primary);
  1545.                Set_Op_Name (Node2);
  1546.                Node1 := Node2;
  1547.             end if;
  1548.  
  1549.             loop
  1550.                exit when Token not in Token_Class_Mulop;
  1551.                Tokptr := Token_Ptr;
  1552.                Node2 := New_Node (P_Multiplying_Operator, Tokptr);
  1553.                if Style_Check then Style.Check_Binary_Operator; end if;
  1554.                Scan; -- past operator
  1555.                Set_Left_Opnd (Node2, Node1);
  1556.                Set_Right_Opnd (Node2, P_Factor);
  1557.                Set_Op_Name (Node2);
  1558.                Node1 := Node2;
  1559.             end loop;
  1560.  
  1561.             loop
  1562.                exit when Token not in Token_Class_Binary_Addop;
  1563.                Tokptr := Token_Ptr;
  1564.                Node2 := New_Node (P_Binary_Adding_Operator, Tokptr);
  1565.                if Style_Check then Style.Check_Binary_Operator; end if;
  1566.                Scan; -- past operator
  1567.                Set_Left_Opnd (Node2, Node1);
  1568.                Set_Right_Opnd (Node2, P_Term);
  1569.                Set_Op_Name (Node2);
  1570.                Node1 := Node2;
  1571.             end loop;
  1572.  
  1573.             Expr_Form := EF_Simple;
  1574.          end if;
  1575.  
  1576.       --  Cases where simple expression does not start with a name
  1577.  
  1578.       else
  1579.          --  Scan initial sign and initial Term
  1580.  
  1581.          if Token in Token_Class_Unary_Addop then
  1582.             Tokptr := Token_Ptr;
  1583.             Node1 := New_Node (P_Unary_Adding_Operator, Tokptr);
  1584.             if Style_Check then Style.Check_Unary_Plus_Or_Minus; end if;
  1585.             Scan; -- past operator
  1586.             Set_Right_Opnd (Node1, P_Term);
  1587.             Set_Op_Name (Node1);
  1588.          else
  1589.             Node1 := P_Term;
  1590.          end if;
  1591.  
  1592.          --  Scan out sequence of terms separated by binary adding operators
  1593.  
  1594.          loop
  1595.             exit when Token not in Token_Class_Binary_Addop;
  1596.             Tokptr := Token_Ptr;
  1597.             Node2 := New_Node (P_Binary_Adding_Operator, Tokptr);
  1598.             Scan; -- past operator
  1599.             Set_Left_Opnd (Node2, Node1);
  1600.             Set_Right_Opnd (Node2, P_Term);
  1601.             Set_Op_Name (Node2);
  1602.             Node1 := Node2;
  1603.          end loop;
  1604.  
  1605.          --  All done, we clearly do not have name or numeric literal so this
  1606.          --  is a case of a simple expression which is some other possibility.
  1607.  
  1608.          Expr_Form := EF_Simple;
  1609.       end if;
  1610.  
  1611.       --  Come here at end of simple expression, where we do a couple of
  1612.       --  special checks to improve error recovery.
  1613.  
  1614.       <<Simple_Expression_Exit_Error_Check>>
  1615.  
  1616.          --  Special test to improve error recovery. If the current token
  1617.          --  is a period, then someone is trying to do selection on something
  1618.          --  that is not a name, e.g. a qualified expression.
  1619.  
  1620.          if Token = Tok_Dot then
  1621.             Error_Msg_SC ("prefix for selection is not a name");
  1622.             raise Error_Resync;
  1623.          end if;
  1624.  
  1625.          --  Special test to improve error recovery: If the current token is
  1626.          --  not the first token on a line (as determined by checking the
  1627.          --  previous token position with the start of the current line),
  1628.          --  then we insist that we have an appropriate terminating token.
  1629.          --  Consider the following two examples:
  1630.  
  1631.          --   1)  if A nad B then ...
  1632.  
  1633.          --   2)  A := B
  1634.          --       C := D
  1635.  
  1636.          --  In the first example, we would like to issue a binary operator
  1637.          --  expected message and resynchronize to the then. In the second
  1638.          --  example, we do not want to issue a binary operator message, so
  1639.          --  that instead we will get the missing semicolon message. This
  1640.          --  distinction is of course a heuristic which does not always work,
  1641.          --  but in practice it is quite effective.
  1642.  
  1643.          --  Note: the one case in which we do not go through this circuit is
  1644.          --  when we have scanned a range attribute and want to return with
  1645.          --  Token pointing to the apostrophe. The apostrophe is not normally
  1646.          --  an expression terminator, and is not in Token_Class_Sterm, but
  1647.          --  in this special case we know that the expression is complete.
  1648.  
  1649.          if not Token_Is_At_Start_Of_Line
  1650.             and then Token not in Token_Class_Sterm
  1651.          then
  1652.             Error_Msg_AP ("binary operator expected");
  1653.             raise Error_Resync;
  1654.          else
  1655.             return Node1;
  1656.          end if;
  1657.  
  1658.    --  If any error occurs, then scan to next expression terminator symbol
  1659.    --  or comma, right paren or vertical bar at the outer (i.e. current) paren
  1660.    --  level. Expr_Form is set to indicate a normal simple expression.
  1661.  
  1662.    exception
  1663.       when Error_Resync =>
  1664.          Resync_Expression;
  1665.          Expr_Form := EF_Simple;
  1666.          return Error;
  1667.  
  1668.    end P_Simple_Expression;
  1669.  
  1670.    ---------------
  1671.    -- 4.4  Term --
  1672.    ---------------
  1673.  
  1674.    --  TERM ::= FACTOR {MULTIPLYING_OPERATOR FACTOR}
  1675.  
  1676.    --  Error recovery: can raise Error_Resync
  1677.  
  1678.    function P_Term return Node_Id is
  1679.       Node1, Node2 : Node_Id;
  1680.       Tokptr       : Source_Ptr;
  1681.  
  1682.    begin
  1683.       Node1 := P_Factor;
  1684.  
  1685.       loop
  1686.          exit when Token not in Token_Class_Mulop;
  1687.          Tokptr := Token_Ptr;
  1688.          Node2 := New_Node (P_Multiplying_Operator, Tokptr);
  1689.          Scan; -- past operator
  1690.          Set_Left_Opnd (Node2, Node1);
  1691.          Set_Right_Opnd (Node2, P_Factor);
  1692.          Set_Op_Name (Node2);
  1693.          Node1 := Node2;
  1694.       end loop;
  1695.  
  1696.       return Node1;
  1697.    end P_Term;
  1698.  
  1699.    -----------------
  1700.    -- 4.4  Factor --
  1701.    -----------------
  1702.  
  1703.    --  FACTOR ::= PRIMARY [** PRIMARY] | abs PRIMARY | not PRIMARY
  1704.  
  1705.    --  Error recovery: can raise Error_Resync
  1706.  
  1707.    function P_Factor return Node_Id is
  1708.       Node1 : Node_Id;
  1709.       Node2 : Node_Id;
  1710.  
  1711.    begin
  1712.       if Token = Tok_Abs then
  1713.          Node1 := New_Node (N_Op_Abs, Token_Ptr);
  1714.          if Style_Check then Style.Check_Abs_Not; end if;
  1715.          Scan; -- past ABS
  1716.          Set_Right_Opnd (Node1, P_Primary);
  1717.          Set_Op_Name (Node1);
  1718.          return Node1;
  1719.  
  1720.       elsif Token = Tok_Not then
  1721.          Node1 := New_Node (N_Op_Not, Token_Ptr);
  1722.          if Style_Check then Style.Check_Abs_Not; end if;
  1723.          Scan; -- past NOT
  1724.          Set_Right_Opnd (Node1, P_Primary);
  1725.          Set_Op_Name (Node1);
  1726.          return Node1;
  1727.  
  1728.       else
  1729.          Node1 := P_Primary;
  1730.  
  1731.          if Token = Tok_Double_Asterisk then
  1732.             Node2 := New_Node (N_Op_Expon, Token_Ptr);
  1733.             Scan; -- past **
  1734.             Set_Left_Opnd (Node2, Node1);
  1735.             Set_Right_Opnd (Node2, P_Primary);
  1736.             Set_Op_Name (Node2);
  1737.             return Node2;
  1738.          else
  1739.             return Node1;
  1740.          end if;
  1741.       end if;
  1742.    end P_Factor;
  1743.  
  1744.    ------------------
  1745.    -- 4.4  Primary --
  1746.    ------------------
  1747.  
  1748.    --  PRIMARY ::=
  1749.    --    NUMERIC_LITERAL  | null
  1750.    --  | STRING_LITERAL   | AGGREGATE
  1751.    --  | NAME             | QUALIFIED_EXPRESSION
  1752.    --  | ALLOCATOR        | (EXPRESSION)
  1753.  
  1754.    --  Error recovery: can raise Error_Resync
  1755.  
  1756.    function P_Primary return Node_Id is
  1757.       Scan_State   : Saved_Scan_State;
  1758.       Node1, Node2 : Node_Id;
  1759.  
  1760.    begin
  1761.       --  The loop runs more than once only if misplaced pragmas are found
  1762.  
  1763.       loop
  1764.          case Token is
  1765.  
  1766.             --  Name token can start a name, call or qualified expression, all
  1767.             --  of which are acceptable possibilities for primary. Note also
  1768.             --  that string literal is included in name (as operator symbol)
  1769.             --  and type conversion is included in name (as indexed component).
  1770.  
  1771.             when Tok_Char_Literal | Tok_Operator_Symbol | Tok_Identifier =>
  1772.                Node1 := P_Name;
  1773.  
  1774.                --  All done unless apostrophe follows
  1775.  
  1776.                if Token /= Tok_Apostrophe then
  1777.                   return Node1;
  1778.  
  1779.                --  Apostrophe following means that we have either just parsed
  1780.                --  the subtype mark of a qualified expression, or the prefix
  1781.                --  or a range attribute.
  1782.  
  1783.                else -- Token = Tok_Apostrophe
  1784.                   Save_Scan_State (Scan_State); -- at apostrophe
  1785.                   Scan; -- past apostrophe
  1786.  
  1787.                   --  If range attribute, then we have a case where this cannot
  1788.                   --  appear, since the only legitimate case (where the scanned
  1789.                   --  expression is a qualified simple name) is handled at the
  1790.                   --  Simple_Expression level. This case corresponds to a usage
  1791.                   --  such as 3 + A'Range, which is always illegal.
  1792.  
  1793.                   if Token = Tok_Range then
  1794.                      Error_Msg_SP ("range attribute not allowed here");
  1795.                      Restore_Scan_State (Scan_State); -- to apostrophe
  1796.                      Node1 := P_Range_Attribute_Reference (Node1);
  1797.                      return Error;
  1798.  
  1799.                   --  If left paren, then we have a qualified expression.
  1800.                   --  Note that P_Name guarantees that in this case, where
  1801.                   --  Token = Tok_Apostrophe on return, the only two possible
  1802.                   --  tokens following the apostrophe are left paren and
  1803.                   --  RANGE, so we know we have a left paren here.
  1804.  
  1805.                   else -- Token = Tok_Left_Paren
  1806.                      return P_Qualified_Expression (Node1);
  1807.  
  1808.                   end if;
  1809.                end if;
  1810.  
  1811.             --  Numeric or string literal
  1812.  
  1813.             when Tok_Integer_Literal |
  1814.                  Tok_Real_Literal    |
  1815.                  Tok_String_Literal  =>
  1816.  
  1817.                Node1 := Token_Node;
  1818.                Scan; -- past number
  1819.                return Node1;
  1820.  
  1821.             --  Left paren, starts aggregate or parenthesized expression
  1822.  
  1823.             when Tok_Left_Paren =>
  1824.                return P_Aggregate_Or_Paren_Expr;
  1825.  
  1826.             --  Allocator
  1827.  
  1828.             when Tok_New =>
  1829.                return P_Allocator;
  1830.  
  1831.             --  Null
  1832.  
  1833.             when Tok_Null =>
  1834.                Scan; -- past NULL
  1835.                return New_Node (N_Null, Prev_Token_Ptr);
  1836.  
  1837.             --  Pragma, not allowed here, so just skip past it
  1838.  
  1839.             when Tok_Pragma =>
  1840.                P_Pragmas_Misplaced;
  1841.  
  1842.             --  Anything else is illegal as the first token of a primary, but
  1843.             --  we test for a reserved identifier so that it is treated nicely
  1844.  
  1845.             when others =>
  1846.                if Is_Reserved_Identifier then
  1847.                   return P_Identifier;
  1848.                else
  1849.                   Error_Msg_AP ("missing operand");
  1850.                   raise Error_Resync;
  1851.                end if;
  1852.  
  1853.          end case;
  1854.       end loop;
  1855.    end P_Primary;
  1856.  
  1857.    ---------------------------
  1858.    -- 4.5  Logical Operator --
  1859.    ---------------------------
  1860.  
  1861.    --  LOGICAL_OPERATOR  ::=  and | or | xor
  1862.  
  1863.    --  Note: AND THEN and OR ELSE are also treated as logical operators
  1864.    --  by the parser (even though they are not operators semantically)
  1865.  
  1866.    --  The value returned is the appropriate Node_Kind code for the operator
  1867.    --  On return, Token points to the token following the scanned operator.
  1868.  
  1869.    --  The caller has checked that the first token is a legitimate logical
  1870.    --  operator token (i.e. is either XOR, AND, OR).
  1871.  
  1872.    --  Error recovery: cannot raise Error_Resync
  1873.  
  1874.    function P_Logical_Operator return Node_Kind is
  1875.    begin
  1876.       if Token = Tok_And then
  1877.          if Style_Check then Style.Check_Binary_Operator; end if;
  1878.          Scan; -- past AND
  1879.  
  1880.          if Token = Tok_Then then
  1881.             Scan; -- past THEN
  1882.             return N_And_Then;
  1883.          else
  1884.             return N_Op_And;
  1885.          end if;
  1886.  
  1887.       elsif Token = Tok_Or then
  1888.          if Style_Check then Style.Check_Binary_Operator; end if;
  1889.          Scan; -- past OR
  1890.  
  1891.          if Token = Tok_Else then
  1892.             Scan; -- past ELSE
  1893.             return N_Or_Else;
  1894.          else
  1895.             return N_Op_Or;
  1896.          end if;
  1897.  
  1898.       else -- Token = Tok_Xor
  1899.          if Style_Check then Style.Check_Binary_Operator; end if;
  1900.          Scan; -- past XOR
  1901.          return N_Op_Xor;
  1902.       end if;
  1903.    end P_Logical_Operator;
  1904.  
  1905.    ------------------------------
  1906.    -- 4.5  Relational Operator --
  1907.    ------------------------------
  1908.  
  1909.    --  RELATIONAL_OPERATOR ::= = | /= | < | <= | > | >=
  1910.  
  1911.    --  The value returned is the appropriate Node_Kind code for the operator.
  1912.    --  On return, Token points to the operator token, NOT past it.
  1913.  
  1914.    --  The caller has checked that the first token is a legitimate relational
  1915.    --  operator token (i.e. is one of the operator tokens listed above).
  1916.  
  1917.    --  Error recovery: cannot raise Error_Resync
  1918.  
  1919.    function P_Relational_Operator return Node_Kind is
  1920.       Op_Kind : Node_Kind;
  1921.       Relop_Node : constant array (Token_Class_Relop) of Node_Kind :=
  1922.         (Tok_Less           => N_Op_Lt,
  1923.          Tok_Equal          => N_Op_Eq,
  1924.          Tok_Greater        => N_Op_Gt,
  1925.          Tok_Not_Equal      => N_Op_Ne,
  1926.          Tok_Greater_Equal  => N_Op_Ge,
  1927.          Tok_Less_Equal     => N_Op_Le,
  1928.          Tok_In             => N_In,
  1929.          Tok_Not            => N_Not_In,
  1930.          Tok_Box            => N_Op_Ne);
  1931.  
  1932.    begin
  1933.       if Token = Tok_Box then
  1934.          Error_Msg_SC ("""<>"" should be ""/=""");
  1935.       end if;
  1936.  
  1937.       Op_Kind := Relop_Node (Token);
  1938.       if Style_Check then Style.Check_Binary_Operator; end if;
  1939.       Scan; -- past operator token
  1940.  
  1941.       if Prev_Token = Tok_Not then
  1942.          T_In;
  1943.       end if;
  1944.  
  1945.       return Op_Kind;
  1946.    end P_Relational_Operator;
  1947.  
  1948.    ---------------------------------
  1949.    -- 4.5  Binary Adding Operator --
  1950.    ---------------------------------
  1951.  
  1952.    --  BINARY_ADDING_OPERATOR ::= + | - | &
  1953.  
  1954.    --  The value returned is the appropriate Node_Kind code for the operator.
  1955.    --  On return, Token points to the operator token (NOT past it).
  1956.  
  1957.    --  The caller has checked that the first token is a legitimate adding
  1958.    --  operator token (i.e. is one of the operator tokens listed above).
  1959.  
  1960.    --  Error recovery: cannot raise Error_Resync
  1961.  
  1962.    function P_Binary_Adding_Operator return Node_Kind is
  1963.       Addop_Node : constant array (Token_Class_Binary_Addop) of Node_Kind :=
  1964.         (Tok_Ampersand      => N_Op_Concat,
  1965.          Tok_Minus          => N_Op_Subtract,
  1966.          Tok_Plus           => N_Op_Add);
  1967.    begin
  1968.       return Addop_Node (Token);
  1969.    end P_Binary_Adding_Operator;
  1970.  
  1971.    --------------------------------
  1972.    -- 4.5  Unary Adding Operator --
  1973.    --------------------------------
  1974.  
  1975.    --  UNARY_ADDING_OPERATOR ::= + | -
  1976.  
  1977.    --  The value returned is the appropriate Node_Kind code for the operator.
  1978.    --  On return, Token points to the operator token (NOT past it).
  1979.  
  1980.    --  The caller has checked that the first token is a legitimate adding
  1981.    --  operator token (i.e. is one of the operator tokens listed above).
  1982.  
  1983.    --  Error recovery: cannot raise Error_Resync
  1984.  
  1985.    function P_Unary_Adding_Operator return Node_Kind is
  1986.       Addop_Node : constant array (Token_Class_Unary_Addop) of Node_Kind :=
  1987.         (Tok_Minus          => N_Op_Minus,
  1988.          Tok_Plus           => N_Op_Plus);
  1989.    begin
  1990.       return Addop_Node (Token);
  1991.    end P_Unary_Adding_Operator;
  1992.  
  1993.    -------------------------------
  1994.    -- 4.5  Multiplying Operator --
  1995.    -------------------------------
  1996.  
  1997.    --  MULTIPLYING_OPERATOR ::= * | / | mod | rem
  1998.  
  1999.    --  The value returned is the appropriate Node_Kind code for the operator.
  2000.    --  On return, Token points to the operator token (NOT past it).
  2001.  
  2002.    --  The caller has checked that the first token is a legitimate multiplying
  2003.    --  operator token (i.e. is one of the operator tokens listed above).
  2004.  
  2005.    --  Error recovery: cannot raise Error_Resync
  2006.  
  2007.    function P_Multiplying_Operator return Node_Kind is
  2008.       Mulop_Node : constant array (Token_Class_Mulop) of Node_Kind :=
  2009.         (Tok_Asterisk       => N_Op_Multiply,
  2010.          Tok_Mod            => N_Op_Mod,
  2011.          Tok_Rem            => N_Op_Rem,
  2012.          Tok_Slash          => N_Op_Divide);
  2013.    begin
  2014.       return Mulop_Node (Token);
  2015.    end P_Multiplying_Operator;
  2016.  
  2017.    --------------------------------------
  2018.    -- 4.5  Highest Precedence Operator --
  2019.    --------------------------------------
  2020.  
  2021.    --  Parsed by P_Factor (4.4)
  2022.  
  2023.    --  Note: this rule is not in fact used by the grammar at any point!
  2024.  
  2025.    --------------------------
  2026.    -- 4.6  Type Conversion --
  2027.    --------------------------
  2028.  
  2029.    --  Parsed by P_Primary as a Name (4.1)
  2030.  
  2031.    -------------------------------
  2032.    -- 4.7  Qualified Expression --
  2033.    -------------------------------
  2034.  
  2035.    --  QUALIFIED_EXPRESSION ::=
  2036.    --    SUBTYPE_MARK ' (EXPRESSION) | SUBTYPE_MARK ' AGGREGATE
  2037.  
  2038.    --  The caller has scanned the name which is the Subtype_Mark parameter
  2039.    --  and scanned past the single quote following the subtype mark. The
  2040.    --  caller has not checked that this name is in fact appropriate for
  2041.    --  a subtype mark name (i.e. it is a selected component or identifier).
  2042.  
  2043.    --  Error_Recovery: cannot raise Error_Resync
  2044.  
  2045.    function  P_Qualified_Expression (Subtype_Mark : Node_Id) return Node_Id is
  2046.       Qual_Node : Node_Id;
  2047.  
  2048.    begin
  2049.       Qual_Node := New_Node (N_Qualified_Expression, Prev_Token_Ptr);
  2050.       Set_Subtype_Mark (Qual_Node, Check_Subtype_Mark (Subtype_Mark));
  2051.       Set_Expression (Qual_Node, P_Aggregate_Or_Paren_Expr);
  2052.       return Qual_Node;
  2053.    end P_Qualified_Expression;
  2054.  
  2055.    --------------------
  2056.    -- 4.8  Allocator --
  2057.    --------------------
  2058.  
  2059.    --  ALLOCATOR ::=
  2060.    --   new SUBTYPE_INDICATION | new QUALIFIED_EXPRESSION
  2061.  
  2062.    --  The caller has checked that the initial token is NEW
  2063.  
  2064.    --  Error recovery: can raise Error_Resync
  2065.  
  2066.    function P_Allocator return Node_Id is
  2067.       Alloc_Node  : Node_Id;
  2068.       Type_Node   : Node_Id;
  2069.  
  2070.    begin
  2071.       Alloc_Node := New_Node (N_Allocator, Token_Ptr);
  2072.       T_New;
  2073.       Type_Node := P_Subtype_Mark_Resync;
  2074.  
  2075.       if Token = Tok_Apostrophe then
  2076.          Scan; -- past apostrophe
  2077.          Set_Expression (Alloc_Node, P_Qualified_Expression (Type_Node));
  2078.       else
  2079.          Set_Expression (Alloc_Node, P_Subtype_Indication (Type_Node));
  2080.       end if;
  2081.  
  2082.       return Alloc_Node;
  2083.    end P_Allocator;
  2084.  
  2085. end Ch4;
  2086.