echo - write one character to the output file *) (* Utility routines:
Utilities:
get_char - I/O routines:
The following routines get_char, unget_char and put_char are used to
implement access to the input and output files.
put_char - return one character to the input file to be reread in subsequent calls
to get_char
unget_char
reject - truncate yytext to size n and return the remaining characters to the
input stream
yyless
return - reject the current match and execute the next one *) (* reject does not actually cause the input to be rescanned; instead,
internal state information is used to find the next match.
returnc - return
start - sets the return value of yylex
returnc
unget_char - obtain one character from the input file (null character at end-of-
file)
get_char
yyclear - executes the default action (copy character); returns true unless
at end-of-file
yydefault
yydefault - finds the last match and the corresponding marked position and adjusts
the matched string accordingly; returns:
- true if a rule has been matched, false otherwise
- n: the number of the matched rule
yyfind
yyfind - declares a match for rule number n
yymatch
yyless - append the next match to the current one
yymore
yymark - gets next character from the input stream and updates yytext and
yyactchar accordingly
yyscan
yymatch - marks position for rule no.
yymore - echoes the current match to the output stream
echo
yynew - yylex return value
Internal routines:
yyscan - starts next match; initializes state information of the lexical
analyzer
yynew
yywrap - puts the lexical analyzer in the given start state; state=0 denotes
the default start state, other values are user-defined *) (* yywrap:
The yywrap function is called by yylex at end-of-file (unless you have
specified a rule matching end-of-file).
yyactchar
yycolno
yydone
yyinput
yylastchar
yyleng
yyline
yylineno
yyoutput
yyreject
yyretval
yyrule
yystate
yytext
procedure echo;
write one character to the output file *) (* Utility routines: Utilities:
function get_char : Char;
I/O routines:
The following routines get_char, unget_char and put_char are used to
implement access to the input and output files. Since \n (newline) for
Lex means line end, the I/O routines have to translate MS-DOS line ends
(carriage-return/line-feed) into newline characters and vice versa. Input
is buffered to allow rescanning text (via unput_char).
The input buffer holds the text of the line to be scanned. When the input
buffer empties, a new line is obtained from the input stream. Characters
can be returned to the input buffer by calls to unget_char. At end-of-
file a null character is returned.
The input routines also keep track of the input position and set the
yyline, yylineno, yycolno variables accordingly.
Since the rest of the Lex library only depends on these three routines
(there are no direct references to the yyinput and yyoutput files or
to the input buffer), you can easily replace get_char, unget_char and
put_char by another suitable set of routines, e.g. if you want to read
from/write to memory, etc. newline character
procedure put_char ( c : Char );
return one character to the input file to be reread in subsequent calls
to get_char unget_char
procedure reject;
truncate yytext to size n and return the remaining characters to the
input stream yyless
procedure return ( n : Integer );
reject the current match and execute the next one *) (* reject does not actually cause the input to be rescanned; instead,
internal state information is used to find the next match. Hence
you should not try to modify the input stream or the yytext variable
when rejecting a match. reject
procedure returnc ( c : Char );
return
procedure start ( state : Integer );
sets the return value of yylex returnc
procedure unget_char ( c : Char );
obtain one character from the input file (null character at end-of-
file) get_char
procedure yyclear;
executes the default action (copy character); returns true unless
at end-of-file yydefault
function yydefault : Boolean;
finds the last match and the corresponding marked position and adjusts
the matched string accordingly; returns:
- true if a rule has been matched, false otherwise
- n: the number of the matched rule yyfind
function yyfind ( var n : Integer ) : Boolean;
declares a match for rule number n yymatch
procedure yyless ( n : Integer );
append the next match to the current one yymore
procedure yymark ( n : Integer );
gets next character from the input stream and updates yytext and
yyactchar accordingly yyscan
procedure yymatch ( n : Integer );
marks position for rule no. n yymark
procedure yymore;
echoes the current match to the output stream echo
procedure yynew;
yylex return value Internal routines:
procedure yyscan;
starts next match; initializes state information of the lexical
analyzer yynew
function yywrap : Boolean;
puts the lexical analyzer in the given start state; state=0 denotes
the default start state, other values are user-defined *) (* yywrap:
The yywrap function is called by yylex at end-of-file (unless you have
specified a rule matching end-of-file). You may redefine this routine
in your Lex program to do application-dependent processing at end of
file. In particular, yywrap may arrange for more input and return false
in which case the yylex routine resumes lexical analysis. yywrap:
yyactchar : Char
current state of lexical analyzer
yycolno : Integer
yydone : Boolean
current match rejected?
yyinput : Text
The Lex library unit supplies a collection of variables and routines
needed by the lexical analyzer routine yylex and application programs
using Lex-generated lexical analyzers. It also provides access to the
input/output streams used by the lexical analyzer and the text of the
matched string, and provides some utility functions which may be used
in actions.
This `standard' version of the LexLib unit is used to implement lexical
analyzers which read from and write to MS-DOS files (using standard input
and output, by default). It is suitable for many standard applications
for lexical analyzers, such as text conversion tools or compilers.
However, you may create your own version of the LexLib unit, tailored to
your target applications. In particular, you may wish to provide another
set of I/O functions, e.g., if you want to read from or write to memory
instead to files, or want to use different file types. *) (* Variables:
The variable yytext contains the current match, yyleng its length.
The variable yyline contains the current input line, and yylineno and
yycolno denote the current input position (line, column). These values
are often used in giving error diagnostics (however, they will only be
meaningful if there is no rescanning across line ends).
The variables yyinput and yyoutput are the text files which are used
by the lexical analyzer. By default, they are assigned to standard
input and output, but you may change these assignments to fit your
target application (use the Turbo Pascal standard routines assign,
reset, and rewrite for this purpose).
yylastchar : Char
current character
yyleng : Byte (* length of matched text *)
absolute yytext
matched text (should be considered r/o)
yyline : String
input and output file
yylineno : Integer
current input line
yyoutput : Text
yyreject : Boolean
matched rule
yyretval : Integer
yylex return value set?
yyrule : Integer
last matched character (#0 if none)
yystate : Integer
The default yywrap routine supplied here closes input and output files
and returns true (causing yylex to terminate). *) (* The following are the internal data structures and routines used by the
lexical analyzer routine yylex; they should not be used directly.
yytext : String
current input position