source: proto/RE2PBS/prototype_template.py @ 2192

Last change on this file since 2192 was 1167, checked in by ksherdy, 8 years ago

Refactor. Remove utility code from grammar.

File size: 1.3 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# prototype.py template
4#
5# Ken Herdy
6# April 20, 2010
7#
8#----------------------------------------------------------------------------
9#
10# (at)lex_strms - Lexical Item Streams.
11# (at)cc_code   - Character Class compiler equations.
12# (at)pbs_code  - Parallel bit stream equations.
13# (at)pbs_debug - Parallel bit stream debug statements.
14#
15#----------------------------------------------------------------------------
16
17import sys
18import bitutil
19
20u8data = ""
21lgth = 0
22
23class Basis_bits():
24        bit_0 = 0
25        bit_1 = 0
26        bit_2 = 0
27        bit_3 = 0 
28        bit_4 = 0
29        bit_5 = 0
30        bit_6 = 0
31        bit_7 = 0 
32 
33class Lex():
34@lex_strms 
35
36def Classify_bytes(basis_bits,lex):
37@cc_code
38        return lex
39
40def Demo(u8data, lex):
41
42        global lgth
43        lgth = len(u8data)
44@pbs_code
45@pbs_debug
46        return
47
48if __name__ == "__main__":
49        import doctest
50        doctest.testmod()
51
52        if len(sys.argv) < 2:
53                sys.stderr.write("Usage: python " + __file__ + " <filename>" "\n")
54                sys.exit(2)
55
56        u8data = bitutil.readfile(sys.argv[1])
57        (bits, EOF_mask) = bitutil.transpose_streams(u8data)
58       
59        basis_bits = Basis_bits()
60        basis_bits.bit_0 = bits[0]
61        basis_bits.bit_1 = bits[1]
62        basis_bits.bit_2 = bits[2]
63        basis_bits.bit_3 = bits[3]
64        basis_bits.bit_4 = bits[4]
65        basis_bits.bit_5 = bits[5]
66        basis_bits.bit_6 = bits[6]
67        basis_bits.bit_7 = bits[7]
68       
69        lex = Lex()
70        Classify_bytes(basis_bits, lex)
71        Demo(u8data, lex)
Note: See TracBrowser for help on using the repository browser.