Hiya, been using Leon's gunit to test ANTLR's AST builder...works great!  I 
made a few improvements (for next v3 ANTLR release).  Here's a few samples:

grammarSpec:
    "parser grammar P; a : A;"
    -> (PARSER_GRAMMAR P (RULES (RULE a (BLOCK (ALT A)))))

    <<
    parser grammar P;
    options {k=2; output=AST;}
    scope S {int x}
    tokens { A; B='33'; }
    @header {foo}
    a : A;
    >>
    ->
    (PARSER_GRAMMAR P
    (OPTIONS (= k 2) (= output AST))
    (scope S {int x})
    (tokens { A (= B '33'))
    (@ header {foo})
    (RULES (RULE a (BLOCK (ALT A)))))

block:
        "( ^(A B) | ^(b C) )" -> (BLOCK (ALT ("^(" A B)) (ALT ("^(" b C)))
        
alternative:
        "x+=ID* -> $x*" ->
            (ALT_REWRITE
                    (ALT (* (BLOCK (ALT (+= x ID)))))
            (-> (ALT (* (BLOCK (ALT x))))))

        "A -> ..." -> (ALT_REWRITE (ALT A) (-> ...))
        "A -> "    -> (ALT_REWRITE (ALT A) (-> EPSILON))

element:
        "b+"            -> (+ (BLOCK (ALT b)))
        "(b)+"          -> (+ (BLOCK (ALT b)))
        "b?"            -> (? (BLOCK (ALT b)))
        "(b)?"          -> (? (BLOCK (ALT b)))
        "(b)*"          -> (* (BLOCK (ALT b)))
        "b*"            -> (* (BLOCK (ALT b)))
        "'while'*"      -> (* (BLOCK (ALT 'while')))
        "'a'+"          -> (+ (BLOCK (ALT 'a')))
        "a[3]"          -> (a 3)
        "'a'..'z'+" -> (+ (BLOCK (ALT (.. 'a' 'z'))))

Pretty cool, eh?

Ter

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to