Go to the first, previous, next, last section, table of contents.
The Lex interface provides procedures for reading strings, booleans,
integers, and floating-point numbers from an input stream. Similar
functionality on text strings is available from the "Scan" module
(see section Scan Interface).
The following constant sets are provided to define what characters Lex
considers 'blank' and 'nonblank':
CONST
Blanks = SET OF CHAR{
' ', '\t', '\n', '\r', '\013' vertical tab , '\f'};
NonBlanks = SET OF CHAR{'!' .. '~'};
Each of the procedures in this interface reads a sequence of characters
from the reader passed to the procedure, and leaves the reader
positioned immediately after that sequence, perhaps at end-of-file. You
may not use Rd.UnGetChar() after calling any of these routines.
- PROCEDURE Scan(rd: Rd.T; READONLY cs: SET OF CHAR := NonBlanks): TEXT
RAISES {Rd.Failure, Alerted};
- PROCEDURE Skip(rd: Rd.T; READONLY cs: SET OF CHAR := Blanks)
RAISES {Rd.Failure, Alerted};
- Read characters until one is found that is not in the character set "cs"
or EOF is reached.
Scan
returns characters read up but not
including the terminating character; Skip
discards them.
A common task in processing data from a reader involves throwing away
blanks. This can be accomplished with the call "Lex.Skip(rd, Blanks)"
or just "Lex.Skip(rd)".
- PROCEDURE Match(rd: Rd.T; t: TEXT) RAISES {Error, Rd.Failure, Alerted};
- Read the longest sequence of characters from "rd" that matches the
sequence of characters in "t". Raise "Error" if "t" is not completely
matched.
- PROCEDURE Bool(rd: Rd.T): BOOLEAN RAISES {Error, Rd.Failure, Alerted};
- Read a boolean from "rd" and return its value.
"Bool" skips blanks, then reads the longest sequence of "rd" that is
a sequence of a "Boolean" in the following grammar:
| Boolean = "F" "A" "L" "S" "E" | "T" "R" "U" "E".
The case of letters in a "Boolean" is not significant. If the
character sequence read from "rd" is an entire "Boolean", "Bool" returns that
boolean; else it raises "Error".
- PROCEDURE Int(rd: Rd.T; defaultBase: [2..16] := 10)
: INTEGER RAISES {Error, FloatMode.Trap, Rd.Failure, Alerted};
- PROCEDURE Unsigned(rd: Rd.T; defaultBase: [2..16] := 16)
: Word.T RAISES {Error, FloatMode.Trap, Rd.Failure, Alerted};
-
Read a number from "rd" and return its value.
- PROCEDURE Real(rd: Rd.T): REAL
RAISES {Error, FloatMode.Trap, Rd.Failure, Alerted};
- PROCEDURE LongReal(rd: Rd.T): LONGREAL
RAISES {Error, FloatMode.Trap, Rd.Failure, Alerted};
- PROCEDURE Extended(rd: Rd.T): EXTENDED
RAISES {Error, FloatMode.Trap, Rd.Failure, Alerted};
-
Read a real number from "rd" and return its value.
Go to the first, previous, next, last section, table of contents.