[antlr-interest] Writing Delphi Target for Antlr3
service
service at sharpplus.com
Sat May 26 00:37:17 PDT 2007
Dear Friends
I am now writing Delphi Target for Antlr 3 . now I encounter a problem .Delphi unlike the other language (Java, C#, etc). it can not declare one variable at function body.
for example:
In Java, you can declare int alt1 in function body
// $ANTLR start IDENTIFIER
public final void mIDENTIFIER() throws RecognitionException {
try {
int _type = IDENTIFIER;
// C.g:12:4: ( LETTER ( LETTER | '0' .. '9' )* )
// C.g:12:4: LETTER ( LETTER | '0' .. '9' )*
{
mLETTER();
// C.g:12:11: ( LETTER | '0' .. '9' )*
loop1:
do {
int alt1=2;
int LA1_0 = input.LA(1);
if ( (LA1_0=='$'||(LA1_0>='0' && LA1_0<='9')||(LA1_0>='A' && LA1_0<='Z')||LA1_0=='_'||(LA1_0>='a' && LA1_0<='z')) ) {
alt1=1;
}
but in Delphi, you must declare it in var section like below
procedure TCLexer.mIDENTIFIER();
var
_type:Integer;
alt1:Integer; <======must declare it at var section
LA1_0 :Char;
begin
try
_type := IDENTIFIER;
// ruleBlockSingleAlt:C.g:12:4: ( LETTER ( LETTER | '0' .. '9' )* )
// C.g:12:4: LETTER ( LETTER | '0' .. '9' )*
begin
mLETTER();
// closureBlock:C.g:12:11: ( LETTER | '0' .. '9' )*
repeat
alt1:=2;
LA1_0 := input.LA(1);
if ( ((LA1_0='$') or ((LA1_0>='0') and ( LA1_0<='9')) or ((LA1_0>='A') and ( LA1_0<='Z')) or (LA1_0='_') or ((LA1_0>='a') and ( LA1_0<='z'))) ) then begin
alt1:=1;
end;
But I look the string template , I found in the lexerRule template, there is no decisionNumber parameter, then I try to use the block.decisionNumber like below
lexerRule(name, ruleName,nakedBlock,ruleDescriptor,block,memoize) ::= <<
// $ANTLR start <ruleName>
procedure T<name>.m<ruleName>(<ruleDescriptor.parameterScope:parameterScope(scope=it)>);
var
_type:Integer;
alt<block.decisionNumber>}>:Integer; <====== I try to get the block decisionNumber
begin
<if(trace)>traceIn("<ruleName>", <ruleDescriptor.index>);<endif>
<ruleDeclarations()>
try
<if(nakedBlock)>
<ruleMemoization(name=ruleName)>
<lexerRuleLabelDefs()>
<ruleDescriptor.actions.init>
<block><\n>
<else>
_type := <ruleName>;
<ruleMemoization(name=ruleName)>
<lexerRuleLabelDefs()>
<ruleDescriptor.actions.init>
<block>
<ruleCleanUp()>
self._type := _type;
<(ruleDescriptor.actions.after):execAction()>
<endif>
finally
<if(trace)>traceOut("<ruleName>", <ruleDescriptor.index>);<endif>
<memoize()>
end;
end;
// $ANTLR end <ruleName>
>>
But it seems that sometimes block's decisionNumber is empty, and block can be embeded into other block so I can not get all DFA decisionnumber. now I want to know how to iterate all the blocks in rule to get their decisonNumber with stringtemplate?
Thanks in advance!
More information about the antlr-interest
mailing list