|
14 | 14 |
|
15 | 15 | import fileinput |
16 | 16 |
|
17 | | -collections = { "gram": [], |
18 | | - "keyword": [], |
19 | | - "reserved": [], |
20 | | - "binop": [], |
21 | | - "unop": [] } |
| 17 | +collections = {"gram": [], |
| 18 | + "keyword": [], |
| 19 | + "reserved": [], |
| 20 | + "binop": [], |
| 21 | + "unop": []} |
22 | 22 |
|
23 | 23 |
|
24 | 24 | in_coll = False |
|
47 | 47 | # Define operator symbol-names here |
48 | 48 |
|
49 | 49 | tokens = ["non_star", "non_slash", "non_eol", |
50 | | - "non_single_quote", "non_double_quote", "ident" ] |
| 50 | + "non_single_quote", "non_double_quote", "ident"] |
51 | 51 |
|
52 | 52 | symnames = { |
53 | | -".": "dot", |
54 | | -"+": "plus", |
55 | | -"-": "minus", |
56 | | -"/": "slash", |
57 | | -"*": "star", |
58 | | -"%": "percent", |
59 | | - |
60 | | -"~": "tilde", |
61 | | -"@": "at", |
62 | | - |
63 | | -"!": "not", |
64 | | -"&": "and", |
65 | | -"|": "or", |
66 | | -"^": "xor", |
67 | | - |
68 | | -"<<": "lsl", |
69 | | -">>": "lsr", |
70 | | -">>>": "asr", |
71 | | - |
72 | | -"&&": "andand", |
73 | | -"||": "oror", |
74 | | - |
75 | | -"<" : "lt", |
76 | | -"<=" : "le", |
77 | | -"==" : "eqeq", |
78 | | -">=" : "ge", |
79 | | -">" : "gt", |
80 | | - |
81 | | -"=": "eq", |
82 | | - |
83 | | -"+=": "plusequal", |
84 | | -"-=": "minusequal", |
85 | | -"/=": "divequal", |
86 | | -"*=": "starequal", |
87 | | -"%=": "percentequal", |
88 | | - |
89 | | -"&=": "andequal", |
90 | | -"|=": "orequal", |
91 | | -"^=": "xorequal", |
92 | | - |
93 | | -">>=": "lsrequal", |
94 | | -">>>=": "asrequal", |
95 | | -"<<=": "lslequal", |
96 | | - |
97 | | -"::": "coloncolon", |
98 | | - |
99 | | -"->": "rightarrow", |
100 | | -"<-": "leftarrow", |
101 | | -"<->": "swaparrow", |
102 | | - |
103 | | -"//": "linecomment", |
104 | | -"/*": "openblockcomment", |
105 | | -"*/": "closeblockcomment", |
106 | | -"macro_rules": "macro_rules", |
107 | | -"=>" : "eg", |
108 | | -".." : "dotdot", |
109 | | -"," : "comma" |
| 53 | + ".": "dot", |
| 54 | + "+": "plus", |
| 55 | + "-": "minus", |
| 56 | + "/": "slash", |
| 57 | + "*": "star", |
| 58 | + "%": "percent", |
| 59 | + |
| 60 | + "~": "tilde", |
| 61 | + "@": "at", |
| 62 | + |
| 63 | + "!": "not", |
| 64 | + "&": "and", |
| 65 | + "|": "or", |
| 66 | + "^": "xor", |
| 67 | + |
| 68 | + "<<": "lsl", |
| 69 | + ">>": "lsr", |
| 70 | + ">>>": "asr", |
| 71 | + |
| 72 | + "&&": "andand", |
| 73 | + "||": "oror", |
| 74 | + |
| 75 | + "<": "lt", |
| 76 | + "<=": "le", |
| 77 | + "==": "eqeq", |
| 78 | + ">=": "ge", |
| 79 | + ">": "gt", |
| 80 | + |
| 81 | + "=": "eq", |
| 82 | + |
| 83 | + "+=": "plusequal", |
| 84 | + "-=": "minusequal", |
| 85 | + "/=": "divequal", |
| 86 | + "*=": "starequal", |
| 87 | + "%=": "percentequal", |
| 88 | + |
| 89 | + "&=": "andequal", |
| 90 | + "|=": "orequal", |
| 91 | + "^=": "xorequal", |
| 92 | + |
| 93 | + ">>=": "lsrequal", |
| 94 | + ">>>=": "asrequal", |
| 95 | + "<<=": "lslequal", |
| 96 | + |
| 97 | + "::": "coloncolon", |
| 98 | + |
| 99 | + "->": "rightarrow", |
| 100 | + "<-": "leftarrow", |
| 101 | + "<->": "swaparrow", |
| 102 | + |
| 103 | + "//": "linecomment", |
| 104 | + "/*": "openblockcomment", |
| 105 | + "*/": "closeblockcomment", |
| 106 | + "macro_rules": "macro_rules", |
| 107 | + "=>": "eg", |
| 108 | + "..": "dotdot", |
| 109 | + ",": "comma" |
110 | 110 | } |
111 | 111 |
|
112 | 112 | lines = [] |
|
126 | 126 | + word) |
127 | 127 | if word not in tokens: |
128 | 128 | if (word in collections["keyword"] or |
129 | | - word in collections["reserved"]): |
130 | | - tokens.append(word) |
| 129 | + word in collections["reserved"]): |
| 130 | + tokens.append(word) |
131 | 131 | else: |
132 | 132 | raise Exception("unknown keyword/reserved word: " |
133 | 133 | + word) |
|
149 | 149 | print("%start parser, token;") |
150 | 150 | print("%%token %s ;" % ("\n\t, ".join(tokens))) |
151 | 151 | for coll in ["keyword", "reserved"]: |
152 | | - print("%s: %s ; " % (coll, "\n\t| ".join(collections[coll]))); |
| 152 | + print("%s: %s ; " % (coll, "\n\t| ".join(collections[coll]))) |
153 | 153 | for coll in ["binop", "unop"]: |
154 | 154 | print("%s: %s ; " % (coll, "\n\t| ".join([symnames[x] |
155 | | - for x in collections[coll]]))); |
156 | | -print("\n".join(lines)); |
| 155 | + for x in collections[coll]]))) |
| 156 | +print("\n".join(lines)) |
0 commit comments