File: parse.l

package info (click to toggle)
cxref 1.5c-9
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,504 kB
  • ctags: 1,359
  • sloc: ansic: 16,721; yacc: 1,930; sh: 722; lex: 416; makefile: 345; lisp: 256; python: 80; perl: 78
file content (416 lines) | stat: -rw-r--r-- 22,743 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
W                       [ \t]
N                       \r*\n
D                       [0-9]
L                       [a-zA-Z_$]
H                       [a-fA-F0-9]
E                       [Ee][+-]?{D}+
FS                      (f|F|l|L)
IS                      (u|U|l|L)*

%x START_COMMENT     COMMENT     SPECIAL_COMMENT
%x START_COMMENT_CPP COMMENT_CPP SPECIAL_COMMENT_CPP
%x CPP CPP_START
%x CPP_INCLUDE CPP_INC_FILE CPP_INC_FLAGS
%x CPP_DEFINE CPP_DEFINE_ARGP CPP_DEFINE_BODY CPP_DEFINE_ARGS
%x GNU_LABEL GNU_ATTRIBUTE GNU_EXTENSION GNU_TYPEOF
%x CHAR_VARYING

%{
/***************************************
  $Header: /home/amb/cxref/RCS/parse.l 1.36 2000/03/13 19:40:31 amb Exp $

  C Cross Referencing & Documentation tool. Version 1.5c.

  C lexical analyser
  CPP processing, including GNU extensions, using yylval as a string.
  ******************/ /******************
  Written by Andrew M. Bishop

  This file Copyright 1995,96,97,98,99,2000 Andrew M. Bishop
  It may be distributed under the GNU Public License, version 2, or
  any higher version.  See section COPYING of the GNU Public license
  for conditions under which this file may be redistributed.
  ***************************************/

#include <string.h>

#include "parse-yy.h"
#include "parse-yacc.h"
#include "cxref.h"
#include "memory.h"

/*+ The name of the current file. +*/
char* parse_file=NULL;

/*+ The current line number in the file. +*/
int parse_line=0;


/*+ If we are in a header file then ignore the comments. +*/
extern int in_header;

/*+ One of the options controlling how comments are processed, +*/
extern int option_all_comments,       /*+ use all comments not just the specially formattted ones. +*/
           option_block_comments,     /*+ remove the leading block comment marker. +*/
           option_no_comments;        /*+ ignore all comments. +*/

/*+ Flag that indicates if the comment warnings are to be issued. +*/
extern int option_warn;


/*+ The flags that come out of GCC when a file is included. +*/
static int inc_file_flags=0;

/*+ The name of a file seen in a CPP_INC_FILE state. +*/
static char *inc_file=NULL;

/*+ The value of the thing that is defined (but only if it is simple). +*/
static char* define_value=NULL;

/*+ The lex state at the time that a comment is seen. +*/
static int comment_init_state=INITIAL;

/*+ To get around the GCC __attribute__ keyword, skip over matched () counted by this. +*/
static int gnu_att_depth=0;

/*+ To get around the GCC __typeof__ keyword, skip over matched () counted by this. +*/
static int gnu_typ_depth=0;

/*+ If we see a comment immediately after a ',', ';', '};', '},' or ')' then push it before. +*/
static int push_past=0;


/*++++++++++++++++++++++++++++++++++++++
  Reset the Lexer, ready for the next file.
  ++++++++++++++++++++++++++++++++++++++*/

void ResetLexer(void)
{
 parse_file=NULL;
 parse_line=0;
 inc_file_flags=0;
 inc_file=NULL;
 define_value=NULL;
 comment_init_state=INITIAL;
 gnu_att_depth=0;
 gnu_typ_depth=0;
 push_past=0;
 BEGIN(INITIAL);
}

%}

%%

 /* Comments, could be embedded in a preprocessor directive. */

<INITIAL>"/*"                     { comment_init_state = INITIAL        ; BEGIN(START_COMMENT); }
<CPP_START>"/*"                   { comment_init_state = CPP_START      ; BEGIN(START_COMMENT); }
<CPP>"/*"                         { comment_init_state = CPP            ; BEGIN(START_COMMENT); }
<CPP_DEFINE>"/*"                  { comment_init_state = CPP_DEFINE     ; BEGIN(START_COMMENT); }
<CPP_INCLUDE>"/*"                 { comment_init_state = CPP_INCLUDE    ; BEGIN(START_COMMENT); }
<CPP_DEFINE_ARGP>"/*"             { comment_init_state = CPP_DEFINE_ARGP; BEGIN(START_COMMENT); }
<CPP_DEFINE_ARGS>"/*"             { comment_init_state = CPP_DEFINE_ARGS; BEGIN(START_COMMENT); }
<CPP_DEFINE_BODY>"/*"             { comment_init_state = CPP_DEFINE_BODY; BEGIN(START_COMMENT); }
<CPP_INC_FILE>"/*"                { comment_init_state = CPP_INC_FILE   ; BEGIN(START_COMMENT); }
<CPP_INC_FLAGS>"/*"               { comment_init_state = CPP_INC_FLAGS  ; BEGIN(START_COMMENT); }

<INITIAL>"//"                     { comment_init_state = INITIAL; BEGIN(START_COMMENT_CPP); }
<CPP_START>"//"                   { comment_init_state = INITIAL; BEGIN(START_COMMENT_CPP); }
<CPP>"//"                         { comment_init_state = INITIAL; BEGIN(START_COMMENT_CPP); }
<CPP_DEFINE>"//"                  { comment_init_state = INITIAL; BEGIN(START_COMMENT_CPP); }
<CPP_INCLUDE>"//"                 { comment_init_state = INITIAL; BEGIN(START_COMMENT_CPP); }
<CPP_DEFINE_ARGP>"//"             { comment_init_state = INITIAL; BEGIN(START_COMMENT_CPP); }
<CPP_DEFINE_ARGS>"//"             { comment_init_state = INITIAL; BEGIN(START_COMMENT_CPP); }
<CPP_DEFINE_BODY>"//"             { comment_init_state = INITIAL; BEGIN(START_COMMENT_CPP); }
<CPP_INC_FILE>"//"                { comment_init_state = INITIAL; BEGIN(START_COMMENT_CPP); }
<CPP_INC_FLAGS>"//"               { comment_init_state = INITIAL; BEGIN(START_COMMENT_CPP); }

<START_COMMENT>"*"+               { BEGIN(SPECIAL_COMMENT); }
<START_COMMENT>"+"+               { BEGIN(SPECIAL_COMMENT); }
<START_COMMENT>[*+ \t]*"*/"       { BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }
<START_COMMENT>{N}                { if(option_all_comments) SeenComment(yytext,0); parse_line++;
                                    if(option_all_comments) BEGIN(SPECIAL_COMMENT); else BEGIN(COMMENT); }
<START_COMMENT>[^*+]              { if(option_all_comments) SeenComment(yytext,0);
                                    if(option_all_comments) BEGIN(SPECIAL_COMMENT); else BEGIN(COMMENT); }

<START_COMMENT_CPP>"*"+           { BEGIN(SPECIAL_COMMENT_CPP); }
<START_COMMENT_CPP>"+"+           { BEGIN(SPECIAL_COMMENT_CPP); }
<START_COMMENT_CPP>{N}            { parse_line++; BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }
<START_COMMENT_CPP>[^*+]          { if(option_all_comments) BEGIN(SPECIAL_COMMENT_CPP); else BEGIN(COMMENT_CPP); }

<COMMENT>{N}                      { parse_line++; }
<COMMENT>.                        { }
<COMMENT>[+*]+/"*/"               { if(option_warn&WARN_COMMENT) fprintf(stderr,"%s:%d: Warning unbalanced cxref comment; starts simple, ends special.\n",parse_file,parse_line); }
<COMMENT>"*/"                     { BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }

<COMMENT_CPP>.*{N}                { if(comment_init_state==CPP_INCLUDE || comment_init_state==CPP_DEFINE) comment_init_state=INITIAL;
                                    parse_line++; BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }

<SPECIAL_COMMENT>{N}              { if(!option_no_comments) SeenComment(yytext,0); parse_line++; }
 /* The following three lines are optimised for run-time speed.
    They replace the following pattern which has variable trailing context:
    <SPECIAL_COMMENT>{N}{W}*[+*|:]/({W}|{N})
 */
<SPECIAL_COMMENT>{N}{W}*[+*|:]/{W} { parse_line++;
                                    if(option_block_comments) yytext[0]='\n',yytext[1]=0;
                                    if(!option_no_comments) SeenComment(yytext,0); }
<SPECIAL_COMMENT>{N}{W}*[+*|:]/\n { parse_line++;
                                    if(option_block_comments) yytext[0]='\n',yytext[1]=0;
                                    if(!option_no_comments) SeenComment(yytext,0); }
<SPECIAL_COMMENT>{N}{W}*[+*|:]/\r\n { parse_line++;
                                    if(option_block_comments) yytext[0]='\n',yytext[1]=0;
                                    if(!option_no_comments) SeenComment(yytext,0); }
<SPECIAL_COMMENT>[^\r\n*+]+       { if(!option_no_comments) SeenComment(yytext,0); }
<SPECIAL_COMMENT>.                { if(!option_no_comments) SeenComment(yytext,0); }

<SPECIAL_COMMENT>{W}*"*"+"*/"     { if(!option_no_comments) SeenComment(NULL,1);
                                    BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }
<SPECIAL_COMMENT>{W}*"+"+"*/"     { if(!option_no_comments) SeenComment(NULL,2);
                                    if(!in_header && comment_init_state==CPP_DEFINE_ARGS) SeenDefineFuncArgComment();
                                    if(!in_header && comment_init_state==CPP_DEFINE_BODY) SeenDefineComment();
                                    if(!in_header && comment_init_state==CPP_INCLUDE)     SeenIncludeComment();
                                    BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }
<SPECIAL_COMMENT>"*/"             { if(!option_all_comments && option_warn&WARN_COMMENT)
                                       fprintf(stderr,"%s:%d: Warning unbalanced cxref comment; starts special, ends simple.\n",parse_file,parse_line);
                                    if(option_all_comments) SeenComment(NULL,3); else if(!option_no_comments) SeenComment(NULL,2);
                                    if(!in_header && comment_init_state==CPP_DEFINE_ARGS) SeenDefineFuncArgComment();
                                    if(!in_header && comment_init_state==CPP_DEFINE_BODY) SeenDefineComment();
                                    if(!in_header && comment_init_state==CPP_INCLUDE)     SeenIncludeComment();
                                    BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }

<SPECIAL_COMMENT_CPP>[^\r\n]+     { if(!option_no_comments) SeenComment(yytext,0); }
<SPECIAL_COMMENT_CPP>.            { if(!option_no_comments) SeenComment(yytext,0); }
<SPECIAL_COMMENT_CPP>{W}*{N}      { if(!option_no_comments) SeenComment(NULL,2);
                                    if(!in_header && comment_init_state==CPP_DEFINE_ARGS) SeenDefineFuncArgComment();
                                    if(!in_header && comment_init_state==CPP_DEFINE_BODY) SeenDefineComment();
                                    if(!in_header && comment_init_state==CPP_INCLUDE)     SeenIncludeComment();
                                    parse_line++; BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }

 /* Preprocessor directives, only valid at the top level. */

#{W}*                           { BEGIN(CPP_START); }

<CPP_START>{D}+{W}+             { parse_line=atoi(yytext); BEGIN(CPP_INC_FILE);}
<CPP_START>define{W}+           { BEGIN(CPP_DEFINE); }
<CPP_START>include{W}+          { BEGIN(CPP_INCLUDE); }
<CPP_START>[a-z]+               { BEGIN(CPP); }

<CPP>.                          { }
<CPP>\\{N}                      { parse_line++; }
<CPP>{N}                        { parse_line++; BEGIN(INITIAL); }

<CPP_DEFINE>{L}({L}|{D}|\$)*    { if(!in_header) SeenDefine(yytext); BEGIN(CPP_DEFINE_ARGP); }
<CPP_DEFINE>\\{N}               { parse_line++; }
<CPP_DEFINE>{W}+                { }

<CPP_DEFINE_ARGP>"("            { BEGIN(CPP_DEFINE_ARGS); }
<CPP_DEFINE_ARGP>{N}            { parse_line++; BEGIN(INITIAL); }
<CPP_DEFINE_ARGP>[^\r\n(]       { define_value=NULL; BEGIN(CPP_DEFINE_BODY); }
<CPP_DEFINE_ARGP>\\{N}          { parse_line++; }

<CPP_DEFINE_ARGS>{L}({L}|{D})*       { if(!in_header) SeenDefineFunctionArg(yytext); }
<CPP_DEFINE_ARGS>{L}({L}|{D})*"..."  { if(!in_header) SeenDefineFunctionArg(yytext); }
<CPP_DEFINE_ARGS>","                 { }
<CPP_DEFINE_ARGS>{W}+                { }
<CPP_DEFINE_ARGS>\\{N}               { parse_line++; }
<CPP_DEFINE_ARGS>")"                 { define_value=(char*)1; BEGIN(CPP_DEFINE_BODY); }

<CPP_DEFINE_BODY>{L}({L}|{D}|\$)*            { if(!in_header) {if(!define_value) define_value=CopyString(yytext); else define_value=(char*)1;} }
<CPP_DEFINE_BODY>0[xX]{H}+{IS}?              { if(!in_header) {if(!define_value) define_value=CopyString(yytext); else define_value=(char*)1;} }
<CPP_DEFINE_BODY>0{D}+{IS}?                  { if(!in_header) {if(!define_value) define_value=CopyString(yytext); else define_value=(char*)1;} }
<CPP_DEFINE_BODY>{D}+{IS}?                   { if(!in_header) {if(!define_value) define_value=CopyString(yytext); else define_value=(char*)1;} }
<CPP_DEFINE_BODY>{D}+{E}{FS}?                { if(!in_header) {if(!define_value) define_value=CopyString(yytext); else define_value=(char*)1;} }
<CPP_DEFINE_BODY>{D}*"."{D}+({E})?{FS}?      { if(!in_header) {if(!define_value) define_value=CopyString(yytext); else define_value=(char*)1;} }
<CPP_DEFINE_BODY>{D}+"."{D}*({E})?{FS}?      { if(!in_header) {if(!define_value) define_value=CopyString(yytext); else define_value=(char*)1;} }
<CPP_DEFINE_BODY>\'(\\.|[^'\r\n])*\'         { if(!in_header) {if(!define_value) define_value=CopyString(yytext); else define_value=(char*)1;} }
<CPP_DEFINE_BODY>\"(\\.|[^"\r\n])*\"         { if(!in_header) {if(!define_value) define_value=CopyString(yytext); else define_value=(char*)1;} }
<CPP_DEFINE_BODY>.                           { }
<CPP_DEFINE_BODY>\\{N}                       { parse_line++; }
<CPP_DEFINE_BODY>{N}                         { parse_line++; if(define_value>(char*)1) SeenDefineValue(define_value); BEGIN(INITIAL); }

<CPP_INCLUDE>[<"][^>"]+[>"]     { SeenInclude(yytext); }
<CPP_INCLUDE>.                  { }
<CPP_INCLUDE>\\{N}              { parse_line++; }
<CPP_INCLUDE>{N}                { parse_line++; BEGIN(INITIAL); }

<CPP_INC_FILE>"\""[^"]+"\""     { inc_file=CopyString(yytext+1); inc_file[strlen(inc_file)-1]=0;
                                  if(!parse_file) parse_file=inc_file;
                                  GetCurrentComment();
                                  inc_file_flags=0; BEGIN(CPP_INC_FLAGS); }
<CPP_INC_FLAGS>{W}+{D}+         { inc_file_flags+=1<<atoi(yytext); }
<CPP_INC_FLAGS>{W}*{N}          { if(inc_file_flags&6) parse_file=SeenFileChange(inc_file,inc_file_flags);
                                  BEGIN(INITIAL); }

 /* GNU C strangeness. */

("__alignof"|"__alignof__")        { yylval="alignof"  ; return(SIZEOF);   }

("__signed"|"__signed__")          { yylval="signed"   ; return(SIGNED);   }
("__unsigned"|"__unsigned__")      { yylval="unsigned" ; return(UNSIGNED); }

("__volatile"|"__volatile__")      { yylval="volatile" ; return(VOLATILE); }
("__const"|"__const__")            { yylval="const"    ; return(CONST);    }

("__inline"|"__inline__")          { yylval="inline"   ; return(INLINE);   }

("asm"|"__asm"|"__asm__")          { yylval="asm"      ; return(ASM);      }

"__label__"                        { BEGIN(GNU_LABEL); }
<GNU_LABEL>[^;]+                   { }
<GNU_LABEL>";"                     { BEGIN(INITIAL); }

("__attribute"|"__attribute__")    { gnu_att_depth=0; BEGIN(GNU_ATTRIBUTE); }
<GNU_ATTRIBUTE>"("                 { gnu_att_depth++; }
<GNU_ATTRIBUTE>[^()]+              { }
<GNU_ATTRIBUTE>")"                 { if(--gnu_att_depth==0) BEGIN(INITIAL); }

("typeof"|"__typeof"|"__typeof__") { gnu_typ_depth=0; BEGIN(GNU_TYPEOF); }
<GNU_TYPEOF>"("                    { gnu_typ_depth++; }
<GNU_TYPEOF>[^()]+                 { }
<GNU_TYPEOF>")"                    { if(--gnu_typ_depth==0) {BEGIN(INITIAL); yylval="typeof"; return(TYPE_NAME);} }

"__extension__"                    { }

("__restrict"|"__restrict__")      { }

("__restrict"|"__restrict__")      { }

"__FUNCTION__"                     { yylval="__FUNCTION__"; return(STRING_LITERAL); }

"__builtin_va_list"                { yylval="__builtin_va_list" ; return(TYPE_NAME); }

 /* VOS char_varying type */

"char_varying"{W}*"("{W}*{D}+{W}*")" { yylval=CopyString(yytext); BEGIN(CHAR_VARYING); return(CHAR); }
<CHAR_VARYING>.|\n                   { unput(*yytext); yylval=""; BEGIN(INITIAL); return('*'); }

 /* C language keywords. */

"auto"                  { yylval="auto"    ; return(AUTO);     }
"break"                 { yylval="break"   ; return(BREAK);    }
"case"                  { yylval="case"    ; return(CASE);     }
"char"                  { yylval="char"    ; return(CHAR);     }
"const"                 { yylval="const"   ; return(CONST);    }
"continue"              { yylval="continue"; return(CONTINUE); }
"default"               { yylval="default" ; return(DEFAULT);  }
"do"                    { yylval="do"      ; return(DO);       }
"double"                { yylval="double"  ; return(DOUBLE);   }
"else"                  { yylval="else"    ; return(ELSE);     }
"enum"                  { yylval="enum"    ; return(ENUM);     }
"extern"                { yylval="extern"  ; return(EXTERN);   }
"float"                 { yylval="float"   ; return(FLOAT);    }
"for"                   { yylval="for"     ; return(FOR);      }
"goto"                  { yylval="goto"    ; return(GOTO);     }
"if"                    { yylval="if"      ; return(IF);       }
"int"                   { yylval="int"     ; return(INT);      }
"inline"                { yylval="inline"  ; return(INLINE);   }
"long"                  { yylval="long"    ; return(LONG);     }
"register"              { yylval="register"; return(REGISTER); }
"return"                { yylval="return"  ; return(RETURN);   }
"short"                 { yylval="short"   ; return(SHORT);    }
"signed"                { yylval="signed"  ; return(SIGNED);   }
"sizeof"                { yylval="sizeof"  ; return(SIZEOF);   }
"static"                { yylval="static"  ; return(STATIC);   }
"struct"                { yylval="struct"  ; return(STRUCT);   }
"switch"                { yylval="switch"  ; return(SWITCH);   }
"typedef"               { yylval="typedef" ; return(TYPEDEF);  }
"union"                 { yylval="union"   ; return(UNION);    }
"unsigned"              { yylval="unsigned"; return(UNSIGNED); }
"void"                  { yylval="void"    ; return(VOID);     }
"volatile"              { yylval="volatile"; return(VOLATILE); }
"while"                 { yylval="while"   ; return(WHILE);    }

 /* C language operators. */

"..."                   { yylval="...";  return(ELLIPSES);     }
">>="                   { yylval=">>=";  return(RIGHT_ASSIGN); }
"<<="                   { yylval="<<=";  return(LEFT_ASSIGN);  }
"+="                    { yylval="+=";   return(ADD_ASSIGN); }
"-="                    { yylval="-=";   return(SUB_ASSIGN); }
"*="                    { yylval="*=";   return(MUL_ASSIGN); }
"/="                    { yylval="/=";   return(DIV_ASSIGN); }
"%="                    { yylval="%=";   return(MOD_ASSIGN); }
"&="                    { yylval="&=";   return(AND_ASSIGN); }
"^="                    { yylval="^=";   return(XOR_ASSIGN); }
"|="                    { yylval="|=";   return(OR_ASSIGN);  }
">>"                    { yylval=">>";   return(RIGHT_SHIFT);}
"<<"                    { yylval="<<";   return(LEFT_SHIFT); }
"++"                    { yylval="++";   return(INC_OP); }
"--"                    { yylval="--";   return(DEC_OP); }
"->"                    { yylval="->";   return(PTR_OP); }
"&&"                    { yylval="&&";   return(AND_OP); }
"||"                    { yylval="||";   return(OR_OP); }
"<="                    { yylval="<=";   return(LE_OP); }
">="                    { yylval=">=";   return(GE_OP); }
"=="                    { yylval="==";   return(EQ_OP); }
"!="                    { yylval="!=";   return(NE_OP); }
";"{W}*("/*"|"//")      { yylval="; ";   push_past=2;
                          comment_init_state=INITIAL; BEGIN(yytext[strlen(yytext)-1]=='*'?START_COMMENT:START_COMMENT_CPP); }
";"                     { yylval=";";    return(';'); }
"{"                     { yylval="{";    return('{'); }
"};"{W}*("/*"|"//")     { yylval="}; ";  push_past=3;
                          comment_init_state=INITIAL; BEGIN(yytext[strlen(yytext)-1]=='*'?START_COMMENT:START_COMMENT_CPP); }
"},"{W}*("/*"|"//")     { yylval="}, ";  push_past=3;
                          comment_init_state=INITIAL; BEGIN(yytext[strlen(yytext)-1]=='*'?START_COMMENT:START_COMMENT_CPP); }
"}"                     { yylval="}";    return('}'); }
","{W}*("/*"|"//")      { yylval=", ";   push_past=2;
                          comment_init_state=INITIAL; BEGIN(yytext[strlen(yytext)-1]=='*'?START_COMMENT:START_COMMENT_CPP); }
","                     { yylval=",";    return(','); }
":"                     { yylval=":";    return(':'); }
"="                     { yylval="=";    return('='); }
"("                     { yylval="(";    return('('); }
")"{W}*("/*"|"//")      { yylval=") ";   push_past=2;
                          comment_init_state=INITIAL; BEGIN(yytext[strlen(yytext)-1]=='*'?START_COMMENT:START_COMMENT_CPP); }
")"                     { yylval=")";    return(')'); }
"["                     { yylval="[";    return('['); }
"]"                     { yylval="]";    return(']'); }
"."                     { yylval=".";    return('.'); }
"&"                     { yylval="&";    return('&'); }
"!"                     { yylval="!";    return('!'); }
"~"                     { yylval="~";    return('~'); }
"-"                     { yylval="-";    return('-'); }
"+"                     { yylval="+";    return('+'); }
"*"                     { yylval="*";    return('*'); }
"/"                     { yylval="/";    return('/'); }
"%"                     { yylval="%";    return('%'); }
"<"                     { yylval="<";    return('<'); }
">"                     { yylval=">";    return('>'); }
"^"                     { yylval="^";    return('^'); }
"|"                     { yylval="|";    return('|'); }
"?"                     { yylval="?";    return('?'); }

 /* Variable / Function / Type names */

{L}({L}|{D}|\$)*        {
                          yylval=CopyString(yytext);
                          if(IsAScopeVariable(yytext))
                             return(IDENTIFIER);
                          else
                             if(IsATypeName(yytext))
                                return(TYPE_NAME);
                             else
                                return(IDENTIFIER);
                        }

 /* Literals */

0[xX]{H}+{IS}?          { yylval=CopyString(yytext); return(LITERAL); }
0{D}+{IS}?              { yylval=CopyString(yytext); return(LITERAL); } 
{D}+{IS}?               { yylval=CopyString(yytext); return(LITERAL); }
'(\\.|[^\\'])+'         { yylval=CopyString(yytext); return(LITERAL); }
"L"'(\\.|[^\\'])+'      { yylval=CopyString(yytext); return(LITERAL); }

{D}+{E}{FS}?            { yylval=CopyString(yytext); return(LITERAL); }
{D}*"."{D}+({E})?{FS}?  { yylval=CopyString(yytext); return(LITERAL); }
{D}+"."{D}*({E})?{FS}?  { yylval=CopyString(yytext); return(LITERAL); }

\"(\\.|[^\\"])*\"       { yylval=CopyString(yytext); return(STRING_LITERAL); }
"L"\"(\\.|[^\\"])*\"    { yylval=CopyString(yytext); return(STRING_LITERAL); }

 /* Other text. */

{N}                     { parse_line++; }
.                       { /* Ignore bad characters */ }

%%