%e 1019 %p 2807 %n 371 %k 284 %a 1213 %o 1117 O [0-7] D [0-9] NZ [1-9] L [a-zA-Z_] A [a-zA-Z_0-9] H [a-fA-F0-9] HP (0[xX]) E ([Ee][+-]?{D}+) P ([Pp][+-]?{D}+) FS (f|F|l|L) IS (((u|U)(l|L|ll|LL)?)|((l|L|ll|LL)(u|U)?)) CP (u|U|L) SP (u8|u|U|L) ES (\\(['"\?\\abfnrtv]|[0-7]{1,3}|x[a-fA-F0-9]+)) WS [ \t\v\n\f] %{ import t_def import y_tab %} %% "/*" { if not skip_comment(): return -1 } "//".* # consume //-comment "auto" return y_tab.AUTO "break" return y_tab.BREAK "case" return y_tab.CASE "char" return y_tab.CHAR "const" return y_tab.CONST "continue" return y_tab.CONTINUE "default" return y_tab.DEFAULT "do" return y_tab.DO "double" return y_tab.DOUBLE "else" return y_tab.ELSE "enum" return y_tab.ENUM "extern" return y_tab.EXTERN "float" return y_tab.FLOAT "for" return y_tab.FOR "goto" return y_tab.GOTO "if" return y_tab.IF "inline" return y_tab.INLINE "int" return y_tab.INT "long" return y_tab.LONG "register" return y_tab.REGISTER "restrict" return y_tab.RESTRICT "return" return y_tab.RETURN "short" return y_tab.SHORT "signed" return y_tab.SIGNED "sizeof" return y_tab.SIZEOF "static" return y_tab.STATIC "struct" return y_tab.STRUCT "switch" return y_tab.SWITCH "typedef" return y_tab.TYPEDEF "union" return y_tab.UNION "unsigned" return y_tab.UNSIGNED "void" return y_tab.VOID "volatile" return y_tab.VOLATILE "while" return y_tab.WHILE "_Alignas" return y_tab.ALIGNAS "_Alignof" return y_tab.ALIGNOF "_Atomic" return y_tab.ATOMIC "_Bool" return y_tab.BOOL "_Complex" return y_tab.COMPLEX "_Generic" return y_tab.GENERIC "_Imaginary" return y_tab.IMAGINARY "_Noreturn" return y_tab.NORETURN "_Static_assert" return y_tab.STATIC_ASSERT "_Thread_local" return y_tab.THREAD_LOCAL "__func__" return y_tab.FUNC_NAME 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 { # THIS IS A HACK FOR NOW return y_tab.TYPEDEF_NAME } /* hack for yacc/bison specification */ (?E{t_def.AST.Identifier}{L}{A}*) | (?E{t_def.AST.Identifier}[$@]("$"|{D}+)) { return y_tab.IDENTIFIER } (?E{t_def.AST.ExpressionIntLiteral}{HP}{H}+{IS}?) | (?E{t_def.AST.ExpressionIntLiteral}{NZ}{D}*{IS}?) | (?E{t_def.AST.ExpressionIntLiteral}"0"{O}*{IS}?) | (?E{t_def.AST.ExpressionCharConstant}{CP}?"'"(?E{t_def.AST.Text}([^'\\\n]|{ES})+)"'") { return y_tab.I_CONSTANT } (?E{t_def.AST.ExpressionFloatLiteral}{D}+{E}{FS}?) | (?E{t_def.AST.ExpressionFloatLiteral}{D}*"."{D}+{E}?{FS}?) | (?E{t_def.AST.ExpressionFloatLiteral}{D}+"."{E}?{FS}?) | (?E{t_def.AST.ExpressionFloatLiteral}{HP}{H}+{P}{FS}?) | (?E{t_def.AST.ExpressionFloatLiteral}{HP}{H}*"."{H}+{P}{FS}?) | (?E{t_def.AST.ExpressionFloatLiteral}{HP}{H}+"."{P}{FS}?) { return y_tab.F_CONSTANT } (?E{t_def.AST.ExpressionStringLiteral}({SP}?\"(?E{t_def.AST.Text}([^"\\\n]|{ES})*)\"{WS}*)+) { return y_tab.STRING_LITERAL } "..." return y_tab.ELLIPSIS ">>=" return y_tab.RIGHT_ASSIGN "<<=" return y_tab.LEFT_ASSIGN "+=" return y_tab.ADD_ASSIGN "-=" return y_tab.SUB_ASSIGN "*=" return y_tab.MUL_ASSIGN "/=" return y_tab.DIV_ASSIGN "%=" return y_tab.MOD_ASSIGN "&=" return y_tab.AND_ASSIGN "^=" return y_tab.XOR_ASSIGN "|=" return y_tab.OR_ASSIGN ">>" return y_tab.RIGHT_OP "<<" return y_tab.LEFT_OP "++" return y_tab.INC_OP "--" return y_tab.DEC_OP "->" return y_tab.PTR_OP "&&" return y_tab.AND_OP "||" return y_tab.OR_OP "<=" return y_tab.LE_OP ">=" return y_tab.GE_OP "==" return y_tab.EQ_OP "!=" return y_tab.NE_OP ";" return ord(';') ("{"|"<%") return ord('{') ("}"|"%>") return ord('}') "," return ord(',') ":" return ord(':') "=" return ord('=') "(" return ord('(') ")" return ord(')') ("["|"<:") return ord('[') ("]"|":>") return ord(']') "." return ord('.') "&" return ord('&') "!" return ord('!') "~" return ord('~') "-" return ord('-') "+" return ord('+') "*" return ord('*') "/" return ord('/') "%" return ord('%') "<" return ord('<') ">" return ord('>') "^" return ord('^') "|" return ord('|') "?" return ord('?') {WS}+ # whitespace separates tokens . # discard bad characters <> return 0 %% def yywrap(): # called at end of input return 1 # terminate now */ def yyerror(s): sys.stdout.flush() sys.stderr.write('*** {0:s}\n'.format(s)) def skip_comment(): c = input() while len(c): if c == '*': c = input() while c == '*': c = input() if c == '/': return True; if len(c) == 0: break c = input() yyerror('unterminated comment') return False