• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1parser grammar TParser;
2
3options {
4
5    // Default language but name it anyway
6    //
7    language  = Java;
8
9    // Produce an AST
10    //
11    output    = AST;
12
13    // Use a superclass to implement all helper
14    // methods, instance variables and overrides
15    // of ANTLR default methods, such as error
16    // handling.
17    //
18    superClass = AbstractTParser;
19
20    // Use the vocabulary generated by the accompanying
21    // lexer. Maven knows how to work out the relationship
22    // between the lexer and parser and will build the
23    // lexer before the parser. It will also rebuild the
24    // parser if the lexer changes.
25    //
26    tokenVocab = TLexer;
27}
28
29// Import a grammar file, even though it does not really need it in this
30// simle demo parser. We do the import to show where imported grammars should be
31// stored for maven builds.
32//
33import Ruleb;
34
35// Some imaginary tokens for tree rewrites
36//
37tokens {
38    SCRIPT;
39}
40
41// What package should the generated source exist in?
42//
43@header {
44
45    package ${package};
46}
47
48
49
50
51// This is just a simple parser for demo purpose
52//
53a  : b* EOF
54
55      -> ^(SCRIPT b*)
56   ;
57
58
59
60keyser
61   : KEYSER^ SOZE
62   ;
63
64expression
65   : addExpr (ADD^ addExpr)*
66   ;
67
68addExpr
69   : ID
70   | INT
71   | STRING
72   ;
73
74
75