FROM M2Error IMPORT ErrorStringAt, ErrorStringAt2, ErrorStringsAt2,
WriteFormat0, FlushErrors, FlushWarnings, ResetErrorScope ;
-FROM M2MetaError IMPORT MetaErrorString1, MetaError0, MetaError1 ;
+FROM M2MetaError IMPORT MetaErrorString0, MetaErrorString1, MetaError0, MetaError1, MetaString0 ;
FROM FormatStrings IMPORT Sprintf1 ;
FROM P0SymBuild IMPORT P0Init, P1Init ;
*)
PROCEDURE ExamineCompilationUnit (VAR name: ADDRESS; VAR isdefimp: BOOLEAN) ;
+VAR
+ Message: String ;
BEGIN
isdefimp := FALSE ; (* default to program module *)
(* stop if we see eof, ';' or '[' *)
END ;
GetToken
END ;
- m2flex.M2Error(string(InitString('failed to find module name'))) ;
- exit(1)
+ Message := MetaString0 (InitString ('no {%kMODULE} name found')) ;
+ m2flex.M2Error (string (Message)) ;
+ exit (1)
END ExamineCompilationUnit ;
name : ADDRESS ;
isdefimp: BOOLEAN ;
BEGIN
- IF OpenSource(s)
+ IF OpenSource (s)
THEN
- ExamineCompilationUnit(name, isdefimp) ;
+ ExamineCompilationUnit (name, isdefimp) ;
IF isdefimp
THEN
- SetMainModule(MakeImplementationSource(GetTokenNo(), makekey(name)))
+ SetMainModule (MakeImplementationSource (GetTokenNo (), makekey (name)))
ELSE
- SetMainModule(MakeProgramSource(GetTokenNo(), makekey(name)))
+ SetMainModule (MakeProgramSource (GetTokenNo (), makekey (name)))
END ;
CloseSource ;
ReInitialize
ELSE
- fprintf1(StdErr, 'failed to open %s\n', s) ;
- exit(1)
+ fprintf1 (StdErr, 'failed to open %s\n', s) ;
+ exit (1)
END
END PeepInto ;
ListOfTokens : ListDesc ;
CurrentTokNo : CARDINAL ;
InsertionIndex : CARDINAL ;
+ SeenEof : BOOLEAN ; (* Have we seen eof since the last call
+ to OpenSource. *)
(*
PROCEDURE Init ;
BEGIN
+ SeenEof := FALSE ;
InsertionIndex := 0 ;
currenttoken := eoftok ;
CurrentTokNo := InitialSourceToken ;
PROCEDURE OpenSource (s: String) : BOOLEAN ;
BEGIN
+ SeenEof := FALSE ;
IF UseBufferedTokens
THEN
GetToken ;
END DumpTokens ;
+(*
+ GetNonEofToken - providing that we have not already seen an eof for this source
+ file call m2flex.GetToken and GetToken if requested.
+*)
+
+PROCEDURE GetNonEofToken (callGetToken: BOOLEAN) ;
+BEGIN
+ IF SeenEof
+ THEN
+ currenttoken := eoftok
+ ELSE
+ (* Call the lexical phase to place a new token into the last bucket. *)
+ m2flex.GetToken () ;
+ IF callGetToken
+ THEN
+ GetToken
+ END
+ END
+END GetNonEofToken ;
+
+
(*
GetToken - gets the next token into currenttoken.
*)
ELSE
IF ListOfTokens.tail=NIL
THEN
- m2flex.GetToken () ;
+ GetNonEofToken (FALSE) ;
IF ListOfTokens.tail=NIL
THEN
HALT
END ;
IF CurrentTokNo>=ListOfTokens.LastBucketOffset
THEN
- (* CurrentTokNo is in the last bucket or needs to be read *)
+ (* CurrentTokNo is in the last bucket or needs to be read. *)
IF CurrentTokNo-ListOfTokens.LastBucketOffset<ListOfTokens.tail^.len
THEN
UpdateFromBucket (ListOfTokens.tail,
CurrentTokNo-ListOfTokens.LastBucketOffset)
ELSE
- (* call the lexical phase to place a new token into the last bucket *)
- m2flex.GetToken () ;
- GetToken ; (* and call ourselves again to collect the token from bucket *)
- RETURN
+ (* and call ourselves again to collect the token from bucket *)
+ GetNonEofToken (TRUE)
END
ELSE
t := CurrentTokNo ;
VAR
s: String ;
BEGIN
+ IF t = eoftok
+ THEN
+ SeenEof := TRUE
+ END ;
IF NOT ((t=eoftok) AND IsLastTokenEof())
THEN
AddTokToList(t, NulName, 0,