[antlr-interest] problems with label
Krishanu Debnath
krishanu.debnath at gmail.com
Mon Jan 17 06:40:30 PST 2005
Hello,
My grammer accepts keywords as a identifier. So I use the following identifier
rule in parser.
id returns [_return_type *idObj]
{
// initialized code
}
:
tId:ID
{
// retrieve the token that has been set in lexer using $setToken()
pIdObj = (_return_type *)... //label tId is used to
retrieve the _return_type node
}
// Followings are the keywords
| tIndex:"index"
{
// similar C++ code except it use label 'tIndex'
}
| tOut:"out"
{
// similar C++ code except it use label 'tOut'
}
// Other keywords
Now to avoid (keyword set is quite large)duplicate codes for each keyword,
I would like to have the 'id' rule as follows ..
id returns [_return_type *idObj]
{
// initialized code
}
:
tId:ID
{
// retrieve the token that has been set in lexer using $setToken()
pIdObj = (_return_type *)... //label tId is used to access
the _return_type node
}
|
// Followings are the keywords
(
tKeyword:""index"
| tKeyword:"out"
|
... // other keywords ..
)
{
// C++ code using label 'tKeyword'
}
But Antlr reports error 'already defined label tKeyword' for this. Is there any
options/work around available to by pass this error?
Krishanu
--
"When I have to rely on inadequacy, I prefer it to be my own."
--Richard Heathfield
More information about the antlr-interest
mailing list