better noise at runtime
[feisty_meow.git] / infobase / examples / cpp_grammar_code / CxxLexer.l
1 /*
2  *        Title:                        Miniature lexer for C++ parser.
3  *
4  *        File Name:            CxxLexer.l
5  *
6  *        Author:                       E.D.Willink
7  *
8  *      This is a complete lexer for C++, intended for use with CxxParser.y.
9  *      All actions are done by macros, so that there is some chance that customisation
10  *      can be performed within the bounds of the CxxLexing.hxx and CxxLexing.cxx
11  *      include files.
12  *END
13  */
14 %{
15 #include <CxxLexing.hxx>
16 %}
17 %a 5000
18 %e 1500
19 %n 1000
20 %o 10000
21 %p 10000
22 ws                                                              [ \f\v\t]
23
24 digit                                                   [0-9]
25 hex                                                             [0-9A-Fa-f]
26 letter                                                  [A-Z_a-z]
27 simple_escape_sequence                  (\\\'|\\\"|\\\?|\\\\|\\a|\\b|\\f|\\n|\\r|\\t|\\v)
28 octal_escape_sequence                   (\\[0-7]|\\[0-7][0-7]|\\[0-7][0-7][0-7])
29 hexadecimal_escape_sequence             (\\x{hex}+)
30 escape_sequence                                 ({simple_escape_sequence}|{octal_escape_sequence}|{hexadecimal_escape_sequence})
31 universal_character_name                (\\u{hex}{hex}{hex}{hex}|\\U{hex}{hex}{hex}{hex}{hex}{hex}{hex}{hex})
32 non_digit                                               ({letter}|{universal_character_name})
33 identifier                                              ({non_digit}({non_digit}|{digit})*)
34
35 character_lit                                   (L?\'([^\'\\\n]|\\.)*)
36 character_literal                               ({character_lit}\')
37
38 string_lit                                              (L?\"([^\"\\\n]|\\.)*)
39 string_literal                                  ({string_lit}\")
40
41 pp_number                                               (\.?{digit}({digit}|{non_digit}|[eE][-+]|\.)*)
42 %%
43 ^.*\n                                                   { LEX_SAVE_LINE(yytext, yyleng); REJECT; }
44 ^{ws}*"#".*                                             { /* Throw away preprocessor lines - hopefully only #line and equivalent. */ }
45
46 {character_lit}\'                               { LEX_CHARACTER_TOKEN(yytext, yyleng-1); };
47 {character_lit}\\                               { ERRMSG("End of line assumed to terminate character with trailing escape.");
48                                                                   LEX_CHARACTER_TOKEN(yytext, yyleng-1); };
49 {character_lit}                                 { ERRMSG("End of line assumed to terminate character.");
50                                                                   LEX_CHARACTER_TOKEN(yytext, yyleng); };
51
52 {string_lit}\"                                  { LEX_STRING_TOKEN(yytext, yyleng-1); };
53 {string_lit}\\                                  { ERRMSG("End of line assumed to terminate string with trailing escape.");
54                                                                   LEX_STRING_TOKEN(yytext, yyleng-1); };
55 {string_lit}                                    { ERRMSG("End of line assumed to terminate string.");
56                                                                   LEX_STRING_TOKEN(yytext, yyleng); };
57
58 "asm"                                                   { LEX_STATIC_TOKEN(ASM); }
59 "auto"                                                  { LEX_STATIC_TOKEN(AUTO); }
60 "bool"                                                  { LEX_C_STATIC_TOKEN(BOOL); }
61 "break"                                                 { LEX_STATIC_TOKEN(BREAK); }
62 "case"                                                  { LEX_STATIC_TOKEN(CASE); }
63 "catch"                                                 { LEX_C_STATIC_TOKEN(CATCH); }
64 "char"                                                  { LEX_STATIC_TOKEN(CHAR); }
65 "class"                                                 { LEX_C_STATIC_TOKEN(CLASS); }
66 "const"                                                 { LEX_STATIC_TOKEN(CONST); }
67 "const_cast"                                    { LEX_C_STATIC_TOKEN(CONST_CAST); }
68 "continue"                                              { LEX_STATIC_TOKEN(CONTINUE); }
69 "default"                                               { LEX_STATIC_TOKEN(DEFAULT); }
70 "delete"                                                { LEX_C_STATIC_TOKEN(DELETE); }
71 "do"                                                    { LEX_STATIC_TOKEN(DO); }
72 "double"                                                { LEX_STATIC_TOKEN(DOUBLE); }
73 "dynamic_cast"                                  { LEX_C_STATIC_TOKEN(DYNAMIC_CAST); }
74 "else"                                                  { LEX_STATIC_TOKEN(ELSE); }
75 "enum"                                                  { LEX_STATIC_TOKEN(ENUM); }
76 "explicit"                                              { LEX_C_STATIC_TOKEN(EXPLICIT); }
77 "export"                                                { LEX_C_STATIC_TOKEN(EXPORT); }
78 "extern"                                                { LEX_STATIC_TOKEN(EXTERN); }
79 "false"                                                 { LEX_C_STATIC_TOKEN(FALSE); }
80 "float"                                                 { LEX_STATIC_TOKEN(FLOAT); }
81 "for"                                                   { LEX_STATIC_TOKEN(FOR); }
82 "friend"                                                { LEX_STATIC_TOKEN(FRIEND); }
83 "goto"                                                  { LEX_STATIC_TOKEN(GOTO); }
84 "if"                                                    { LEX_STATIC_TOKEN(IF); }
85 "inline"                                                { LEX_C_STATIC_TOKEN(INLINE); }
86 "int"                                                   { LEX_STATIC_TOKEN(INT); }
87 "long"                                                  { LEX_STATIC_TOKEN(LONG); }
88 "mutable"                                               { LEX_C_STATIC_TOKEN(MUTABLE); }
89 "namespace"                                             { LEX_C_STATIC_TOKEN(NAMESPACE); }
90 "new"                                                   { LEX_C_STATIC_TOKEN(NEW); }
91 "operator"                                              { LEX_C_STATIC_TOKEN(OPERATOR); }
92 "private"                                               { LEX_C_STATIC_TOKEN(PRIVATE); }
93 "protected"                                             { LEX_C_STATIC_TOKEN(PROTECTED); }
94 "public"                                                { LEX_C_STATIC_TOKEN(PUBLIC); }
95 "register"                                              { LEX_STATIC_TOKEN(REGISTER); }
96 "reinterpret_cast"                              { LEX_C_STATIC_TOKEN(REINTERPRET_CAST); }
97 "return"                                                { LEX_STATIC_TOKEN(RETURN); }
98 "short"                                                 { LEX_STATIC_TOKEN(SHORT); }
99 "signed"                                                { LEX_C_STATIC_TOKEN(SIGNED); }
100 "sizeof"                                                { LEX_STATIC_TOKEN(SIZEOF); }
101 "static"                                                { LEX_STATIC_TOKEN(STATIC); }
102 "static_cast"                                   { LEX_C_STATIC_TOKEN(STATIC_CAST); }
103 "struct"                                                { LEX_STATIC_TOKEN(STRUCT); }
104 "switch"                                                { LEX_STATIC_TOKEN(SWITCH); }
105 "template"                                              { LEX_C_STATIC_TOKEN(TEMPLATE); }
106 "this"                                                  { LEX_C_STATIC_TOKEN(THIS); }
107 "throw"                                                 { LEX_C_STATIC_TOKEN(THROW); }
108 "true"                                                  { LEX_C_STATIC_TOKEN(TRUE); }
109 "try"                                                   { LEX_C_STATIC_TOKEN(TRY); }
110 "typedef"                                               { LEX_STATIC_TOKEN(TYPEDEF); }
111 "typeid"                                                { LEX_C_STATIC_TOKEN(TYPEID); }
112 "typename"                                              { LEX_C_STATIC_TOKEN(TYPENAME); }
113 "union"                                                 { LEX_STATIC_TOKEN(UNION); }
114 "unsigned"                                              { LEX_STATIC_TOKEN(UNSIGNED); }
115 "using"                                                 { LEX_C_STATIC_TOKEN(USING); }
116 "virtual"                                               { LEX_STATIC_TOKEN(VIRTUAL); }
117 "void"                                                  { LEX_STATIC_TOKEN(VOID); }
118 "volatile"                                              { LEX_STATIC_TOKEN(VOLATILE); }
119 "wchar_t"                                               { LEX_C_STATIC_TOKEN(WCHAR_T); }
120 "while"                                                 { LEX_STATIC_TOKEN(WHILE); }
121
122 "::"                                                    { LEX_C_STATIC_TOKEN(SCOPE); }
123 "..."                                                   { LEX_STATIC_TOKEN(ELLIPSIS); }
124 "<<"                                                    { LEX_STATIC_TOKEN(SHL); }
125 ">>"                                                    { LEX_STATIC_TOKEN(SHR); }
126 "=="                                                    { LEX_STATIC_TOKEN(EQ); }
127 "!="                                                    { LEX_STATIC_TOKEN(NE); }
128 "<="                                                    { LEX_STATIC_TOKEN(LE); }
129 ">="                                                    { LEX_STATIC_TOKEN(GE); }
130 "&&"                                                    { LEX_STATIC_TOKEN(LOG_AND); }
131 "||"                                                    { LEX_STATIC_TOKEN(LOG_OR); }
132 "++"                                                    { LEX_STATIC_TOKEN(INC); }
133 "--"                                                    { LEX_STATIC_TOKEN(DEC); }
134 "->*"                                                   { LEX_STATIC_TOKEN(ARROW_STAR); }
135 "->"                                                    { LEX_STATIC_TOKEN(ARROW); }
136 ".*"                                                    { LEX_STATIC_TOKEN(DOT_STAR); }
137 "+="                                                    { LEX_STATIC_TOKEN(ASS_ADD); }
138 "-="                                                    { LEX_STATIC_TOKEN(ASS_SUB); }
139 "*="                                                    { LEX_STATIC_TOKEN(ASS_MUL); }
140 "/="                                                    { LEX_STATIC_TOKEN(ASS_DIV); }
141 "%="                                                    { LEX_STATIC_TOKEN(ASS_MOD); }
142 "^="                                                    { LEX_STATIC_TOKEN(ASS_XOR); }
143 "&="                                                    { LEX_STATIC_TOKEN(ASS_AND); }
144 "|="                                                    { LEX_STATIC_TOKEN(ASS_OR); }
145 ">>="                                                   { LEX_STATIC_TOKEN(ASS_SHR); }
146 "<<="                                                   { LEX_STATIC_TOKEN(ASS_SHL); }
147
148 {pp_number}                                             { LEX_NUMBER_TOKEN(yytext, yyleng); }
149
150 {identifier}                                    { LEX_IDENTIFIER_TOKEN(yytext, yyleng); }
151
152 {escape_sequence}                               |
153 {universal_character_name}              { LEX_ESCAPED_TOKEN(yytext, yyleng); }
154
155 \n                                                              |
156 {ws}+                                                   { /* Throw away whitespace */ }
157 .                                                               { LEX_ASCII_TOKEN(yytext[0]); }
158
159 %%
160 #include <CxxLexing.cxx>