[antlr-interest] target language independent action code
Arnulf Heller
aheller at gmx.at
Mon Jan 21 13:46:36 PST 2008
At 22:37 21.01.2008, you wrote:
>Arnulf Heller schrieb:
>>And realizing that most example grammars use Java as target
>>language (and action code) led me to this posting ...
>
>I'd like to point out that at the time of writing at least CSharp
>mimics every Java example. How C and ActionCode fare, I don't know
>but that counts puts Java examples - vs. examples in other languages
>- into the minority.
>
>Johannes
Hm. Interesting. Taking a look into CMinus.g, I can understand that
action code like
variable
: type declarator ';'
-> {$function.size()>0 && $function::name==null}?
globalVariable(type={$type.st},name={$declarator.st})
-> variable(type={$type.st},name={$declarator.st})
;
declarator
: ID -> {new StringTemplate($ID.text)}
;
will work on most target languages. Thats because Terence already did
the work in these cases (and I assume that there are hidden string
templates that translate that). ANTLR translates the $variable tokens
appropriately.
But I can not imagine that this works in C#, does it?
program
scope {
List globals;
List functions;
}
@init {
$program::globals = new ArrayList();
$program::functions = new ArrayList();
}
: declaration+
->
program(globals={$program::globals},functions={$program::functions})
;
If it does then C# is indeed just a reincarnation of Java (or should
I say relabel?) :-)
Arnulf
More information about the antlr-interest
mailing list