[antlr-interest] The most import questions for me about antlr?

John B. Brodie jbb at acm.org
Mon May 9 21:13:17 PDT 2005


Sir or Madam :-

You asked:
>1.
>     I want to make my new language..or call it a script, such as  
>python,ruby,lua,etc.
>and use the new language write a "program" and "run" it.
>please note, Not olny "parse" the program, but also "RUN" it!
>
>Can antlr help me?  I do think it can help me, but I do not know How to do.

Of course Antlr can help you in this endeavor.

>Would you like to tell me how to start? or give me a sample.

As a beginning, define your new language as a Context Free Grammar (CFG)
(in the sense of the Chomsky hierarchy). Probably best to divide this CFG
specification into 2 pieces:

   a) Lexical Analysis (e.g. use a Regular Language) which consumes
      characters and produces Tokens; and

   b) Syntax Analysis (e.g. use a Context Free Grammar in the LL(k) form)
      which consumes Tokens and produces an Abstract Syntax Tree (AST).

Next, specify a Tree Walker which traverses the AST produced by the Syntax
Analysis to perform a Semantic Analysis of the program to be run
(e.g. answer the question: is this a correct program?); this step should
probably transform the input AST into another AST suitable for
interpretation.

Finally, specify a Tree Walker which traverses the resultant semantically
correct AST to "run" the input program.

And so you end up with 4 Antlr specifications: a Lexer, a Parser, and 2
Tree Walkers.

>2.
>     I found a lot of grammar file(*.g) at www.antlr.org, but how to use it?
>If i can use the *.g to make my new language?

1) Use these grammar examples to learn more about what Antlr can do for you.

2) Extract appropriate snippets from these grammars to help you process
   your language.



Hope this helps...
   -jbb


More information about the antlr-interest mailing list