source: trunk/yao/share/antlr-2.7.7/examples/python/transform/transform.g

Last change on this file was 1, checked in by lnalod, 15 years ago

Initial import of YAO sources

File size: 1.1 KB
Line 
1// This file is part of PyANTLR. See LICENSE.txt for license
2// details..........Copyright (C) Wolfgang Haefelinger, 2004.
3//
4// $Id$
5
6options {
7    language=Python;
8}
9
10class transform_p extends Parser;
11options {
12    buildAST = true;    // uses CommonAST by default
13    ASTLabelType = "antlr.CommonAST";
14}
15
16expr
17    :   mexpr (PLUS^ mexpr)* SEMI!
18    ;
19
20mexpr
21    :   atom (STAR^ atom)*
22    ;
23
24atom:   INT
25    ;
26
27class transform_l extends Lexer;
28
29WS  :   (' '
30    |   '\t'
31    |   '\n'
32    |   '\r')
33        { $skip; }
34    ;
35
36LPAREN: '('
37    ;
38
39RPAREN: ')'
40    ;
41
42STAR:   '*'
43    ;
44
45PLUS:   '+'
46    ;
47
48SEMI:   ';'
49    ;
50
51protected
52DIGIT
53    :   '0'..'9'
54    ;
55
56INT :   (DIGIT)+
57    ;
58
59class transform_w extends TreeParser;
60options {
61    buildAST = true;
62    ASTLabelType = "antlr.CommonAST";
63}
64
65expr:!  #(PLUS left:expr right:expr)
66        {
67            if #right.getType()==INT and int(#right.getText()) == 0:
68                #expr = #left
69            elif #left.getType()==INT and int(#left.getText()) ==0:
70                #expr = #right;
71            else:
72                #expr = #(PLUS, left, right);
73        }
74    |   #(STAR expr expr)
75    |   i:INT
76    ;
Note: See TracBrowser for help on using the repository browser.