-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0001.py
64 lines (50 loc) · 1.59 KB
/
0001.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import regex
import combinators.tokenization as tokenization
specifications = [ ( "COMMENT", ( "\(\*(.|[\r\n])*?\*\)", regex.MULTILINE ) ),
( "COMMENT", ( "\{(.|[\r\n])*?\}", regex.MULTILINE ) ),
( "COMMENT", ( "//.*", ) ),
( "NL", ( "[\r\n]+", ) ),
( "SPACE", ( "[ \t]+", ) ),
( "NAME", ( "[A-Za-z_][A-Za-z_0-9]*", ) ),
( "INT", ( "0x[0-9A-Fa-f]+", ) ),
( "INT", ( "[0-9]+", ) ),
( "REAL", ( "[0-9]+\.[0-9]*([Ee][+\-]?[0-9]+)*", ) ),
( "OP", ( "(\.\.)|(<>)|(<=)|(>=)|(:=)|[;,=\(\):\[\]\.+\-<>\*/@\^]", ) ),
( "STRING", ("'([^']|(''))*'", ) ),
( "STRING", ("\"([^\"]|(\"\"))*\"", ) ),
( "CHAR", ( "#[0-9]+", ) ),
( "CHAR", ( "#\$[0-9A-Fa-f]+", ) ), ]
tokenizer = tokenization.create (specifications)
try:
s = """
(* Hey there!
This is a long comment. *)
{ Hey there!
This is a long comment. }
process
output "Hello, World!%n"
3.141592
10
0x10
"""
for token in tokenizer (s):
print (token)
except tokenization.Error as e:
print (e)
tokenizer = tokenization.filtered (tokenization.create (specifications), tokenization.strip ([ "SPACE" ]))
try:
s = """
(* Hey there!
This is a long comment. *)
{ Hey there!
This is a long comment. }
process
output "Hello, World!%n"
3.141592
10
0x10
"""
for token in tokenizer (s):
print (token)
except tokenization.Error as e:
print (e)