[antlr-interest] antlr newbie question..
Zhou Shuo
Shuo.Zhou at haw-hamburg.de
Sat May 15 14:47:43 PDT 2010
Hi everyone!
I am an absolute newbie here and I would like to know if ANTLR is able to do the following job:
Say I have some code containing:
{
...
motor1_speed = 100; //assigned value can be arbitrary..
motor2_speed = 200;
...
}
And I need to translate it in:
{
...
motor.1.setSpeed(100);
motor.2.setSpeed(200);
...
}
For this task my professor has recommended me to use the lexer/parser combination tool and
for me ANTLR seems to be very promising . But after some research I still could not get an overview
about how to use ANTLR for this task... The tutorials/examples seem to be all about building some compilers..
Also I found something about the translation on the ANTLR homepage:
/*
@grammar
...
@@ to
<begin lang="grammar">
...
</end>
*/
GRAMMAR
: '@grammar' '\n'
{out.println("<begin lang=\"grammar\">");}
CODE_CHUNK
{out.println("</end>");}
;
EVERYTHING_ELSE
: c=. {out.print((char)c);}
;
As I have understood the code above will match
the keyword "grammar" and translate it into "<begin lang="grammar">" (Please correct me if i'm wrong..)
But in my case how would I be able to get the values(100, 200..) that are assigned to the variables..
Do I need to write all these lexer/parser files for the compilers as well o.O
I'm totally lost here....
I will be so grateful If anyone could give me some hints on this!
Or the best would be a simple example that might be able to solve the issue I mentioned in the beginning..
Well.. I know I'm asking too much..
Anyway..
Thanks all in advance!
Shuo
More information about the antlr-interest
mailing list