source: trunk/yao/share/antlr-2.7.7/examples/python/columns/columns.g @ 1

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

Initial import of YAO sources

File size: 1.3 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
6header "Lexer.__main__" {
7// main - create and run lexer from stdin
8if __name__ == "__main__":
9    import sys
10    import antlr
11    import columns_l
12   
13    // create lexer - shall read from stdin
14    L = columns_l.Lexer()
15   
16    try:
17        token = L.nextToken()
18        while not token.isEOF():
19            print token
20            token = L.nextToken()
21   
22    except antlr.TokenStreamException, e:
23        print "error: exception caught while lexing:", e
24   
25    // end of main
26}
27
28options {
29    language=Python;
30}
31// not working: Lexer not seen at this place ..
32// {
33//    if __name__ == "__main__":
34//      import columns_l
35//      Lexer.main()
36
37// }
38class columns_l extends Lexer;
39
40{
41    done = False;
42
43    def uponEOF(self):
44        done=True
45
46    def tab(self):
47       t = 4;
48       c = self.getColumn();
49       nc = (((c-1)/t)+1)*t+1;
50       self.setColumn( nc )
51
52    def main():
53       lexer = columns_l.Lexer()
54       while not Lexer.done:
55           t = lexer.nextToken();
56           print "Token: ",t
57
58    main = staticmethod(main)
59}
60
61INT : ('0'..'9')+ ;
62
63ID : ('a'..'z')+ ;
64
65WS : (' '|'\t'|'\n'{ self.newline();})+ {$setType(SKIP)}
66   ;
Note: See TracBrowser for help on using the repository browser.