INTERFACEFriends interface forM3CLexF ;
M3CLex
IMPORT Rd; IMPORT M3AST_LX, M3CToken, M3CReservedWord, M3CHash, M3CLex; TYPE FriendPart = M3CLex.Public OBJECT rd: Rd.T := NIL; identifiers: M3CReservedWord.Table; literals: M3CHash.Table; cur_identifier: M3AST_LX.Symbol_rep := NIL; cur_literal: M3AST_LX.Literal_rep := NIL; line, offset, startOfToken, linesInToken: CARDINAL := 0; callBack: M3CLex.CallBack := NIL; tokenBuffer: Buffer; hashValue: M3CHash.Value := NIL; METHODS get(): CHAR RAISES {Rd.Failure, Rd.EndOfFile}; unget(ch: CHAR); readId(firstCh: CHAR): M3CToken.T RAISES {Rd.Failure}; readNumericLiteral(firstCh: CHAR): M3CToken.T RAISES {Rd.Failure}; readCharLiteral(wide: BOOLEAN): M3CToken.T RAISES {Rd.Failure}; readTextLiteral(wide: BOOLEAN): M3CToken.T RAISES {Rd.Failure}; readCommentOrPragma(isComment: BOOLEAN) RAISES {Rd.Failure}; END; REVEAL M3CLex.T <: FriendPart; CONST IsComment = TRUE; IsPragma = FALSE;The
get
method returns the next character from the lookahead buffer,
raising Rd.EndOfFile
if the stream is exhausted. unget(ch)
puts
ch
into the lookahead buffer, causing get
to return it the next time
it is called. Multiple calls without an intervening get
have no
effect.
The readId
method reads an identifier that begins with firstCh
.
If the identifier correspsonds to a reserved word, the associated
M3CToken.T
value is returned, otherwise M3CToken.T.Identifier
is returned and the identifier
field is set to the Symbol_rep
for the identifier.
The readNumericLiteral
method reads a numeric literal that starts
with firstCh, returning the appropriate value of M3CToken.T
, and
setting the literal
field to the Literal_rep
value for the
literal.
readCharLiteral
and readTextLiteral
read character literals and
text literals, respectively, and assume that the leading quote or
double-quote character has already been consumed. The value of the
literal
field is set to the Literal_rep
value for the literal.
readCommentOrPragma
assumes that the leading (
or <
character
has been consumed and tenh attempts to process the remainder of the
comment or pragma, calling the callback
method with the result.
Manipulating the token buffer directly. Call these procedures with
buffer
= t.tokenBuffer
.
TYPE Buffer <: REFANY; PROCEDURE BufferToText(buffer: Buffer; length: CARDINAL): TEXT RAISES {};
convertslength
chars frombuffer
to a TEXT and returns the result.
<*INLINE*> PROCEDURE BufferPut( VAR buffer: Buffer; pos: CARDINAL; ch: CHAR) RAISES {};
Storesch
as positionpos
inbuffer
, possibly adding an overflow area (hence VAR).
<*INLINE*> PROCEDURE HashAndBufferPut( ch: CHAR; hashValue: M3CHash.Value; VAR buffer: Buffer; VAR pos: CARDINAL) RAISES {};
AsBuffePut
, but also callsM3CHash.AddCharToValue(ch, hashValue)
and incrementspos
.
END M3CLexF.