Update Makefile to make it compile with recent pilex
[c_to_python.git] / ansi_c.l
1 %e  1019
2 %p  2807
3 %n  371
4 %k  284
5 %a  1213
6 %o  1117
7
8 O   [0-7]
9 D   [0-9]
10 NZ  [1-9]
11 L   [a-zA-Z_]
12 A   [a-zA-Z_0-9]
13 H   [a-fA-F0-9]
14 HP  (0[xX])
15 E   ([Ee][+-]?{D}+)
16 P   ([Pp][+-]?{D}+)
17 FS  (f|F|l|L)
18 IS  (((u|U)(l|L|ll|LL)?)|((l|L|ll|LL)(u|U)?))
19 CP  (u|U|L)
20 SP  (u8|u|U|L)
21 ES  (\\(['"\?\\abfnrtv]|[0-7]{1,3}|x[a-fA-F0-9]+))
22 WS  [ \t\v\n\f]
23
24 %{
25   import t_def
26   import y_tab
27 %}
28
29 %%
30
31 "/*" {
32   if not skip_comment():
33     return -1
34 }
35 "//".*                                  # consume //-comment
36
37 "auto"                                  return y_tab.AUTO
38 "break"                                 return y_tab.BREAK
39 "case"                                  return y_tab.CASE
40 "char"                                  return y_tab.CHAR
41 "const"                                 return y_tab.CONST
42 "continue"                              return y_tab.CONTINUE
43 "default"                               return y_tab.DEFAULT
44 "do"                                    return y_tab.DO
45 "double"                                return y_tab.DOUBLE
46 "else"                                  return y_tab.ELSE
47 "enum"                                  return y_tab.ENUM
48 "extern"                                return y_tab.EXTERN
49 "float"                                 return y_tab.FLOAT
50 "for"                                   return y_tab.FOR
51 "goto"                                  return y_tab.GOTO
52 "if"                                    return y_tab.IF
53 "inline"                                return y_tab.INLINE
54 "int"                                   return y_tab.INT
55 "long"                                  return y_tab.LONG
56 "register"                              return y_tab.REGISTER
57 "restrict"                              return y_tab.RESTRICT
58 "return"                                return y_tab.RETURN
59 "short"                                 return y_tab.SHORT
60 "signed"                                return y_tab.SIGNED
61 "sizeof"                                return y_tab.SIZEOF
62 "static"                                return y_tab.STATIC
63 "struct"                                return y_tab.STRUCT
64 "switch"                                return y_tab.SWITCH
65 "typedef"                               return y_tab.TYPEDEF
66 "union"                                 return y_tab.UNION
67 "unsigned"                              return y_tab.UNSIGNED
68 "void"                                  return y_tab.VOID
69 "volatile"                              return y_tab.VOLATILE
70 "while"                                 return y_tab.WHILE
71 "_Alignas"                              return y_tab.ALIGNAS
72 "_Alignof"                              return y_tab.ALIGNOF
73 "_Atomic"                               return y_tab.ATOMIC
74 "_Bool"                                 return y_tab.BOOL
75 "_Complex"                              return y_tab.COMPLEX
76 "_Generic"                              return y_tab.GENERIC
77 "_Imaginary"                            return y_tab.IMAGINARY
78 "_Noreturn"                             return y_tab.NORETURN
79 "_Static_assert"                        return y_tab.STATIC_ASSERT
80 "_Thread_local"                         return y_tab.THREAD_LOCAL
81 "__func__"                              return y_tab.FUNC_NAME
82
83 FILE|GRAM_STYPE|YYLTYPE|assoc|bool|boundary|code_props|code_props_type|location|muscle_kind|named_ref|param_type|scanflags_t|size_t|symbol|symbol_class|symbol_list|uniqstr|variant|warnings|u?int(8|16|32|64)_t|BaseType_t|TickType_t|AmazonGetFfsDeviceTypeIdProductId|AmazonStateFfsDeviceTypeIdProductId|AmazonGetFfsPin|AmazonStateFfsPin|AmazonGetFfsX509Csr|AmazonStateFfsX509Csr|AmazonSetFfsX509CertChainDownload|AmazonGetFfsX509CertChainStatus|AmazonFfsX509CertChainStorageStatus|AmazonStateFfsX509CertChainStatus|AmazonSetFfsStaticKey {
84   # THIS IS A HACK FOR NOW
85   return y_tab.TYPEDEF_NAME
86 }
87
88  /* hack for yacc/bison specification */
89 (?E{t_def.AST.Identifier}{L}{A}*) |
90 (?E{t_def.AST.Identifier}[$@]("$"|{D}+)) {
91   return y_tab.IDENTIFIER
92 }
93
94 (?E{t_def.AST.ExpressionIntLiteral}{HP}{H}+{IS}?) |
95 (?E{t_def.AST.ExpressionIntLiteral}{NZ}{D}*{IS}?) |
96 (?E{t_def.AST.ExpressionIntLiteral}"0"{O}*{IS}?) |
97 (?E{t_def.AST.ExpressionCharConstant}{CP}?"'"(?E{t_def.AST.Text}([^'\\\n]|{ES})+)"'") {
98   return y_tab.I_CONSTANT
99 }
100
101 (?E{t_def.AST.ExpressionFloatLiteral}{D}+{E}{FS}?) |
102 (?E{t_def.AST.ExpressionFloatLiteral}{D}*"."{D}+{E}?{FS}?) |
103 (?E{t_def.AST.ExpressionFloatLiteral}{D}+"."{E}?{FS}?) |
104 (?E{t_def.AST.ExpressionFloatLiteral}{HP}{H}+{P}{FS}?) |
105 (?E{t_def.AST.ExpressionFloatLiteral}{HP}{H}*"."{H}+{P}{FS}?) |
106 (?E{t_def.AST.ExpressionFloatLiteral}{HP}{H}+"."{P}{FS}?) {
107   return y_tab.F_CONSTANT
108 }
109
110 (?E{t_def.AST.ExpressionStringLiteral}({SP}?\"(?E{t_def.AST.Text}([^"\\\n]|{ES})*)\"{WS}*)+) {
111   return y_tab.STRING_LITERAL
112 }
113
114 "..."                                   return y_tab.ELLIPSIS
115 ">>="                                   return y_tab.RIGHT_ASSIGN
116 "<<="                                   return y_tab.LEFT_ASSIGN
117 "+="                                    return y_tab.ADD_ASSIGN
118 "-="                                    return y_tab.SUB_ASSIGN
119 "*="                                    return y_tab.MUL_ASSIGN
120 "/="                                    return y_tab.DIV_ASSIGN
121 "%="                                    return y_tab.MOD_ASSIGN
122 "&="                                    return y_tab.AND_ASSIGN
123 "^="                                    return y_tab.XOR_ASSIGN
124 "|="                                    return y_tab.OR_ASSIGN
125 ">>"                                    return y_tab.RIGHT_OP
126 "<<"                                    return y_tab.LEFT_OP
127 "++"                                    return y_tab.INC_OP
128 "--"                                    return y_tab.DEC_OP
129 "->"                                    return y_tab.PTR_OP
130 "&&"                                    return y_tab.AND_OP
131 "||"                                    return y_tab.OR_OP
132 "<="                                    return y_tab.LE_OP
133 ">="                                    return y_tab.GE_OP
134 "=="                                    return y_tab.EQ_OP
135 "!="                                    return y_tab.NE_OP
136 ";"                                     return ord(';')
137 ("{"|"<%")                              return ord('{')
138 ("}"|"%>")                              return ord('}')
139 ","                                     return ord(',')
140 ":"                                     return ord(':')
141 "="                                     return ord('=')
142 "("                                     return ord('(')
143 ")"                                     return ord(')')
144 ("["|"<:")                              return ord('[')
145 ("]"|":>")                              return ord(']')
146 "."                                     return ord('.')
147 "&"                                     return ord('&')
148 "!"                                     return ord('!')
149 "~"                                     return ord('~')
150 "-"                                     return ord('-')
151 "+"                                     return ord('+')
152 "*"                                     return ord('*')
153 "/"                                     return ord('/')
154 "%"                                     return ord('%')
155 "<"                                     return ord('<')
156 ">"                                     return ord('>')
157 "^"                                     return ord('^')
158 "|"                                     return ord('|')
159 "?"                                     return ord('?')
160
161 {WS}+                                   # whitespace separates tokens
162 .                                       # discard bad characters
163 <<EOF>>                                 return 0
164
165 %%
166
167 def yywrap():   # called at end of input
168   return 1      # terminate now */
169
170 def yyerror(s):
171   sys.stdout.flush()
172   sys.stderr.write('*** {0:s}\n'.format(s))
173
174 def skip_comment():
175   c = input()
176   while len(c):
177     if c == '*':
178       c = input()
179       while c == '*':
180         c = input()
181       if c == '/':
182         return True;
183       if len(c) == 0:
184         break
185     c = input()
186   yyerror('unterminated comment')
187   return False