[antlr-interest] Best Approach/Suggestions?

Matthew Bowman matthew.bowman at sogotech.com
Thu Sep 13 03:41:25 PDT 2007


So here's my problem...

We're trying to construct a mini "scripting" which must support the 
following:

1. Functions (there is an exhaustive list that will be supported)

    - A()
    - B(x)
    - C(x,y)
    - D(x,y,z)

These functions will in the end result in a database query returning a 
number of (int,int) key-value pairs. The argument types can either be 
string or numerical.

2. Binary Operators

    - Numerical: + - * / ^
    - Logical: < > <= >= = != AND OR

3. Constants

    - Numerical: 0-9
    - Logical: TRUE FALSE (1 0 respectively)

Some examples would be something like

B(5) < B(10)
A > 9
D("foo",1,2) * 8
etc..

The final result of evaluating the tree will be the same type of 
(int,int) key-value pairs that are returned from a simple function.

So far we've managed to subclass CommonTree (using a simple grammar and 
the ! ^ tree operators) and construct an "evalutable" AST (using the 
TreeAdaptor) form which suffices. However, we've found scattered 
documentation regarding tree grammars and tree walkers and want to be 
sure we're heading in the right direction. Some questions we have are:

(a) What exactly is the difference between a "grammar" and a "tree grammar"?
(b) Where and how would you want to use a "tree walker"?
(c) Is it possible to use something other than CommonTree but still use 
the ANTLR tree construction operators?

Thanks in advance,
--Matthew
 


More information about the antlr-interest mailing list