OSDN Git Service

* 3vtrasym.adb:
[pf3gnuchains/gcc-fork.git] / gcc / ada / par.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                                  P A R                                   --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2003 Free Software Foundation, Inc.          --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 with Atree;    use Atree;
28 with Casing;   use Casing;
29 with Debug;    use Debug;
30 with Elists;   use Elists;
31 with Errout;   use Errout;
32 with Fname;    use Fname;
33 with Lib;      use Lib;
34 with Namet;    use Namet;
35 with Nlists;   use Nlists;
36 with Nmake;    use Nmake;
37 with Opt;      use Opt;
38 with Output;   use Output;
39 with Scans;    use Scans;
40 with Scn;      use Scn;
41 with Sinput;   use Sinput;
42 with Sinput.L; use Sinput.L;
43 with Sinfo;    use Sinfo;
44 with Snames;   use Snames;
45 with Style;
46 with Table;
47 with Tbuild;   use Tbuild;
48
49 function Par (Configuration_Pragmas : Boolean) return List_Id is
50
51    Num_Library_Units : Natural := 0;
52    --  Count number of units parsed (relevant only in syntax check only mode,
53    --  since in semantics check mode only a single unit is permitted anyway)
54
55    Save_Config_Switches : Config_Switches_Type;
56    --  Variable used to save values of config switches while we parse the
57    --  new unit, to be restored on exit for proper recursive behavior.
58
59    Loop_Block_Count : Nat := 0;
60    --  Counter used for constructing loop/block names (see the routine
61    --  Par.Ch5.Get_Loop_Block_Name)
62
63    --------------------
64    -- Error Recovery --
65    --------------------
66
67    --  When an error is encountered, a call is made to one of the Error_Msg
68    --  routines to record the error. If the syntax scan is not derailed by the
69    --  error (e.g. a complaint that logical operators are inconsistent in an
70    --  EXPRESSION), then control returns from the Error_Msg call, and the
71    --  parse continues unimpeded.
72
73    --  If on the other hand, the Error_Msg represents a situation from which
74    --  the parser cannot recover locally, the exception Error_Resync is raised
75    --  immediately after the call to Error_Msg. Handlers for Error_Resync
76    --  are located at strategic points to resynchronize the parse. For example,
77    --  when an error occurs in a statement, the handler skips to the next
78    --  semicolon and continues the scan from there.
79
80    --  Each parsing procedure contains a note with the heading "Error recovery"
81    --  which shows if it can propagate the Error_Resync exception. In order
82    --  not to propagate the exception, a procedure must either contain its own
83    --  handler for this exception, or it must not call any other routines which
84    --  propagate the exception.
85
86    --  Note: the arrangement of Error_Resync handlers is such that it should
87    --  never be possible to transfer control through a procedure which made
88    --  an entry in the scope stack, invalidating the contents of the stack.
89
90    Error_Resync : exception;
91    --  Exception raised on error that is not handled locally, see above.
92
93    Last_Resync_Point : Source_Ptr;
94    --  The resynchronization routines in Par.Sync run a risk of getting
95    --  stuck in an infinite loop if they do not skip a token, and the caller
96    --  keeps repeating the same resync call. On the other hand, if they skip
97    --  a token unconditionally, some recovery opportunities are missed. The
98    --  variable Last_Resync_Point records the token location previously set
99    --  by a Resync call, and if a subsequent Resync call occurs at the same
100    --  location, then the Resync routine does guarantee to skip a token.
101
102    --------------------------------------------
103    -- Handling Semicolon Used in Place of IS --
104    --------------------------------------------
105
106    --  The following global variables are used in handling the error situation
107    --  of using a semicolon in place of IS in a subprogram declaration as in:
108
109    --    procedure X (Y : Integer);
110    --       Q : Integer;
111    --    begin
112    --       ...
113    --    end;
114
115    --  The two contexts in which this can appear are at the outer level, and
116    --  within a declarative region. At the outer level, we know something is
117    --  wrong as soon as we see the Q (or begin, if there are no declarations),
118    --  and we can immediately decide that the semicolon should have been IS.
119
120    --  The situation in a declarative region is more complex. The declaration
121    --  of Q could belong to the outer region, and we do not know that we have
122    --  an error until we hit the begin. It is still not clear at this point
123    --  from a syntactic point of view that something is wrong, because the
124    --  begin could belong to the enclosing subprogram or package. However, we
125    --  can incorporate a bit of semantic knowledge and note that the body of
126    --  X is missing, so we definitely DO have an error. We diagnose this error
127    --  as semicolon in place of IS on the subprogram line.
128
129    --  There are two styles for this diagnostic. If the begin immediately
130    --  follows the semicolon, then we can place a flag (IS expected) right
131    --  on the semicolon. Otherwise we do not detect the error until we hit
132    --  the begin which refers back to the line with the semicolon.
133
134    --  To control the process in the second case, the following global
135    --  variables are set to indicate that we have a subprogram declaration
136    --  whose body is required and has not yet been found. The prefix SIS
137    --  stands for "Subprogram IS" handling.
138
139    SIS_Entry_Active : Boolean;
140    --  Set True to indicate that an entry is active (i.e. that a subprogram
141    --  declaration has been encountered, and no body for this subprogram has
142    --  been encountered). The remaining fields are valid only if this is True.
143
144    SIS_Labl : Node_Id;
145    --  Subprogram designator
146
147    SIS_Sloc : Source_Ptr;
148    --  Source location of FUNCTION/PROCEDURE keyword
149
150    SIS_Ecol : Column_Number;
151    --  Column number of FUNCTION/PROCEDURE keyword
152
153    SIS_Semicolon_Sloc : Source_Ptr;
154    --  Source location of semicolon at end of subprogram declaration
155
156    SIS_Declaration_Node : Node_Id;
157    --  Pointer to tree node for subprogram declaration
158
159    SIS_Missing_Semicolon_Message : Error_Msg_Id;
160    --  Used to save message ID of missing semicolon message (which will be
161    --  modified to missing IS if necessary). Set to No_Error_Msg in the
162    --  normal (non-error) case.
163
164    --  Five things can happen to an active SIS entry
165
166    --   1. If a BEGIN is encountered with an SIS entry active, then we have
167    --   exactly the situation in which we know the body of the subprogram is
168    --   missing. After posting an error message, we change the spec to a body,
169    --   rechaining the declarations that intervened between the spec and BEGIN.
170
171    --   2. Another subprogram declaration or body is encountered. In this
172    --   case the entry gets overwritten with the information for the new
173    --   subprogram declaration. We don't catch some nested cases this way,
174    --   but it doesn't seem worth the effort.
175
176    --   3. A nested declarative region (e.g. package declaration or package
177    --   body) is encountered. The SIS active indication is reset at the start
178    --   of such a nested region. Again, like case 2, this causes us to miss
179    --   some nested cases, but it doesn't seen worth the effort to stack and
180    --   unstack the SIS information. Maybe we will reconsider this if we ever
181    --   get a complaint about a missed case :-)
182
183    --   4. We encounter a valid pragma INTERFACE or IMPORT that effectively
184    --   supplies the missing body. In this case we reset the entry.
185
186    --   5. We encounter the end of the declarative region without encoutering
187    --   a BEGIN first. In this situation we simply reset the entry. We know
188    --   that there is a missing body, but it seems more reasonable to let the
189    --   later semantic checking discover this.
190
191    ----------------------------------------------------
192    -- Handling of Reserved Words Used as Identifiers --
193    ----------------------------------------------------
194
195    --  Note: throughout the parser, the terms reserved word and keyword
196    --  are used interchangably to refer to the same set of reserved
197    --  keywords (including until, protected, etc).
198
199    --  If a reserved word is used in place of an identifier, the parser
200    --  where possible tries to recover gracefully. In particular, if the
201    --  keyword is clearly spelled using identifier casing, e.g. Until in
202    --  a source program using mixed case identifiers and lower case keywords,
203    --  then the keyword is treated as an identifier if it appears in a place
204    --  where an identifier is required.
205
206    --  The situation is more complex if the keyword is spelled with normal
207    --  keyword casing. In this case, the parser is more reluctant to
208    --  consider it to be intended as an identifier, unless it has some
209    --  further confirmation.
210
211    --  In the case of an identifier appearing in the identifier list of a
212    --  declaration, the appearence of a comma or colon right after the
213    --  keyword on the same line is taken as confirmation. For an enumeration
214    --  literal, a comma or right paren right after the identifier is also
215    --  treated as adequate confirmation.
216
217    --  The following type is used in calls to Is_Reserved_Identifier and
218    --  also to P_Defining_Identifier and P_Identifier. The default for all
219    --  these functins is that reserved words in reserved word case are not
220    --  considered to be reserved identifiers. The Id_Check value indicates
221    --  tokens, which if they appear immediately after the identifier, are
222    --  taken as confirming that the use of an identifier was expected
223
224    type Id_Check is
225      (None,
226       --  Default, no special token test
227
228       C_Comma_Right_Paren,
229       --  Consider as identifier if followed by comma or right paren
230
231       C_Comma_Colon,
232       --  Consider as identifier if followed by comma or colon
233
234       C_Do,
235       --  Consider as identifier if followed by DO
236
237       C_Dot,
238       --  Consider as identifier if followed by period
239
240       C_Greater_Greater,
241       --  Consider as identifier if followed by >>
242
243       C_In,
244       --  Consider as identifier if followed by IN
245
246       C_Is,
247       --  Consider as identifier if followed by IS
248
249       C_Left_Paren_Semicolon,
250       --  Consider as identifier if followed by left paren or semicolon
251
252       C_Use,
253       --  Consider as identifier if followed by USE
254
255       C_Vertical_Bar_Arrow);
256       --  Consider as identifier if followed by | or =>
257
258    --------------------------------------------
259    -- Handling IS Used in Place of Semicolon --
260    --------------------------------------------
261
262    --  This is a somewhat trickier situation, and we can't catch it in all
263    --  cases, but we do our best to detect common situations resulting from
264    --  a "cut and paste" operation which forgets to change the IS to semicolon.
265    --  Consider the following example:
266
267    --    package body X is
268    --      procedure A;
269    --      procedure B is
270    --      procedure C;
271    --      ...
272    --      procedure D is
273    --      begin
274    --         ...
275    --      end;
276    --    begin
277    --      ...
278    --    end;
279
280    --  The trouble is that the section of text from PROCEDURE B through END;
281    --  consitutes a valid procedure body, and the danger is that we find out
282    --  far too late that something is wrong (indeed most compilers will behave
283    --  uncomfortably on the above example).
284
285    --  We have two approaches to helping to control this situation. First we
286    --  make every attempt to avoid swallowing the last END; if we can be
287    --  sure that some error will result from doing so. In particular, we won't
288    --  accept the END; unless it is exactly correct (in particular it must not
289    --  have incorrect name tokens), and we won't accept it if it is immediately
290    --  followed by end of file, WITH or SEPARATE (all tokens that unmistakeably
291    --  signal the start of a compilation unit, and which therefore allow us to
292    --  reserve the END; for the outer level.) For more details on this aspect
293    --  of the handling, see package Par.Endh.
294
295    --  If we can avoid eating up the END; then the result in the absense of
296    --  any additional steps would be to post a missing END referring back to
297    --  the subprogram with the bogus IS. Similarly, if the enclosing package
298    --  has no BEGIN, then the result is a missing BEGIN message, which again
299    --  refers back to the subprogram header.
300
301    --  Such an error message is not too bad (it's already a big improvement
302    --  over what many parsers do), but it's not ideal, because the declarations
303    --  following the IS have been absorbed into the wrong scope. In the above
304    --  case, this could result for example in a bogus complaint that the body
305    --  of D was missing from the package.
306
307    --  To catch at least some of these cases, we take the following additional
308    --  steps. First, a subprogram body is marked as having a suspicious IS if
309    --  the declaration line is followed by a line which starts with a symbol
310    --  that can start a declaration in the same column, or to the left of the
311    --  column in which the FUNCTION or PROCEDURE starts (normal style is to
312    --  indent any declarations which really belong a subprogram). If such a
313    --  subprogram encounters a missing BEGIN or missing END, then we decide
314    --  that the IS should have been a semicolon, and the subprogram body node
315    --  is marked (by setting the Bad_Is_Detected flag true. Note that we do
316    --  not do this for library level procedures, only for nested procedures,
317    --  since for library level procedures, we must have a body.
318
319    --  The processing for a declarative part checks to see if the last
320    --  declaration scanned is marked in this way, and if it is, the tree
321    --  is modified to reflect the IS being interpreted as a semicolon.
322
323    ---------------------------------------------------
324    -- Parser Type Definitions and Control Variables --
325    ---------------------------------------------------
326
327    --  The following variable and associated type declaration are used by the
328    --  expression parsing routines to return more detailed information about
329    --  the categorization of a parsed expression.
330
331    type Expr_Form_Type is (
332       EF_Simple_Name,  -- Simple name, i.e. possibly qualified identifier
333       EF_Name,         -- Simple expression which could also be a name
334       EF_Simple,       -- Simple expression which is not call or name
335       EF_Range_Attr,   -- Range attribute reference
336       EF_Non_Simple);  -- Expression that is not a simple expression
337
338    Expr_Form : Expr_Form_Type;
339
340    --  The following type is used for calls to P_Subprogram, P_Package, P_Task,
341    --  P_Protected to indicate which of several possibilities is acceptable.
342
343    type Pf_Rec is record
344       Spcn : Boolean;                  -- True if specification OK
345       Decl : Boolean;                  -- True if declaration OK
346       Gins : Boolean;                  -- True if generic instantiation OK
347       Pbod : Boolean;                  -- True if proper body OK
348       Rnam : Boolean;                  -- True if renaming declaration OK
349       Stub : Boolean;                  -- True if body stub OK
350       Fil1 : Boolean;                  -- Filler to fill to 8 bits
351       Fil2 : Boolean;                  -- Filler to fill to 8 bits
352    end record;
353    pragma Pack (Pf_Rec);
354
355    function T return Boolean renames True;
356    function F return Boolean renames False;
357
358    Pf_Decl_Gins_Pbod_Rnam_Stub : constant Pf_Rec :=
359                                              Pf_Rec'(F, T, T, T, T, T, F, F);
360    Pf_Decl                     : constant Pf_Rec :=
361                                              Pf_Rec'(F, T, F, F, F, F, F, F);
362    Pf_Decl_Gins_Pbod_Rnam      : constant Pf_Rec :=
363                                              Pf_Rec'(F, T, T, T, T, F, F, F);
364    Pf_Decl_Pbod                : constant Pf_Rec :=
365                                              Pf_Rec'(F, T, F, T, F, F, F, F);
366    Pf_Pbod                     : constant Pf_Rec :=
367                                              Pf_Rec'(F, F, F, T, F, F, F, F);
368    Pf_Spcn                     : constant Pf_Rec :=
369                                              Pf_Rec'(T, F, F, F, F, F, F, F);
370    --  The above are the only allowed values of Pf_Rec arguments
371
372    type SS_Rec is record
373       Eftm : Boolean;      -- ELSIF can terminate sequence
374       Eltm : Boolean;      -- ELSE can terminate sequence
375       Extm : Boolean;      -- EXCEPTION can terminate sequence
376       Ortm : Boolean;      -- OR can terminate sequence
377       Sreq : Boolean;      -- at least one statement required
378       Tatm : Boolean;      -- THEN ABORT can terminate sequence
379       Whtm : Boolean;      -- WHEN can terminate sequence
380       Unco : Boolean;      -- Unconditional terminate after one statement
381    end record;
382    pragma Pack (SS_Rec);
383
384    SS_Eftm_Eltm_Sreq : constant SS_Rec := SS_Rec'(T, T, F, F, T, F, F, F);
385    SS_Eltm_Ortm_Tatm : constant SS_Rec := SS_Rec'(F, T, F, T, F, T, F, F);
386    SS_Extm_Sreq      : constant SS_Rec := SS_Rec'(F, F, T, F, T, F, F, F);
387    SS_None           : constant SS_Rec := SS_Rec'(F, F, F, F, F, F, F, F);
388    SS_Ortm_Sreq      : constant SS_Rec := SS_Rec'(F, F, F, T, T, F, F, F);
389    SS_Sreq           : constant SS_Rec := SS_Rec'(F, F, F, F, T, F, F, F);
390    SS_Sreq_Whtm      : constant SS_Rec := SS_Rec'(F, F, F, F, T, F, T, F);
391    SS_Whtm           : constant SS_Rec := SS_Rec'(F, F, F, F, F, F, T, F);
392    SS_Unco           : constant SS_Rec := SS_Rec'(F, F, F, F, F, F, F, T);
393
394    Label_List : Elist_Id;
395    --  List of label nodes for labels appearing in the current compilation.
396    --  Used by Par.Labl to construct the corresponding implicit declarations.
397
398    -----------------
399    -- Scope Table --
400    -----------------
401
402    --  The scope table, also referred to as the scope stack, is used to
403    --  record the current scope context. It is organized as a stack, with
404    --  inner nested entries corresponding to higher entries on the stack.
405    --  An entry is made when the parser encounters the opening of a nested
406    --  construct (such as a record, task, package etc.), and then package
407    --  Par.Endh uses this stack to deal with END lines (including properly
408    --  dealing with END nesting errors).
409
410    type SS_End_Type is
411    --  Type of end entry required for this scope. The last two entries are
412    --  used only in the subprogram body case to mark the case of a suspicious
413    --  IS, or a bad IS (i.e. suspicions confirmed by missing BEGIN or END).
414    --  See separate section on dealing with IS used in place of semicolon.
415    --  Note that for many purposes E_Name, E_Suspicious_Is and E_Bad_Is are
416    --  treated the same (E_Suspicious_Is and E_Bad_Is are simply special cases
417    --  of E_Name). They are placed at the end of the enumeration so that a
418    --  test for >= E_Name catches all three cases efficiently.
419
420       (E_Dummy,           -- dummy entry at outer level
421        E_Case,            -- END CASE;
422        E_If,              -- END IF;
423        E_Loop,            -- END LOOP;
424        E_Record,          -- END RECORD;
425        E_Select,          -- END SELECT;
426        E_Name,            -- END [name];
427        E_Suspicious_Is,   -- END [name]; (case of suspicious IS)
428        E_Bad_Is);         -- END [name]; (case of bad IS)
429
430    --  The following describes a single entry in the scope table
431
432    type Scope_Table_Entry is record
433       Etyp : SS_End_Type;
434       --  Type of end entry, as per above description
435
436       Lreq : Boolean;
437       --  A flag indicating whether the label, if present, is required to
438       --  appear on the end line. It is referenced only in the case of
439       --  Etyp = E_Name or E_Suspicious_Is where the name may or may not be
440       --  required (yes for labeled block, no in other cases). Note that for
441       --  all cases except begin, the question of whether a label is required
442       --  can be determined from the other fields (for loop, it is required if
443       --  it is present, and for the other constructs it is never required or
444       --  allowed).
445
446       Ecol : Column_Number;
447       --  Contains the absolute column number (with tabs expanded) of the
448       --  the expected column of the end assuming normal Ada indentation
449       --  usage. If the RM_Column_Check mode is set, this value is used for
450       --  generating error messages about indentation. Otherwise it is used
451       --  only to control heuristic error recovery actions.
452
453       Labl : Node_Id;
454       --  This field is used only for the LOOP and BEGIN cases, and is the
455       --  Node_Id value of the label name. For all cases except child units,
456       --  this value is an entity whose Chars field contains the name pointer
457       --  that identifies the label uniquely. For the child unit case the Labl
458       --  field references an N_Defining_Program_Unit_Name node for the name.
459       --  For cases other than LOOP or BEGIN, the Label field is set to Error,
460       --  indicating that it is an error to have a label on the end line.
461       --  (this is really a misuse of Error since there is no Error ???)
462
463       Decl : List_Id;
464       --  Points to the list of declarations (i.e. the declarative part)
465       --  associated with this construct. It is set only in the END [name]
466       --  cases, and is set to No_List for all other cases which do not have a
467       --  declarative unit associated with them. This is used for determining
468       --  the proper location for implicit label declarations.
469
470       Node : Node_Id;
471       --  Empty except in the case of entries for IF and CASE statements,
472       --  in which case it contains the N_If_Statement or N_Case_Statement
473       --  node. This is used for setting the End_Span field.
474
475       Sloc : Source_Ptr;
476       --  Source location of the opening token of the construct. This is
477       --  used to refer back to this line in error messages (such as missing
478       --  or incorrect end lines). The Sloc field is not used, and is not set,
479       --  if a label is present (the Labl field provides the text name of the
480       --  label in this case, which is fine for error messages).
481
482       S_Is : Source_Ptr;
483       --  S_Is is relevant only if Etyp is set to E_Suspicious_Is or
484       --  E_Bad_Is. It records the location of the IS that is considered
485       --  to be suspicious.
486
487       Junk : Boolean;
488       --  A boolean flag that is set true if the opening entry is the dubious
489       --  result of some prior error, e.g. a record entry where the record
490       --  keyword was missing. It is used to suppress the issuing of a
491       --  corresponding junk complaint about the end line (we do not want
492       --  to complain about a missing end record when there was no record).
493    end record;
494
495    --  The following declares the scope table itself. The Last field is the
496    --  stack pointer, so that Scope.Table (Scope.Last) is the top entry. The
497    --  oldest entry, at Scope_Stack (0), is a dummy entry with Etyp set to
498    --  E_Dummy, and the other fields undefined. This dummy entry ensures that
499    --  Scope_Stack (Scope_Stack_Ptr).Etyp can always be tested, and that the
500    --  scope stack pointer is always in range.
501
502    package Scope is new Table.Table (
503      Table_Component_Type => Scope_Table_Entry,
504      Table_Index_Type     => Int,
505      Table_Low_Bound      => 0,
506      Table_Initial        => 50,
507      Table_Increment      => 100,
508      Table_Name           => "Scope");
509
510    ---------------------------------
511    -- Parsing Routines by Chapter --
512    ---------------------------------
513
514    --  Uncommented declarations in this section simply parse the construct
515    --  corresponding to their name, and return an ID value for the Node or
516    --  List that is created.
517
518    package Ch2 is
519       function P_Pragma                               return Node_Id;
520
521       function P_Identifier (C : Id_Check := None) return Node_Id;
522       --  Scans out an identifier. The parameter C determines the treatment
523       --  of reserved identifiers. See declaration of Id_Check for details.
524
525       function P_Pragmas_Opt return List_Id;
526       --  This function scans for a sequence of pragmas in other than a
527       --  declaration sequence or statement sequence context. All pragmas
528       --  can appear except pragmas Assert and Debug, which are only allowed
529       --  in a declaration or statement sequence context.
530
531       procedure P_Pragmas_Misplaced;
532       --  Skips misplaced pragmas with a complaint
533
534       procedure P_Pragmas_Opt (List : List_Id);
535       --  Parses optional pragmas and appends them to the List
536    end Ch2;
537
538    package Ch3 is
539       Missing_Begin_Msg : Error_Msg_Id;
540       --  This variable is set by a call to P_Declarative_Part. Normally it
541       --  is set to No_Error_Msg, indicating that no special processing is
542       --  required by the caller. The special case arises when a statement
543       --  is found in the sequence of declarations. In this case the Id of
544       --  the message issued ("declaration expected") is preserved in this
545       --  variable, then the caller can change it to an appropriate missing
546       --  begin message if indeed the BEGIN is missing.
547
548       function P_Access_Definition                    return Node_Id;
549       function P_Access_Type_Definition               return Node_Id;
550       function P_Array_Type_Definition                return Node_Id;
551       function P_Basic_Declarative_Items              return List_Id;
552       function P_Constraint_Opt                       return Node_Id;
553       function P_Declarative_Part                     return List_Id;
554       function P_Discrete_Choice_List                 return List_Id;
555       function P_Discrete_Range                       return Node_Id;
556       function P_Discrete_Subtype_Definition          return Node_Id;
557       function P_Known_Discriminant_Part_Opt          return List_Id;
558       function P_Signed_Integer_Type_Definition       return Node_Id;
559       function P_Range                                return Node_Id;
560       function P_Range_Or_Subtype_Mark                return Node_Id;
561       function P_Range_Constraint                     return Node_Id;
562       function P_Record_Definition                    return Node_Id;
563       function P_Subtype_Indication                   return Node_Id;
564       function P_Subtype_Mark                         return Node_Id;
565       function P_Subtype_Mark_Resync                  return Node_Id;
566       function P_Unknown_Discriminant_Part_Opt        return Boolean;
567
568       procedure P_Component_Items (Decls : List_Id);
569       --  Scan out one or more component items and append them to the
570       --  given list. Only scans out more than one declaration in the
571       --  case where the source has a single declaration with multiple
572       --  defining identifiers.
573
574       function P_Defining_Identifier (C : Id_Check := None) return Node_Id;
575       --  Scan out a defining identifier. The parameter C controls the
576       --  treatment of errors in case a reserved word is scanned. See the
577       --  declaration of this type for details.
578
579       function Init_Expr_Opt (P : Boolean := False) return Node_Id;
580       --  If an initialization expression is present (:= expression), then
581       --  it is scanned out and returned, otherwise Empty is returned if no
582       --  initialization expression is present. This procedure also handles
583       --  certain common error cases cleanly. The parameter P indicates if
584       --  a right paren can follow the expression (default = no right paren
585       --  allowed).
586
587       procedure Skip_Declaration (S : List_Id);
588       --  Used when scanning statements to skip past a mispaced declaration
589       --  The declaration is scanned out and appended to the given list.
590       --  Token is known to be a declaration token (in Token_Class_Declk)
591       --  on entry, so there definition is a declaration to be scanned.
592
593       function P_Subtype_Indication (Subtype_Mark : Node_Id) return Node_Id;
594       --  This version of P_Subtype_Indication is called when the caller has
595       --  already scanned out the subtype mark which is passed as a parameter.
596
597       function P_Subtype_Mark_Attribute (Type_Node : Node_Id) return Node_Id;
598       --  Parse a subtype mark attribute. The caller has already parsed the
599       --  subtype mark, which is passed in as the argument, and has checked
600       --  that the current token is apostrophe.
601
602    end Ch3;
603
604    package Ch4 is
605       function P_Aggregate                            return Node_Id;
606       function P_Expression                           return Node_Id;
607       function P_Expression_No_Right_Paren            return Node_Id;
608       function P_Expression_Or_Range_Attribute        return Node_Id;
609       function P_Function_Name                        return Node_Id;
610       function P_Name                                 return Node_Id;
611       function P_Qualified_Simple_Name                return Node_Id;
612       function P_Qualified_Simple_Name_Resync         return Node_Id;
613       function P_Simple_Expression                    return Node_Id;
614       function P_Simple_Expression_Or_Range_Attribute return Node_Id;
615
616       function P_Qualified_Expression
617         (Subtype_Mark : Node_Id)
618          return         Node_Id;
619       --  This routine scans out a qualified expression when the caller has
620       --  already scanned out the name and apostrophe of the construct.
621
622    end Ch4;
623
624    package Ch5 is
625
626       function P_Statement_Name (Name_Node : Node_Id) return Node_Id;
627       --  Given a node representing a name (which is a call), converts it
628       --  to the syntactically corresponding procedure call statement.
629
630       function P_Sequence_Of_Statements (SS_Flags : SS_Rec) return List_Id;
631       --  The argument indicates the acceptable termination tokens.
632       --  See body in Par.Ch5 for details of the use of this parameter.
633
634       procedure Parse_Decls_Begin_End (Parent : Node_Id);
635       --  Parses declarations and handled statement sequence, setting
636       --  fields of Parent node appropriately.
637
638    end Ch5;
639
640    package Ch6 is
641       function P_Designator                           return Node_Id;
642       function P_Defining_Program_Unit_Name           return Node_Id;
643       function P_Formal_Part                          return List_Id;
644       function P_Parameter_Profile                    return List_Id;
645       function P_Return_Statement                     return Node_Id;
646       function P_Subprogram_Specification             return Node_Id;
647
648       procedure P_Mode (Node : Node_Id);
649       --  Sets In_Present and/or Out_Present flags in Node scanning past
650       --  IN, OUT or IN OUT tokens in the source.
651
652       function P_Subprogram (Pf_Flags : Pf_Rec)       return Node_Id;
653       --  Scans out any construct starting with either of the keywords
654       --  PROCEDURE or FUNCTION. The parameter indicates which possible
655       --  possible kinds of construct (body, spec, instantiation etc.)
656       --  are permissible in the current context.
657
658    end Ch6;
659
660    package Ch7 is
661       function P_Package (Pf_Flags : Pf_Rec) return Node_Id;
662       --  Scans out any construct starting with the keyword PACKAGE. The
663       --  parameter indicates which possible kinds of construct (body, spec,
664       --  instantiation etc.) are permissible in the current context.
665    end Ch7;
666
667    package Ch8 is
668       function P_Use_Clause                           return Node_Id;
669    end Ch8;
670
671    package Ch9 is
672       function P_Abort_Statement                      return Node_Id;
673       function P_Abortable_Part                       return Node_Id;
674       function P_Accept_Statement                     return Node_Id;
675       function P_Delay_Statement                      return Node_Id;
676       function P_Entry_Body                           return Node_Id;
677       function P_Protected                            return Node_Id;
678       function P_Requeue_Statement                    return Node_Id;
679       function P_Select_Statement                     return Node_Id;
680       function P_Task                                 return Node_Id;
681       function P_Terminate_Alternative                return Node_Id;
682    end Ch9;
683
684    package Ch10 is
685       function P_Compilation_Unit                     return Node_Id;
686       --  Note: this function scans a single compilation unit, and
687       --  checks that an end of file follows this unit, diagnosing
688       --  any unexpected input as an error, and then skipping it, so
689       --  that Token is set to Tok_EOF on return. An exception is in
690       --  syntax-only mode, where multiple compilation units are
691       --  permitted. In this case, P_Compilation_Unit does not check
692       --  for end of file and there may be more compilation units to
693       --  scan. The caller can uniquely detect this situation by the
694       --  fact that Token is not set to Tok_EOF on return.
695    end Ch10;
696
697    package Ch11 is
698       function P_Handled_Sequence_Of_Statements       return Node_Id;
699       function P_Raise_Statement                      return Node_Id;
700
701       function Parse_Exception_Handlers               return List_Id;
702       --  Parses the partial construct EXCEPTION followed by a list of
703       --  exception handlers which appears in a number of productions,
704       --  and returns the list of exception handlers.
705
706    end Ch11;
707
708    package Ch12 is
709       function P_Generic                              return Node_Id;
710       function P_Generic_Actual_Part_Opt              return List_Id;
711    end Ch12;
712
713    package Ch13 is
714       function P_Representation_Clause                return Node_Id;
715
716       function P_Code_Statement (Subtype_Mark : Node_Id) return Node_Id;
717       --  Function to parse a code statement. The caller has scanned out
718       --  the name to be used as the subtype mark (but has not checked that
719       --  it is suitable for use as a subtype mark, i.e. is either an
720       --  identifier or a selected component). The current token is an
721       --  apostrophe and the following token is either a left paren or
722       --  RANGE (the latter being an error to be caught by P_Code_Statement.
723    end Ch13;
724
725    --  Note: the parsing for annexe J features (i.e. obsolescent features)
726    --  is found in the logical section where these features would be if
727    --  they were not obsolescent. In particular:
728
729    --    Delta constraint is parsed by P_Delta_Constraint (3.5.9)
730    --    At clause is parsed by P_At_Clause (13.1)
731    --    Mod clause is parsed by P_Mod_Clause (13.5.1)
732
733    ------------------
734    -- End Handling --
735    ------------------
736
737    --  Routines for handling end lines, including scope recovery
738
739    package Endh is
740
741       function Check_End return Boolean;
742       --  Called when an end sequence is required. In the absence of an error
743       --  situation, Token contains Tok_End on entry, but in a missing end
744       --  case, this may not be the case. Pop_End_Context is used to determine
745       --  the appropriate action to be taken. The returned result is True if
746       --  an End sequence was encountered and False if no End sequence was
747       --  present. This occurs if the END keyword encountered was determined
748       --  to be improper and deleted (i.e. Pop_End_Context set End_Action to
749       --  Skip_And_Reject). Note that the END sequence includes a semicolon,
750       --  except in the case of END RECORD, where a semicolon follows the END
751       --  RECORD, but is not part of the record type definition itself.
752
753       procedure End_Skip;
754       --  Skip past an end sequence. On entry Token contains Tok_End, and we
755       --  we know that the end sequence is syntactically incorrect, and that
756       --  an appropriate error message has already been posted. The mission
757       --  is simply to position the scan pointer to be the best guess of the
758       --  position after the end sequence. We do not issue any additional
759       --  error messages while carrying this out.
760
761       procedure End_Statements (Parent : Node_Id := Empty);
762       --  Called when an end is required or expected to terminate a sequence
763       --  of statements. The caller has already made an appropriate entry in
764       --  the Scope.Table to describe the expected form of the end. This can
765       --  only be used in cases where the only appropriate terminator is end.
766       --  If Parent is non-empty, then if a correct END line is encountered,
767       --  the End_Label field of Parent is set appropriately.
768
769    end Endh;
770
771    ------------------------------------
772    -- Resynchronization After Errors --
773    ------------------------------------
774
775    --  These procedures are used to resynchronize after errors. Following an
776    --  error which is not immediately locally recoverable, the exception
777    --  Error_Resync is raised. The handler for Error_Resync typically calls
778    --  one of these recovery procedures to resynchronize the source position
779    --  to a point from which parsing can be restarted.
780
781    --  Note: these procedures output an information message that tokens are
782    --  being skipped, but this message is output only if the option for
783    --  Multiple_Errors_Per_Line is set in Options.
784
785    package Sync is
786
787       procedure Resync_Choice;
788       --  Used if an error occurs scanning a choice. The scan pointer is
789       --  advanced to the next vertical bar, arrow, or semicolon, whichever
790       --  comes first. We also quit if we encounter an end of file.
791
792       procedure Resync_Expression;
793       --  Used if an error is detected during the parsing of an expression.
794       --  It skips past tokens until either a token which cannot be part of
795       --  an expression is encountered (an expression terminator), or if a
796       --  comma or right parenthesis or vertical bar is encountered at the
797       --  current parenthesis level (a parenthesis level counter is maintained
798       --  to carry out this test).
799
800       procedure Resync_Past_Semicolon;
801       --  Used if an error occurs while scanning a sequence of declarations.
802       --  The scan pointer is positioned past the next semicolon and the scan
803       --  resumes. The scan is also resumed on encountering a token which
804       --  starts a declaration (but we make sure to skip at least one token
805       --  in this case, to avoid getting stuck in a loop).
806
807       procedure Resync_To_Semicolon;
808       --  Similar to Resync_Past_Semicolon, except that the scan pointer is
809       --  left pointing to the semicolon rather than past it.
810
811       procedure Resync_Past_Semicolon_Or_To_Loop_Or_Then;
812       --  Used if an error occurs while scanning a sequence of statements.
813       --  The scan pointer is positioned past the next semicolon, or to the
814       --  next occurrence of either then or loop, and the scan resumes.
815
816       procedure Resync_To_When;
817       --  Used when an error occurs scanning an entry index specification.
818       --  The scan pointer is positioned to the next WHEN (or to IS or
819       --  semicolon if either of these appear before WHEN, indicating
820       --  another error has occurred).
821
822       procedure Resync_Semicolon_List;
823       --  Used if an error occurs while scanning a parenthesized list of items
824       --  separated by semicolons. The scan pointer is advanced to the next
825       --  semicolon or right parenthesis at the outer parenthesis level, or
826       --  to the next is or RETURN keyword occurence, whichever comes first.
827
828       procedure Resync_Cunit;
829       --  Synchronize to next token which could be the start of a compilation
830       --  unit, or to the end of file token.
831
832    end Sync;
833
834    -------------------------
835    -- Token Scan Routines --
836    -------------------------
837
838    --  Routines to check for expected tokens
839
840    package Tchk is
841
842       --  Procedures with names of the form T_xxx, where Tok_xxx is a token
843       --  name, check that the current token matches the required token, and
844       --  if so, scan past it. If not, an error is issued indicating that
845       --  the required token is not present (xxx expected). In most cases, the
846       --  scan pointer is not moved in the not-found case, but there are some
847       --  exceptions to this, see for example T_Id, where the scan pointer is
848       --  moved across a literal appearing where an identifier is expected.
849
850       procedure T_Abort;
851       procedure T_Arrow;
852       procedure T_At;
853       procedure T_Body;
854       procedure T_Box;
855       procedure T_Colon;
856       procedure T_Colon_Equal;
857       procedure T_Comma;
858       procedure T_Dot_Dot;
859       procedure T_For;
860       procedure T_Greater_Greater;
861       procedure T_Identifier;
862       procedure T_In;
863       procedure T_Is;
864       procedure T_Left_Paren;
865       procedure T_Loop;
866       procedure T_Mod;
867       procedure T_New;
868       procedure T_Of;
869       procedure T_Or;
870       procedure T_Private;
871       procedure T_Range;
872       procedure T_Record;
873       procedure T_Right_Paren;
874       procedure T_Semicolon;
875       procedure T_Then;
876       procedure T_Type;
877       procedure T_Use;
878       procedure T_When;
879       procedure T_With;
880
881       --  Procedures have names of the form TF_xxx, where Tok_xxx is a token
882       --  name check that the current token matches the required token, and
883       --  if so, scan past it. If not, an error message is issued indicating
884       --  that the required token is not present (xxx expected).
885
886       --  If the missing token is at the end of the line, then control returns
887       --  immediately after posting the message. If there are remaining tokens
888       --  on the current line, a search is conducted to see if the token
889       --  appears later on the current line, as follows:
890
891       --  A call to Scan_Save is issued and a forward search for the token
892       --  is carried out. If the token is found on the current line before a
893       --  semicolon, then it is scanned out and the scan continues from that
894       --  point. If not the scan is restored to the point where it was missing.
895
896       procedure TF_Arrow;
897       procedure TF_Is;
898       procedure TF_Loop;
899       procedure TF_Return;
900       procedure TF_Semicolon;
901       procedure TF_Then;
902       procedure TF_Use;
903
904    end Tchk;
905
906    ----------------------
907    -- Utility Routines --
908    ----------------------
909
910    package Util is
911
912       function Bad_Spelling_Of (T : Token_Type) return Boolean;
913       --  This function is called in an error situation. It checks if the
914       --  current token is an identifier whose name is a plausible bad
915       --  spelling of the given keyword token, and if so, issues an error
916       --  message, sets Token from T, and returns True. Otherwise Token is
917       --  unchanged, and False is returned.
918
919       procedure Check_Bad_Layout;
920       --  Check for bad indentation in RM checking mode. Used for statements
921       --  and declarations. Checks if current token is at start of line and
922       --  is exdented from the current expected end column, and if so an
923       --  error message is generated.
924
925       procedure Check_Misspelling_Of (T : Token_Type);
926       pragma Inline (Check_Misspelling_Of);
927       --  This is similar to the function above, except that it does not
928       --  return a result. It is typically used in a situation where any
929       --  identifier is an error, and it makes sense to simply convert it
930       --  to the given token if it is a plausible misspelling of it.
931
932       procedure Check_95_Keyword (Token_95, Next : Token_Type);
933       --  This routine checks if the token after the current one matches the
934       --  Next argument. If so, the scan is backed up to the current token
935       --  and Token_Type is changed to Token_95 after issuing an appropriate
936       --  error message ("(Ada 83) keyword xx cannot be used"). If not,
937       --  the scan is backed up with Token_Type unchanged. This routine
938       --  is used to deal with an attempt to use a 95 keyword in Ada 83
939       --  mode. The caller has typically checked that the current token,
940       --  an identifier, matches one of the 95 keywords.
941
942       procedure Check_Simple_Expression (E : Node_Id);
943       --  Given an expression E, that has just been scanned, so that Expr_Form
944       --  is still set, outputs an error if E is a non-simple expression. E is
945       --  not modified by this call.
946
947       procedure Check_Simple_Expression_In_Ada_83 (E : Node_Id);
948       --  Like Check_Simple_Expression, except that the error message is only
949       --  given when operating in Ada 83 mode, and includes "in Ada 83".
950
951       function Check_Subtype_Mark (Mark : Node_Id) return Node_Id;
952       --  Called to check that a node representing a name (or call) is
953       --  suitable for a subtype mark, i.e, that it is an identifier or
954       --  a selected component. If so, or if it is already Error, then
955       --  it is returned unchanged. Otherwise an error message is issued
956       --  and Error is returned.
957
958       function Comma_Present return Boolean;
959       --  Used in comma delimited lists to determine if a comma is present, or
960       --  can reasonably be assumed to have been present (an error message is
961       --  generated in the latter case). If True is returned, the scan has been
962       --  positioned past the comma. If False is returned, the scan position
963       --  is unchanged. Note that all comma-delimited lists are terminated by
964       --  a right paren, so the only legitimate tokens when Comma_Present is
965       --  called are right paren and comma. If some other token is found, then
966       --  Comma_Present has the job of deciding whether it is better to pretend
967       --  a comma was present, post a message for a missing comma and return
968       --  True, or return False and let the caller diagnose the missing right
969       --  parenthesis.
970
971       procedure Discard_Junk_Node (N : Node_Id);
972       procedure Discard_Junk_List (L : List_Id);
973       pragma Inline (Discard_Junk_Node);
974       pragma Inline (Discard_Junk_List);
975       --  These procedures do nothing at all, their effect is simply to discard
976       --  the argument. A typical use is to skip by some junk that is not
977       --  expected in the current context.
978
979       procedure Ignore (T : Token_Type);
980       --  If current token matches T, then give an error message and skip
981       --  past it, otherwise the call has no effect at all. T may be any
982       --  reserved word token, or comma, left or right paren, or semicolon.
983
984       function Is_Reserved_Identifier (C : Id_Check := None) return Boolean;
985       --  Test if current token is a reserved identifier. This test is based
986       --  on the token being a keyword and being spelled in typical identifier
987       --  style (i.e. starting with an upper case letter). The parameter C
988       --  determines the special treatment if a reserved word is encountered
989       --  that has the normal casing of a reserved word.
990
991       procedure Merge_Identifier (Prev : Node_Id; Nxt : Token_Type);
992       --  Called when the previous token is an identifier (whose Token_Node
993       --  value is given by Prev) to check if current token is an identifier
994       --  that can be merged with the previous one adding an underscore. The
995       --  merge is only attempted if the following token matches Nxt. If all
996       --  conditions are met, an error message is issued, and the merge is
997       --  carried out, modifying the Chars field of Prev.
998
999       procedure No_Constraint;
1000       --  Called in a place where no constraint is allowed, but one might
1001       --  appear due to a common error (e.g. after the type mark in a procedure
1002       --  parameter. If a constraint is present, an error message is posted,
1003       --  and the constraint is scanned and discarded.
1004
1005       function No_Right_Paren (Expr : Node_Id) return Node_Id;
1006       --  Function to check for no right paren at end of expression, returns
1007       --  its argument if no right paren, else flags paren and returns Error.
1008
1009       procedure Push_Scope_Stack;
1010       pragma Inline (Push_Scope_Stack);
1011       --  Push a new entry onto the scope stack. Scope.Last (the stack pointer)
1012       --  is incremented. The Junk field is preinitialized to False. The caller
1013       --  is expected to fill in all remaining entries of the new new top stack
1014       --  entry at Scope.Table (Scope.Last).
1015
1016       procedure Pop_Scope_Stack;
1017       --  Pop an entry off the top of the scope stack. Scope_Last (the scope
1018       --  table stack pointer) is decremented by one. It is a fatal error to
1019       --  try to pop off the dummy entry at the bottom of the stack (i.e.
1020       --  Scope.Last must be non-zero at the time of call).
1021
1022       function Separate_Present return Boolean;
1023       --  Determines if the current token is either Tok_Separate, or an
1024       --  identifier that is a possible misspelling of "separate" followed
1025       --  by a semicolon. True is returned if so, otherwise False.
1026
1027       procedure Signal_Bad_Attribute;
1028       --  The current token is an identifier that is supposed to be an
1029       --  attribute identifier but is not. This routine posts appropriate
1030       --  error messages, including a check for a near misspelling.
1031
1032       function Token_Is_At_Start_Of_Line return Boolean;
1033       pragma Inline (Token_Is_At_Start_Of_Line);
1034       --  Determines if the current token is the first token on the line
1035
1036       function Token_Is_At_End_Of_Line return Boolean;
1037       --  Determines if the current token is the last token on the line
1038
1039    end Util;
1040
1041    ---------------------------------------
1042    -- Specialized Syntax Check Routines --
1043    ---------------------------------------
1044
1045    function Prag (Pragma_Node : Node_Id; Semi : Source_Ptr) return Node_Id;
1046    --  This function is passed a tree for a pragma that has been scanned out.
1047    --  The pragma is syntactically well formed according to the general syntax
1048    --  for pragmas and the pragma identifier is for one of the recognized
1049    --  pragmas. It performs specific syntactic checks for specific pragmas.
1050    --  The result is the input node if it is OK, or Error otherwise. The
1051    --  reason that this is separated out is to facilitate the addition
1052    --  of implementation defined pragmas. The second parameter records the
1053    --  location of the semicolon following the pragma (this is needed for
1054    --  correct processing of the List and Page pragmas). The returned value
1055    --  is a copy of Pragma_Node, or Error if an error is found. Note that
1056    --  at the point where Prag is called, the right paren ending the pragma
1057    --  has been scanned out, and except in the case of pragma Style_Checks,
1058    --  so has the following semicolon. For Style_Checks, the caller delays
1059    --  the scanning of the semicolon so that it will be scanned using the
1060    --  settings from the Style_Checks pragma preceding it.
1061
1062    -------------------------
1063    -- Subsidiary Routines --
1064    -------------------------
1065
1066    procedure Labl;
1067    --  This procedure creates implicit label declarations for all label that
1068    --  are declared in the current unit. Note that this could conceptually
1069    --  be done at the point where the labels are declared, but it is tricky
1070    --  to do it then, since the tree is not hooked up at the point where the
1071    --  label is declared (e.g. a sequence of statements is not yet attached
1072    --  to its containing scope at the point a label in the sequence is found)
1073
1074    procedure Load;
1075    --  This procedure loads all subsidiary units that are required by this
1076    --  unit, including with'ed units, specs for bodies, and parents for child
1077    --  units. It does not load bodies for inlined procedures and generics,
1078    --  since we don't know till semantic analysis is complete what is needed.
1079
1080    -----------
1081    -- Stubs --
1082    -----------
1083
1084    --  The package bodies can see all routines defined in all other subpackages
1085
1086    use Ch2;
1087    use Ch3;
1088    use Ch4;
1089    use Ch5;
1090    use Ch6;
1091    use Ch7;
1092    use Ch8;
1093    use Ch9;
1094    use Ch10;
1095    use Ch11;
1096    use Ch12;
1097    use Ch13;
1098
1099    use Endh;
1100    use Tchk;
1101    use Sync;
1102    use Util;
1103
1104    package body Ch2 is separate;
1105    package body Ch3 is separate;
1106    package body Ch4 is separate;
1107    package body Ch5 is separate;
1108    package body Ch6 is separate;
1109    package body Ch7 is separate;
1110    package body Ch8 is separate;
1111    package body Ch9 is separate;
1112    package body Ch10 is separate;
1113    package body Ch11 is separate;
1114    package body Ch12 is separate;
1115    package body Ch13 is separate;
1116
1117    package body Endh is separate;
1118    package body Tchk is separate;
1119    package body Sync is separate;
1120    package body Util is separate;
1121
1122    function Prag (Pragma_Node : Node_Id; Semi : Source_Ptr) return Node_Id
1123      is separate;
1124
1125    procedure Labl is separate;
1126    procedure Load is separate;
1127
1128    ---------
1129    -- Par --
1130    ---------
1131
1132 --  This function is the parse routine called at the outer level. It parses
1133 --  the current compilation unit and adds implicit label declarations.
1134
1135 begin
1136    --  Deal with configuration pragmas case first
1137
1138    if Configuration_Pragmas then
1139       declare
1140          Ecount  : constant Int     := Serious_Errors_Detected;
1141          Pragmas : constant List_Id := Empty_List;
1142          P_Node  : Node_Id;
1143
1144       begin
1145          loop
1146             if Token = Tok_EOF then
1147                return Pragmas;
1148
1149             elsif Token /= Tok_Pragma then
1150                Error_Msg_SC ("only pragmas allowed in configuration file");
1151                return Error_List;
1152
1153             else
1154                P_Node := P_Pragma;
1155
1156                if Serious_Errors_Detected > Ecount then
1157                   return Error_List;
1158                end if;
1159
1160                if Chars (P_Node) > Last_Configuration_Pragma_Name
1161                  and then Chars (P_Node) /= Name_Source_Reference
1162                then
1163                   Error_Msg_SC
1164                     ("only configuration pragmas allowed " &
1165                      "in configuration file");
1166                   return Error_List;
1167                end if;
1168
1169                Append (P_Node, Pragmas);
1170             end if;
1171          end loop;
1172       end;
1173
1174    --  Normal case of compilation unit
1175
1176    else
1177       Save_Opt_Config_Switches (Save_Config_Switches);
1178
1179       --  Special processing for language defined units. For this purpose
1180       --  we do NOT consider the renamings in annex J as predefined. That
1181       --  allows users to compile their own versions of these files, and
1182       --  in particular, in the VMS implementation, the DEC versions can
1183       --  be substituted for the standard Ada 95 versions.
1184
1185       if Is_Predefined_File_Name
1186            (Fname => File_Name (Current_Source_File),
1187             Renamings_Included => False)
1188       then
1189          Set_Opt_Config_Switches
1190            (Is_Internal_File_Name (File_Name (Current_Source_File)));
1191
1192          --  If this is the main unit, disallow compilation unless the -gnatg
1193          --  (GNAT mode) switch is set (from a user point of view, the rule is
1194          --  that language defined units cannot be recompiled).
1195
1196          --  However, an exception is s-rpc, and its children. We test this
1197          --  by looking at the character after the minus, the rule is that
1198          --  System.RPC and its children are the only children in System
1199          --  whose second level name can start with the letter r.
1200
1201          Get_Name_String (File_Name (Current_Source_File));
1202
1203          if (Name_Len < 3 or else Name_Buffer (1 .. 3) /= "s-r")
1204            and then Current_Source_Unit = Main_Unit
1205            and then not GNAT_Mode
1206            and then Operating_Mode = Generate_Code
1207          then
1208             Error_Msg_SC ("language defined units may not be recompiled");
1209          end if;
1210       end if;
1211
1212       --  The following loop runs more than once only in syntax check mode
1213       --  where we allow multiple compilation units in the same file.
1214
1215       loop
1216          Set_Opt_Config_Switches
1217            (Is_Internal_File_Name (File_Name (Current_Source_File)));
1218
1219          --  Initialize scope table and other parser control variables
1220
1221          Compiler_State := Parsing;
1222          Scope.Init;
1223          Scope.Increment_Last;
1224          Scope.Table (0).Etyp := E_Dummy;
1225          SIS_Entry_Active := False;
1226          Last_Resync_Point := No_Location;
1227
1228          Label_List := New_Elmt_List;
1229          Discard_Node (P_Compilation_Unit);
1230
1231          --  If we are not at an end of file, then this means that we are
1232          --  in syntax scan mode, and we can have another compilation unit,
1233          --  otherwise we will exit from the loop.
1234
1235          exit when Token = Tok_EOF;
1236          Restore_Opt_Config_Switches (Save_Config_Switches);
1237       end loop;
1238
1239       --  Now that we have completely parsed the source file, we can
1240       --  complete the source file table entry.
1241
1242       Complete_Source_File_Entry;
1243
1244       --  An internal error check, the scope stack should now be empty
1245
1246       pragma Assert (Scope.Last = 0);
1247
1248       --  Remaining steps are to create implicit label declarations and to
1249       --  load required subsidiary sources. These steps are required only
1250       --  if we are doing semantic checking.
1251
1252       if Operating_Mode /= Check_Syntax or else Debug_Flag_F then
1253          Par.Labl;
1254          Par.Load;
1255       end if;
1256
1257       --  Restore settings of switches saved on entry
1258
1259       Restore_Opt_Config_Switches (Save_Config_Switches);
1260       Set_Comes_From_Source_Default (False);
1261       return Empty_List;
1262    end if;
1263
1264 end Par;