%option noyywrap nounput noinput yylineno %{ #include "lexer.h" #include "ast.h" #include "parser.h" #include #include static bool failed = false; static char unescape(char escaped) { switch (escaped) { case 'n': return '\n'; case 't': return '\t'; case '0': return '\0'; default: return escaped; } } static int fail(const char* message) { (void)fprintf(stderr, "line %d: %s\n", yylineno, message); failed = true; return 0; } %} %% "::" return TOK_COLONCOLON; "emit" return TOK_EMIT; "static_assert" return TOK_STATIC_ASSERT; "commit" return TOK_COMMIT; "declare" return TOK_DECLARE; "undeclare" return TOK_UNDECLARE; "enable_if_t" return TOK_ENABLE_IF; "repeat" return TOK_REPEAT; "define" return TOK_DEFINE; "parameters" return TOK_PARAMETERS; "return" return TOK_RETURN; "invoke_result_t" return TOK_INVOKE_RESULT; "arguments" return TOK_ARGUMENTS; "sequence" return TOK_SEQUENCE; "name" return TOK_NAME; "value_of" return TOK_VALUE_OF; "declval" return TOK_DECLVAL; "void" return TOK_VOID; "int32_t" return TOK_INT32; "byte" return TOK_BYTE; "size_t" return TOK_SIZE_T; "char" return TOK_CHAR_T; "tuple" return TOK_TUPLE; "remove_cv_t" return TOK_REMOVE_CV; "decltype" return TOK_DECLTYPE; "difference" return TOK_DIFFERENCE; "sum" return TOK_SUM; "product" return TOK_PRODUCT; "quotient" return TOK_QUOTIENT; "array" return TOK_ARRAY; "extent" return TOK_EXTENT; "tuple_size" return TOK_TUPLE_SIZE; "integral_constant" return TOK_INTEGRAL_CONSTANT; "value" return TOK_VALUE; "conditional_t" return TOK_CONDITIONAL_T; "conditional" return TOK_CONDITIONAL; "true_type" return TOK_TRUE_TYPE; "false_type" return TOK_FALSE_TYPE; "is_same" return TOK_IS_SAME; "equal" return TOK_EQUAL; "less" return TOK_LESS; [<>(),;] return yytext[0]; '\\.' yylval.character = unescape(yytext[2]); return TOK_CHAR; '.' yylval.character = yytext[1]; return TOK_CHAR; "//"[^\n]* /* a comment */ [ \t\r\n]+ /* blanks */ [0-9]+ return fail("numeric literals are for the weak, subtract two characters"); [A-Za-z_][A-Za-z0-9_]* return fail("that is not a notion this language recognises"); . return fail("what is this character even"); %% bool lexer_failed(void) { return failed; }