27 March 2000 Release 2.22 Notes for New Users of PCCTS Version 1.33MR22
15
#66. Tokens are supplied as demanded by the parser. They are "pulled" rather than "pushed"
ANTLR
Parser::consume()
-->
ANTLR
TokenBuffer::getToken()
-->
ANTLR
TokenBuffer::get
ANTLR
Token()
-->
DLG
Lexer::getToken()
--> MyToken::makeToken(ANTLRtokenType,lexText,line)
#67. The lexer can access parser information using member function
getParser()
The member functions
ANTLR
TokenBuffer::getParser() and
DLG
LexerBase::getParser() return a pointer to the
current parser.
#68. Additional notes for users converting from C to C++ mode
In general:
zz
name
=>
name
,
_name
, or
name
()
example:
zzlextext
=> _lextext
,
lextext()
except for:
zzchar
=> ch
In
DLG
LexerBase:
NLA=tokenCode
=> return tokenCode
line++
=> newline()
line=value
=> _line=value
and
=> set_line(value)
set_line() is not available in vanilla 1.33
zztokens[
i
]
=>
parserClassName
::tokenName(
i
)
and
=> getParser()->parserTokenName(
i
)
tokenName() is not available in vanilla 1.33
parserTokenName is not available in vanilla 1.33
zzendcol
=> _endcol
,
set_endcol()
,
get_endcol()
zzbegcol
=> _begcol
,
set_begcol()
,
get_begcol()
#69. Use the macro
mytoken(
expr
)
to convert an
ANTLR
TokenPtr to an
ANTLR
Token *
#70. When using reference counted tokens be careful about saving a pointer generated by
myToken()
Reference counted tokens are deallocated when the reference count maintained by
ANTLR
TokenPtr reaches zero.
Saving a pointer generated by
mytoken()
subverts the reference counting scheme because the reference is not
counted. If such a pointer were stored in an AST it is likely that the token will soon be deallocated leaving you with
a pointer to garbage.
#71.
LA(
i
)
is a cache of
LT
(
i
)
values used by the parser - it is valid only for
i
k
Contributed by John Lilley (jlilley@empathy.com)
#72. To disable reference counting of
ANTLR
Tokens use
parserName
.noGarbageCollectTokens()
#73. For string input use
DLG
Stri
ngInput(const DLGChar *string)
for a
DLG
InputStream
#74. Use
#lexmember <<...>>
to insert code into the
DLG
Lexer class
#75. Use
#lexprefix <<...>>
to insert
#include
statements into the
DLG
Lexer file
#76. How to change the default error reporting actions of
DLG
and
ANTLR
For
DLG:
#lexmember <<
virtual ANTLRTokenType erraction() {
Your error action goes here.
Normally you'll want to end by calling the standard action:
return DLGLexerBase::erraction();
};
>>
For
ANTLR
, start by adding a virtual member function "syn" to your parser: