DEFINITION MODULE NFAPattern;
This module provides a simulator for a non-deterministic finite au-
tomaton produced by one of the program which make up the Pattern
system. The modules may be inter-changed in a program by merely
changing the names of the procedures. (The exception to this is a
machine generated definition of the finite automaton, which must
be exchanged in the source program.) No implementation details
are described here, interested parties should see the appropriate
section of the full description of the Pattern system.
Neither module makes any claim to be a full fledged lexical ana-
lyzer. They are merely exaggerated pattern matchers, which can
serve as the base of a lexical analyzer.
FROM FileSystem IMPORT File;
AcceptingMarker = MAX (CARDINAL);
InvalidMarker = MAX (CARDINAL) - 1;
EndMarker = MAX (CARDINAL);
EmptyTransition = 377C;
These constants are for use by the mechanical code generator
NFA2TXT. Naturally, one should not try to take advantage of the
StateRecord = RECORD
next1,next2 : CARDINAL;
char : CHAR;
END; (* StateRecord *)
This represents the definition of a single state. It is included
here for information only, and should not be used by any program.
lastLexeme : ARRAY [0..255] OF CHAR;
This array holds the last lexeme matched by ReadPattern, it should
be considered read-only, although changing it will not affect the
operation of the module.
NFAPattern - 1
PROCEDURE DefineConstant (num,start : CARDINAL);
PROCEDURE DefineState (num,n1,n2 : CARDINAL; ch : CHAR);
Both DefineConstant and DefineState are included for the use of me-
chanically created NFA definitions. Because their use is imple-
mentation dependent, they should only be used with files created
by the NFA2TXT program.
This procedure resets the information concerning the current NFA in
use. It must be called before the definition of a NFA, but it is
called automatically by ReadNFAFromDisk and by mechanically cre-
ated code from NFA2TXT.
PROCEDURE ReadPattern (VAR num : CARDINAL);
This procedure activates the NFA simulator. It will return the num-
ber of the pattern it finds (as determined by the LEX2NFA pro-
gram), or 65535 if it cannot match any pattern.
PROCEDURE ReadNFAFromDisk (VAR f : File);
This procedure can be used to replace the current NFA (if any) with
the NFA represented by the information in the file. It will re-
turn when the NFA has been successfully read, or when a disk error
NFAPattern - 2