1grammar t046rewrite;
2options {
3    language=Cpp;
4}
5
6@lexer::includes
7{
8#include "UserTestTraits.hpp"
9}
10@lexer::namespace
11{ Antlr3Test }
12
13@parser::includes {
14#include "UserTestTraits.hpp"
15}
16@parser::namespace
17{ Antlr3Test }
18
19program
20@init {
21    start = self.input.LT(1)
22}
23    :   method+
24        {
25        self.input.insertBefore(start,"public class Wrapper {\n")
26        self.input.insertAfter($method.stop, "\n}\n")
27        }
28    ;
29
30method
31    :   m='method' ID '(' ')' body
32        {self.input.replace($m, "public void");}
33    ;
34
35body
36scope {
37    decls
38}
39@init {
40    $body::decls = set()
41}
42    :   lcurly='{' stat* '}'
43        {
44        for it in $body::decls:
45            self.input.insertAfter($lcurly, "\nint "+it+";")
46        }
47    ;
48
49stat:   ID '=' expr ';' {$body::decls.add($ID.text);}
50    ;
51
52expr:   mul ('+' mul)*
53    ;
54
55mul :   atom ('*' atom)*
56    ;
57
58atom:   ID
59    |   INT
60    ;
61
62ID  :   ('a'..'z'|'A'..'Z')+ ;
63
64INT :   ('0'..'9')+ ;
65
66WS  :   (' '|'\t'|'\n')+ {$channel=HIDDEN;}
67    ;
68