home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
549a.lha
/
M2P_v1.0
/
mods.lzh
/
LexAn.mod
< prev
next >
Wrap
Text File
|
1991-08-10
|
3KB
|
167 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;
(*----------------------------------------------------------------------*)
VAR
MacroList: SymLists.SymList;
(*----------------------------------------------------------------------*)
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;
(*----------------------------------------------------------------------*)
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;
(*----------------------------------------------------------------------*)
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;
END GetToken;
(*----------------------------------------------------------------------*)
PROCEDURE PrintToken(VAR Tok : FSM.TokenRec);
VAR
i: CARDINAL;
BEGIN
END PrintToken;
(************************************************************************)
BEGIN
SymLists.Create(MacroList);
END LexAn.