home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
549b.lha
/
M2P_v1.0_sources
/
source.lzh
/
LexAn.mpp
< prev
Wrap
Text File
|
1991-08-10
|
5KB
|
162 lines
(*======================================================================*)
(* Modula-2 Lexical Analyzer *)
(*======================================================================*)
(* Version: 1.00 Author: Dennis Brueni *)
(* Date: 07-07-91 Changes: original *)
(*======================================================================*)
(* The lexical analyzer proper resides in two separate modules. *)
(* *)
(* (1) LexAn Your lookin' at it. *)
(* *)
(* (2) FSM The Heart of the Beast. The implememtation of *)
(* of the Finite State Machine. *)
(*======================================================================*)
IMPLEMENTATION MODULE LexAn;
IMPORT FIO,Strings,SymLists,MacLists,SymTab,FSM;
@INCLUDE "MACROS"
(*----------------------------------------------------------------------*)
VAR MacroList: SymLists.SymList;
(*----------------------------------------------------------------------*)
@LongAddressing
@NoCopyStrings
PROCEDURE SetSourceFile(FileName: ARRAY OF CHAR):BOOLEAN;
BEGIN
FSM.SourceFile := FIO.Open(FileName);
IF NOT FIO.GoodFILE(FSM.SourceFile) THEN
FSM.SourceFile := FIO.INPUT;
RETURN FALSE;
ELSE
RETURN TRUE;
END;
END SetSourceFile;
(*----------------------------------------------------------------------*)
@NoCopyStrings
PROCEDURE SetDestFile(FileName: ARRAY OF CHAR):BOOLEAN;
BEGIN
FSM.DestFile := FIO.Create(FileName);
IF NOT FIO.GoodFILE(FSM.DestFile) THEN
FSM.DestFile := FIO.OUTPUT;
RETURN FALSE;
ELSE
RETURN TRUE;
END;
END SetDestFile;
(*----------------------------------------------------------------------*)
@NoLongAddressing
PROCEDURE FeedMacro(list: SymLists.SymList);
VAR temp: SymLists.SymList;
BEGIN
temp:=MacroList;
MacroList:=SymLists.ConCat(list,temp);
SymLists.Destroy(temp);
END FeedMacro;
(*----------------------------------------------------------------------*)
PROCEDURE GetToken;
VAR temp: MacLists.TokRecPtr;
retry:BOOLEAN;
PROCEDURE GetNext(VAR temp: MacLists.TokRecPtr):BOOLEAN;
BEGIN
IF SymLists.Empty(MacroList) THEN
RETURN FALSE;
ELSE;
temp:=SymLists.First(MacroList);
SymLists.Delete(MacroList,temp^.sym^);
RETURN TRUE;
END;
END GetNext;
BEGIN
retry:=FALSE;
IF GetNext(temp) THEN
WHILE (temp^.typ=FSM.M2KillArg) AND GetNext(temp) DO
SymTab.Delete(temp^.sym^);
retry:=NOT GetNext(temp);
END;
IF retry THEN
FSM.GetBSU;
ELSE
WITH temp^ DO
WITH FSM.Token DO
Strings.Assign(sym^,String);
Class:=typ;
Length:=len;
END;
END;
END;
ELSE
FSM.GetBSU;
END;
@IF DEBUG THEN
IF PrintTokens THEN PrintToken(FSM.Token); END;
@END
END GetToken;
(*----------------------------------------------------------------------*)
@LongAddressing
PROCEDURE PrintToken(VAR Tok : FSM.TokenRec);
VAR i: CARDINAL;
@IF DEBUG THEN
PROCEDURE StringOut(VAR Str: ARRAY OF CHAR);
BEGIN
FIO.WriteChar(FIO.OUTPUT,47C);
FIO.WriteString(FIO.OUTPUT,Str);
FIO.WriteChar(FIO.OUTPUT,47C);
END StringOut;
BEGIN
WITH Tok DO
FIO.WriteString(FIO.OUTPUT,' ');
FIO.WriteString(FIO.OUTPUT,FSM.Strings[Class]);
FOR i:= Strings.Length(FSM.Strings[Class]) TO 12 DO
FIO.WriteChar(FIO.OUTPUT,' ');
END;
CASE Class OF
FSM.M2ID,
FSM.M2Str,
FSM.M2String:StringOut(String);
|FSM.M2ch: StringOut(String);
FIO.WriteString(FIO.OUTPUT,' = ORD(');
FIO.WriteCard(FIO.OUTPUT,ORD(String[0]));
FIO.WriteChar(FIO.OUTPUT,')');
ELSE
FIO.WriteString(FIO.OUTPUT,String);
END;
FIO.WriteLn(FIO.OUTPUT);
END;
@ELSE
BEGIN
@END
END PrintToken;
(************************************************************************)
BEGIN
SymLists.Create(MacroList);
@IF DEBUG THEN
PrintTokens:=FALSE;
@END
END LexAn.