2023-07-27 14:04:50 -04:00
|
|
|
%{
|
|
|
|
/*===========================================================================
|
2023-08-04 14:34:51 -04:00
|
|
|
Copyright (c) 1998-2000, The Santa Cruz Operation
|
2023-07-27 14:04:50 -04:00
|
|
|
All rights reserved.
|
2023-08-04 14:34:51 -04:00
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
*Redistributions of source code must retain the above copyright notice,
|
|
|
|
this list of conditions and the following disclaimer.
|
|
|
|
|
|
|
|
*Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
*Neither name of The Santa Cruz Operation nor the names of its contributors
|
|
|
|
may be used to endorse or promote products derived from this software
|
2023-08-04 14:34:51 -04:00
|
|
|
without specific prior written permission.
|
2023-07-27 14:04:50 -04:00
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
|
2023-08-04 15:09:58 -04:00
|
|
|
IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT falseT LIMITED TO,
|
2023-07-27 14:04:50 -04:00
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
2023-08-04 15:19:25 -04:00
|
|
|
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
|
2023-07-27 14:04:50 -04:00
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
2023-08-04 15:09:58 -04:00
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT falseT LIMITED TO, PROCUREMENT OF
|
2023-07-27 14:04:50 -04:00
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION)
|
|
|
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
2023-08-04 14:34:51 -04:00
|
|
|
DAMAGE.
|
2023-07-27 14:04:50 -04:00
|
|
|
=========================================================================*/
|
|
|
|
|
|
|
|
/* cscope - interactive C symbol cross-reference
|
|
|
|
*
|
|
|
|
* C symbol scanner
|
|
|
|
*/
|
|
|
|
#include "global.h"
|
|
|
|
|
|
|
|
#include "scanner.h"
|
|
|
|
#include "lookup.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
/* the line counting has been moved from character reading for speed */
|
|
|
|
/* comments are discarded */
|
|
|
|
|
|
|
|
#ifndef FLEX_SCANNER
|
|
|
|
# error Sorry, this scanner needs flex. It is not usable with AT&T Lex.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define IFLEVELINC 5 /* #if nesting level size increment */
|
2023-08-04 15:09:58 -04:00
|
|
|
#define YY_false_TOP_STATE 1
|
2023-07-27 14:04:50 -04:00
|
|
|
|
|
|
|
int first; /* buffer index for first char of symbol */
|
|
|
|
int last; /* buffer index for last char of symbol */
|
|
|
|
int lineno; /* symbol line number */
|
|
|
|
int myylineno = 1;
|
|
|
|
|
2023-08-04 14:34:51 -04:00
|
|
|
/* HBB 20001007: new variables, emulating yytext in a way that allows
|
|
|
|
* the yymore() simulation, my_yymore(), to be used even in the presence of
|
2023-07-27 14:04:50 -04:00
|
|
|
* yyless(). */
|
|
|
|
size_t my_yyleng = 0;
|
|
|
|
char *my_yytext = NULL;
|
|
|
|
|
2023-08-04 15:09:58 -04:00
|
|
|
static bool arraydimension; /* inside array dimension declaration */
|
|
|
|
static bool bplisting; /* breakpoint listing */
|
2023-07-27 14:04:50 -04:00
|
|
|
static int braces; /* unmatched left brace count */
|
2023-08-04 15:09:58 -04:00
|
|
|
static bool classdef; /* c++ class definition */
|
|
|
|
static bool elseelif; /* #else or #elif found */
|
|
|
|
static bool esudef; /* enum/struct/union global definition */
|
|
|
|
static bool external; /* external definition */
|
2023-07-27 14:04:50 -04:00
|
|
|
static int externalbraces; /* external definition outer brace count */
|
2023-08-04 15:09:58 -04:00
|
|
|
static bool fcndef; /* function definition */
|
|
|
|
static bool global; /* file global scope (outside functions) */
|
2023-07-27 14:04:50 -04:00
|
|
|
static size_t iflevel; /* #if nesting level */
|
2023-08-04 15:09:58 -04:00
|
|
|
static bool initializer; /* data initializer */
|
2023-07-27 14:04:50 -04:00
|
|
|
static int initializerbraces; /* data initializer outer brace count */
|
2023-08-04 15:09:58 -04:00
|
|
|
static bool lex; /* lex file */
|
2023-07-27 14:04:50 -04:00
|
|
|
static size_t miflevel = IFLEVELINC; /* maximum #if nesting level */
|
|
|
|
static int *maxifbraces; /* maximum brace count within #if */
|
|
|
|
static int *preifbraces; /* brace count before #if */
|
|
|
|
static int parens; /* unmatched left parenthesis count */
|
2023-08-04 15:09:58 -04:00
|
|
|
static bool ppdefine; /* preprocessor define statement */
|
|
|
|
static bool pseudoelif; /* pseudo-#elif */
|
|
|
|
static bool oldtype; /* next identifier is an old type */
|
|
|
|
static bool rules; /* lex/yacc rules */
|
|
|
|
static bool sdl; /* sdl file */
|
|
|
|
static bool structfield; /* structure field declaration */
|
2023-07-27 14:04:50 -04:00
|
|
|
static int tagdef; /* class/enum/struct/union tag definition */
|
2023-08-04 15:09:58 -04:00
|
|
|
static bool template; /* function template */
|
2023-07-27 14:04:50 -04:00
|
|
|
static int templateparens; /* function template outer parentheses count */
|
|
|
|
static int typedefbraces = -1; /* initial typedef brace count */
|
|
|
|
static int token; /* token found */
|
|
|
|
static int ident_start; /* begin of preceding identifier */
|
|
|
|
|
|
|
|
static void my_yymore(void);
|
|
|
|
|
|
|
|
%}
|
|
|
|
identifier [a-zA-Z_$][a-zA-Z_0-9$]*
|
|
|
|
number \.?[0-9][.0-9a-fA-FlLuUxX]*
|
|
|
|
comment "/*"([^*]*("*"+[^/])?)*"*/"|"//"[^\n]*\n
|
|
|
|
ws [ \t\r\v\f]
|
|
|
|
wsnl [ \t\r\v\f\n]|{comment}
|
|
|
|
|
|
|
|
/* flex options: stack of start conditions, and don't use yywrap() */
|
|
|
|
%option stack
|
|
|
|
%option noyywrap
|
|
|
|
|
|
|
|
%start SDL
|
|
|
|
%a 4000
|
|
|
|
%o 7000
|
|
|
|
|
|
|
|
/* exclusive start conditions. not available in AT&T lex -> use flex! */
|
|
|
|
%x IN_PREPROC WAS_ENDIF WAS_IDENTIFIER WAS_ESU IN_DQUOTE IN_SQUOTE COMMENT
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
%\{ { /* lex/yacc C declarations/definitions */
|
2023-08-04 15:09:58 -04:00
|
|
|
global = true;
|
2023-07-27 14:04:50 -04:00
|
|
|
goto more;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
%\} {
|
2023-08-04 15:09:58 -04:00
|
|
|
global = false;
|
2023-07-27 14:04:50 -04:00
|
|
|
goto more;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
^%% { /* lex/yacc rules delimiter */
|
|
|
|
braces = 0;
|
2023-08-04 15:09:58 -04:00
|
|
|
if (rules == false) {
|
2023-07-27 14:04:50 -04:00
|
|
|
/* this %% starts the section containing the rules */
|
2023-08-04 15:09:58 -04:00
|
|
|
rules = true;
|
2023-07-27 14:04:50 -04:00
|
|
|
|
|
|
|
/* Copy yytext to private buffer, to be able to add further
|
|
|
|
* content following it: */
|
|
|
|
my_yymore();
|
|
|
|
|
|
|
|
/* simulate a yylex() or yyparse() definition */
|
|
|
|
(void) strcat(my_yytext, " /* ");
|
|
|
|
first = strlen(my_yytext);
|
2023-08-04 15:09:58 -04:00
|
|
|
if (lex == true) {
|
2023-07-27 14:04:50 -04:00
|
|
|
(void) strcat(my_yytext, "yylex");
|
2023-08-04 14:34:51 -04:00
|
|
|
} else {
|
2023-07-27 14:04:50 -04:00
|
|
|
/* yacc: yyparse implicitly calls yylex */
|
|
|
|
char *s = " yylex()";
|
|
|
|
char *cp = s + strlen(s);
|
|
|
|
while (--cp >= s) {
|
|
|
|
unput(*cp);
|
|
|
|
}
|
|
|
|
(void) strcat(my_yytext, "yyparse");
|
|
|
|
}
|
|
|
|
last = strlen(my_yytext);
|
|
|
|
(void) strcat(my_yytext, " */");
|
|
|
|
my_yyleng = strlen(my_yytext);
|
|
|
|
return(FCNDEF);
|
|
|
|
} else {
|
|
|
|
/* were in the rules section, now comes the closing one */
|
2023-08-04 15:09:58 -04:00
|
|
|
rules = false;
|
|
|
|
global = true;
|
2023-07-27 14:04:50 -04:00
|
|
|
last = first;
|
|
|
|
my_yymore();
|
|
|
|
return(FCNEND);
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
<SDL>STATE[ \t]+({identifier}|\*) { /* sdl state, treat as function def */
|
|
|
|
braces = 1;
|
2023-08-04 15:09:58 -04:00
|
|
|
fcndef = true;
|
2023-07-27 14:04:50 -04:00
|
|
|
token = FCNDEF;
|
|
|
|
goto findident;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
<SDL>ENDSTATE[ \t] { /* end of an sdl state, treat as end of a function */
|
|
|
|
goto endstate;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
\{ { /* count unmatched left braces for fcn def detection */
|
|
|
|
++braces;
|
2023-08-04 14:34:51 -04:00
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
/* mark an untagged enum/struct/union so its beginning
|
|
|
|
can be found */
|
|
|
|
if (tagdef) {
|
|
|
|
if (braces == 1) {
|
2023-08-04 15:09:58 -04:00
|
|
|
esudef = true;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
token = tagdef;
|
|
|
|
tagdef = '\0';
|
|
|
|
last = first;
|
|
|
|
my_yymore();
|
|
|
|
return(token);
|
|
|
|
}
|
|
|
|
goto more;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
\#{ws}* { /* start a preprocessor line */
|
2023-08-04 15:09:58 -04:00
|
|
|
if (rules == false) /* don't consider CPP for lex/yacc rules */
|
2023-07-27 14:04:50 -04:00
|
|
|
BEGIN(IN_PREPROC);
|
|
|
|
yyleng = 1; /* get rid of the blanks, if any */
|
|
|
|
goto more;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
<IN_PREPROC>endif([^a-zA-Z0-9_$\n].*)? { /* #endif */
|
|
|
|
/* delay treatment of #endif depending on whether an
|
|
|
|
* #if comes right after it, or not */
|
|
|
|
/* HBB 20010619: new pattern allows trailing garbage
|
|
|
|
* after the #endif */
|
|
|
|
BEGIN(WAS_ENDIF);
|
|
|
|
goto more;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
<WAS_ENDIF>\n{wsnl}*#{ws}*if(ndef|def)?{ws}+ {
|
|
|
|
/* attempt to correct erroneous brace count caused by:
|
2023-08-04 14:34:51 -04:00
|
|
|
*
|
2023-07-27 14:04:50 -04:00
|
|
|
* #if ...
|
|
|
|
* ... {
|
|
|
|
* #endif
|
|
|
|
* #if ...
|
|
|
|
* ... {
|
|
|
|
* #endif
|
|
|
|
*/
|
|
|
|
/* the current #if must not have an #else or #elif */
|
2023-08-04 15:09:58 -04:00
|
|
|
if (elseelif == true) {
|
2023-07-27 14:04:50 -04:00
|
|
|
goto endif;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
2023-08-04 15:09:58 -04:00
|
|
|
pseudoelif = true;
|
2023-07-27 14:04:50 -04:00
|
|
|
BEGIN(INITIAL);
|
|
|
|
yyless(1); /* rescan all but the line ending */
|
|
|
|
yy_set_bol(1);
|
|
|
|
goto eol;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
<WAS_ENDIF>\n{wsnl}* { /* an #endif with no #if right after it */
|
|
|
|
endif:
|
|
|
|
if (iflevel > 0) {
|
|
|
|
/* get the maximum brace count for this #if */
|
|
|
|
if (braces < maxifbraces[--iflevel]) {
|
|
|
|
braces = maxifbraces[iflevel];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
yyless(1);
|
|
|
|
yy_set_bol(1);
|
|
|
|
goto eol;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
<IN_PREPROC>ifndef{ws}+ |
|
|
|
|
<IN_PREPROC>ifdef{ws}+ |
|
|
|
|
<IN_PREPROC>if{ws}+ { /* #if directive */
|
2023-08-04 15:09:58 -04:00
|
|
|
elseelif = false;
|
|
|
|
if (pseudoelif == true) {
|
|
|
|
pseudoelif = false;
|
2023-07-27 14:04:50 -04:00
|
|
|
goto elif;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
/* make sure there is room for the current brace count */
|
|
|
|
if (iflevel == miflevel) {
|
|
|
|
miflevel += IFLEVELINC;
|
|
|
|
maxifbraces = realloc(maxifbraces, miflevel * sizeof(*maxifbraces));
|
|
|
|
preifbraces = realloc(preifbraces, miflevel * sizeof(*preifbraces));
|
|
|
|
}
|
|
|
|
/* push the current brace count */
|
|
|
|
preifbraces[iflevel] = braces;
|
|
|
|
maxifbraces[iflevel++] = 0;
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
goto more;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
<IN_PREPROC>else({ws}.*)? { /* #else --- eat up whole line */
|
2023-08-04 15:09:58 -04:00
|
|
|
elseelif = true;
|
2023-07-27 14:04:50 -04:00
|
|
|
if (iflevel > 0) {
|
2023-08-04 14:34:51 -04:00
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
/* save the maximum brace count for this #if */
|
|
|
|
if (braces > maxifbraces[iflevel - 1]) {
|
|
|
|
maxifbraces[iflevel - 1] = braces;
|
|
|
|
}
|
|
|
|
/* restore the brace count to before the #if */
|
|
|
|
braces = preifbraces[iflevel - 1];
|
|
|
|
}
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
goto more;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
<IN_PREPROC>elif{ws}+ { /* #elif */
|
2023-08-04 15:09:58 -04:00
|
|
|
/* elseelif = true; --- HBB I doubt this is correct */
|
2023-07-27 14:04:50 -04:00
|
|
|
elif:
|
|
|
|
if (iflevel > 0) {
|
2023-08-04 14:34:51 -04:00
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
/* save the maximum brace count for this #if */
|
|
|
|
if (braces > maxifbraces[iflevel - 1]) {
|
|
|
|
maxifbraces[iflevel - 1] = braces;
|
|
|
|
}
|
|
|
|
/* restore the brace count to before the #if */
|
|
|
|
braces = preifbraces[iflevel - 1];
|
|
|
|
}
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
goto more;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
<IN_PREPROC>include{ws}*\"[^"\n]+\" |
|
|
|
|
<IN_PREPROC>include{ws}*<[^>\n]+> { /* #include file */
|
|
|
|
char *s;
|
|
|
|
char remember = yytext[yyleng-1];
|
2023-08-04 14:34:51 -04:00
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
my_yymore();
|
|
|
|
s = strpbrk(my_yytext, "\"<");
|
|
|
|
if (!s)
|
|
|
|
return(LEXERR);
|
|
|
|
my_yytext[my_yyleng-1] = '\0';
|
|
|
|
incfile(s + 1, s);
|
|
|
|
my_yytext[my_yyleng-1] = remember;
|
|
|
|
first = s - my_yytext;
|
|
|
|
last = my_yyleng - 1;
|
2023-08-04 15:09:58 -04:00
|
|
|
if (compress == true) {
|
2023-07-27 14:04:50 -04:00
|
|
|
my_yytext[0] = '\2'; /* compress the keyword */
|
|
|
|
}
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
return(INCLUDE);
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
\} {
|
|
|
|
/* could be the last enum member initializer */
|
|
|
|
if (braces == initializerbraces) {
|
|
|
|
initializerbraces = -1;
|
2023-08-04 15:09:58 -04:00
|
|
|
initializer = false;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
if (--braces <= 0) {
|
|
|
|
endstate:
|
|
|
|
braces = 0;
|
2023-08-04 15:09:58 -04:00
|
|
|
classdef = false;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
2023-08-04 15:09:58 -04:00
|
|
|
if (braces == 0 || (braces == 1 && classdef == true)) {
|
2023-07-27 14:04:50 -04:00
|
|
|
|
|
|
|
/* if the end of an enum/struct/union definition */
|
2023-08-04 15:09:58 -04:00
|
|
|
if (esudef == true) {
|
|
|
|
esudef = false;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
/* if the end of the function */
|
2023-08-04 15:09:58 -04:00
|
|
|
else if (fcndef == true) {
|
|
|
|
fcndef = false;
|
2023-07-27 14:04:50 -04:00
|
|
|
last = first;
|
|
|
|
my_yymore();
|
|
|
|
return(FCNEND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
goto more;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
\( { /* count unmatched left parentheses for function templates */
|
|
|
|
++parens;
|
|
|
|
goto more;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
\) {
|
|
|
|
if (--parens <= 0) {
|
|
|
|
parens = 0;
|
|
|
|
}
|
|
|
|
/* if the end of a function template */
|
|
|
|
if (parens == templateparens) {
|
|
|
|
templateparens = -1;
|
2023-08-04 15:09:58 -04:00
|
|
|
template = false;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
goto more;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
= { /* if a global definition initializer */
|
|
|
|
if (!my_yytext)
|
|
|
|
return(LEXERR);
|
2023-08-04 15:09:58 -04:00
|
|
|
if (global == true && ppdefine == false && my_yytext[0] != '#') {
|
2023-07-27 14:04:50 -04:00
|
|
|
initializerbraces = braces;
|
2023-08-04 15:09:58 -04:00
|
|
|
initializer = true;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
goto more;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
: { /* a if global structure field */
|
|
|
|
if (!my_yytext)
|
|
|
|
return(LEXERR);
|
2023-08-04 15:09:58 -04:00
|
|
|
if (global == true && ppdefine == false && my_yytext[0] != '#') {
|
|
|
|
structfield = true;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
goto more;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
\, {
|
|
|
|
if (braces == initializerbraces) {
|
|
|
|
initializerbraces = -1;
|
2023-08-04 15:09:58 -04:00
|
|
|
initializer = false;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
2023-08-04 15:09:58 -04:00
|
|
|
structfield = false;
|
2023-07-27 14:04:50 -04:00
|
|
|
goto more;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
; { /* if the enum/struct/union was not a definition */
|
|
|
|
if (braces == 0) {
|
2023-08-04 15:09:58 -04:00
|
|
|
esudef = false;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
/* if the end of a typedef */
|
|
|
|
if (braces == typedefbraces) {
|
|
|
|
typedefbraces = -1;
|
|
|
|
}
|
|
|
|
/* if the end of a external definition */
|
|
|
|
if (braces == externalbraces) {
|
|
|
|
externalbraces = -1;
|
2023-08-04 15:09:58 -04:00
|
|
|
external = false;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
2023-08-04 15:09:58 -04:00
|
|
|
structfield = false;
|
|
|
|
initializer = false;
|
2023-07-27 14:04:50 -04:00
|
|
|
goto more;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
<IN_PREPROC>define{ws}+{identifier} {
|
2023-08-04 14:34:51 -04:00
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
/* preprocessor macro or constant definition */
|
2023-08-04 15:09:58 -04:00
|
|
|
ppdefine = true;
|
2023-07-27 14:04:50 -04:00
|
|
|
token = DEFINE;
|
2023-08-04 15:09:58 -04:00
|
|
|
if (compress == true) {
|
2023-07-27 14:04:50 -04:00
|
|
|
my_yytext[0] = '\1'; /* compress the keyword */
|
|
|
|
}
|
|
|
|
findident:
|
|
|
|
/* search backwards through yytext[] to find the identifier */
|
2023-08-04 15:09:58 -04:00
|
|
|
/* falseTE: this had better be left to flex, by use of
|
2023-07-27 14:04:50 -04:00
|
|
|
* yet another starting condition */
|
|
|
|
my_yymore();
|
|
|
|
first = my_yyleng - 1;
|
|
|
|
while (my_yytext[first] != ' ' && my_yytext[first] != '\t') {
|
|
|
|
--first;
|
|
|
|
}
|
|
|
|
++first;
|
|
|
|
last = my_yyleng;
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
goto definition;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
<IN_PREPROC>\n { /* unknown preprocessor line */
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
++myylineno;
|
|
|
|
goto more;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
<IN_PREPROC>. |
|
|
|
|
<IN_PREPROC>{identifier} { /* unknown preprocessor line */
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
goto more;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class{wsnl}+{identifier}({wsnl}|{identifier}|[():])*\{ { /* class definition */
|
2023-08-04 15:09:58 -04:00
|
|
|
classdef = true;
|
2023-07-27 14:04:50 -04:00
|
|
|
tagdef = 'c';
|
|
|
|
yyless(5); /* eat up 'class', and re-scan */
|
|
|
|
yy_set_bol(0);
|
|
|
|
goto more;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
("enum"|"struct"|"union") {
|
|
|
|
ident_start = first;
|
|
|
|
BEGIN(WAS_ESU);
|
|
|
|
goto more;
|
|
|
|
}
|
|
|
|
<WAS_ESU>{
|
|
|
|
({wsnl}+{identifier}){wsnl}*\{ { /* e/s/u definition */
|
|
|
|
tagdef = my_yytext[ident_start];
|
|
|
|
BEGIN(WAS_IDENTIFIER);
|
|
|
|
goto ident;
|
|
|
|
}
|
|
|
|
{wsnl}*\{ { /* e/s/u definition without a tag */
|
|
|
|
tagdef = my_yytext[ident_start];
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
if (braces == 0) {
|
2023-08-04 15:09:58 -04:00
|
|
|
esudef = true;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
last = first;
|
|
|
|
yyless(0); /* re-scan all this as normal text */
|
|
|
|
tagdef = '\0';
|
|
|
|
goto more;
|
|
|
|
}
|
2023-08-04 14:34:51 -04:00
|
|
|
({wsnl}+{identifier})?{wsnl}* |
|
2023-07-27 14:04:50 -04:00
|
|
|
.|\n { /* e/s/u usage */
|
|
|
|
BEGIN(WAS_IDENTIFIER);
|
|
|
|
goto ident;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if{wsnl}*\( { /* ignore 'if' */
|
|
|
|
yyless(2);
|
|
|
|
yy_set_bol(0);
|
|
|
|
goto more;
|
2023-08-04 14:34:51 -04:00
|
|
|
}
|
2023-07-27 14:04:50 -04:00
|
|
|
|
|
|
|
{identifier} { /* identifier found: do nothing, yet. (!) */
|
|
|
|
BEGIN(WAS_IDENTIFIER);
|
|
|
|
ident_start = first;
|
|
|
|
goto more;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
|
2023-08-04 14:34:51 -04:00
|
|
|
<WAS_IDENTIFIER>{
|
2023-07-27 14:04:50 -04:00
|
|
|
{ws}*\(({wsnl}|{identifier}|{number}|[*&[\]=,.:])*\)([()]|{wsnl})*[:a-zA-Z_#{] {
|
|
|
|
/* a function definition */
|
2023-08-04 14:34:51 -04:00
|
|
|
/* note: "#define a (b) {" and "#if defined(a)\n#"
|
2023-07-27 14:04:50 -04:00
|
|
|
* are not fcn definitions! */
|
2023-08-04 14:34:51 -04:00
|
|
|
/* warning: "if (...)" must not overflow yytext,
|
|
|
|
* so the content of function argument definitions
|
|
|
|
* is restricted, in particular parentheses are
|
2023-07-27 14:04:50 -04:00
|
|
|
* not allowed */
|
|
|
|
/* FIXME HBB 20001003: the above 'not allowed' may well be the
|
|
|
|
* reason for the parsing bug concerning function pointer usage,
|
|
|
|
* I suspect. --- I think my new special-case rule for 'if'
|
|
|
|
* could be helpful in removing that limitation */
|
2023-08-04 15:09:58 -04:00
|
|
|
if ((braces == 0 && ppdefine == false && my_yytext[0] != '#' && rules == false) ||
|
|
|
|
(braces == 1 && classdef == true)) {
|
|
|
|
fcndef = true;
|
2023-07-27 14:04:50 -04:00
|
|
|
token = FCNDEF;
|
|
|
|
goto fcn;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
goto fcncal;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
{ws}*\(([*&[\]=,.]|{identifier}|{number}|{wsnl})* { /* function call */
|
2023-08-04 15:09:58 -04:00
|
|
|
fcncal: if (fcndef == true || ppdefine == true || rules == true) {
|
2023-07-27 14:04:50 -04:00
|
|
|
token = FCNCALL;
|
|
|
|
goto fcn;
|
2023-08-12 16:35:41 -04:00
|
|
|
/* NOTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
2023-08-04 15:09:58 -04:00
|
|
|
if (template == false) {
|
2023-07-27 14:04:50 -04:00
|
|
|
templateparens = parens;
|
2023-08-04 15:09:58 -04:00
|
|
|
template = true;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
goto ident;
|
2023-08-04 15:09:58 -04:00
|
|
|
/* falseTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
("*"|{wsnl})+{identifier} { /* typedef name or modifier use */
|
|
|
|
goto ident;
|
2023-08-04 15:09:58 -04:00
|
|
|
/* falseTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
.|\n { /* general identifer usage */
|
|
|
|
char *s;
|
|
|
|
|
2023-08-04 15:09:58 -04:00
|
|
|
if (global == true && ppdefine == false && my_yytext[0] != '#' &&
|
|
|
|
external == false && initializer == false &&
|
|
|
|
arraydimension == false && structfield == false &&
|
|
|
|
template == false && fcndef == false) {
|
|
|
|
if (esudef == true) {
|
2023-07-27 14:04:50 -04:00
|
|
|
/* if enum/struct/union */
|
|
|
|
token = MEMBERDEF;
|
|
|
|
} else {
|
|
|
|
token = GLOBALDEF;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ident:
|
|
|
|
token = IDENT;
|
|
|
|
}
|
|
|
|
fcn:
|
|
|
|
if (YYSTATE == WAS_IDENTIFIER) {
|
|
|
|
/* Position back to the actual identifier: */
|
2023-08-04 14:34:51 -04:00
|
|
|
last = first;
|
2023-07-27 14:04:50 -04:00
|
|
|
first = ident_start;
|
|
|
|
yyless(0);
|
|
|
|
/* HBB 20001008: if the anti-backup-pattern above matched,
|
|
|
|
* and the matched context ended with a \n, then the scanner
|
|
|
|
* believes it's at the start of a new line. But the yyless()
|
|
|
|
* should feeds that \n back into the input, so that's
|
|
|
|
* wrong. --> force 'beginning-of-line' status off. */
|
|
|
|
yy_set_bol(0);
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
} else {
|
|
|
|
my_yymore();
|
|
|
|
last = my_yyleng;
|
|
|
|
}
|
|
|
|
definition:
|
|
|
|
|
|
|
|
/* if a long line */
|
|
|
|
if (yyleng > STMTMAX) {
|
|
|
|
int c;
|
2023-08-04 14:34:51 -04:00
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
/* skip to the end of the line */
|
|
|
|
warning("line too long");
|
2023-08-04 14:34:51 -04:00
|
|
|
while ((c = input()) > LEXEOF) {
|
2023-07-27 14:04:50 -04:00
|
|
|
if (c == '\n') {
|
|
|
|
unput(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* truncate a long symbol */
|
|
|
|
if (yyleng > PATLEN) {
|
|
|
|
warning("symbol too long");
|
|
|
|
my_yyleng = first + PATLEN;
|
|
|
|
my_yytext[my_yyleng] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if found word was a keyword: */
|
|
|
|
if ((s = lookup(my_yytext + first)) != NULL) {
|
|
|
|
first = my_yyleng;
|
2023-08-04 14:34:51 -04:00
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
/* if the start of a typedef */
|
|
|
|
if (s == typedeftext) {
|
|
|
|
typedefbraces = braces;
|
2023-08-04 15:09:58 -04:00
|
|
|
oldtype = true;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
/* if an enum/struct/union */
|
|
|
|
/* (needed for "typedef struct tag name;" so
|
|
|
|
tag isn't marked as the typedef name) */
|
|
|
|
else if (s == enumtext || s == structtext || s == uniontext) {
|
|
|
|
/* do nothing */
|
|
|
|
} else if (s == externtext) {
|
|
|
|
/* if an external definition */
|
|
|
|
externalbraces = braces;
|
2023-08-04 15:09:58 -04:00
|
|
|
external = true;
|
|
|
|
} else if (templateparens == parens && template == true) {
|
2023-08-04 14:34:51 -04:00
|
|
|
/* keyword doesn't start a function
|
2023-07-27 14:04:50 -04:00
|
|
|
* template */
|
|
|
|
templateparens = -1;
|
2023-08-04 15:09:58 -04:00
|
|
|
template = false;
|
2023-08-04 14:34:51 -04:00
|
|
|
} else {
|
|
|
|
/* identifier after typedef was a
|
2023-07-27 14:04:50 -04:00
|
|
|
* keyword */
|
2023-08-04 15:09:58 -04:00
|
|
|
oldtype = false;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
2023-08-04 14:34:51 -04:00
|
|
|
} else {
|
2023-07-27 14:04:50 -04:00
|
|
|
/* not a keyword --> found an identifier */
|
|
|
|
/* last = yyleng; */
|
2023-08-04 14:34:51 -04:00
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
/* if a class/enum/struct/union tag definition */
|
|
|
|
/* FIXME HBB 20001001: why reject "class"? */
|
|
|
|
if (tagdef && strnotequal(my_yytext + first, "class")) {
|
|
|
|
token = tagdef;
|
|
|
|
tagdef = '\0';
|
|
|
|
if (braces == 0) {
|
2023-08-04 15:09:58 -04:00
|
|
|
esudef = true;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
2023-08-04 15:09:58 -04:00
|
|
|
} else if (braces == typedefbraces && oldtype == false &&
|
|
|
|
arraydimension == false) {
|
2023-07-27 14:04:50 -04:00
|
|
|
/* if a typedef name */
|
|
|
|
token = TYPEDEF;
|
|
|
|
} else {
|
2023-08-04 15:09:58 -04:00
|
|
|
oldtype = false;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
/* my_yymore(); */
|
|
|
|
return(token);
|
2023-08-04 15:09:58 -04:00
|
|
|
/* falseTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
\[ { /* array dimension (don't worry or about subscripts) */
|
2023-08-04 15:09:58 -04:00
|
|
|
arraydimension = true;
|
2023-07-27 14:04:50 -04:00
|
|
|
goto more;
|
2023-08-04 15:09:58 -04:00
|
|
|
/* falseTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
\] {
|
2023-08-04 15:09:58 -04:00
|
|
|
arraydimension = false;
|
2023-07-27 14:04:50 -04:00
|
|
|
goto more;
|
2023-08-04 15:09:58 -04:00
|
|
|
/* falseTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
\\\n { /* preprocessor statement is continued on next line */
|
|
|
|
/* save the '\\' to the output file, but not the '\n': */
|
|
|
|
yyleng = 1;
|
|
|
|
my_yymore();
|
|
|
|
goto eol;
|
2023-08-04 15:09:58 -04:00
|
|
|
/* falseTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
\n { /* end of the line */
|
2023-08-04 15:09:58 -04:00
|
|
|
if (ppdefine == true) { /* end of a #define */
|
|
|
|
ppdefine = false;
|
2023-07-27 14:04:50 -04:00
|
|
|
yyless(yyleng - 1);
|
|
|
|
last = first;
|
|
|
|
my_yymore();
|
|
|
|
return(DEFINEEND);
|
|
|
|
}
|
|
|
|
/* skip the first 8 columns of a breakpoint listing line */
|
|
|
|
/* and skip the file path in the page header */
|
2023-08-04 15:09:58 -04:00
|
|
|
if (bplisting == true) {
|
2023-07-27 14:04:50 -04:00
|
|
|
int c, i;
|
|
|
|
|
|
|
|
/* FIXME HBB 20001007: should call input() instead */
|
|
|
|
switch (input()) { /* tab and EOF just fall through */
|
|
|
|
case ' ': /* breakpoint number line */
|
|
|
|
case '[':
|
|
|
|
for (i = 1; i < 8 && input() > LEXEOF; ++i)
|
|
|
|
;
|
|
|
|
break;
|
|
|
|
case '.': /* header line */
|
|
|
|
case '/':
|
|
|
|
/* skip to the end of the line */
|
|
|
|
while ((c = input()) > LEXEOF) {
|
|
|
|
if (c == '\n') {
|
|
|
|
unput(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '\n': /* empty line */
|
|
|
|
unput('\n');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
eol:
|
|
|
|
++myylineno;
|
|
|
|
first = 0;
|
|
|
|
last = 0;
|
|
|
|
if (symbols > 0) {
|
|
|
|
/* no my_yymore(): \n doesn't need to be in my_yytext */
|
|
|
|
return(NEWLINE);
|
|
|
|
}
|
|
|
|
/* line ended --> flush my_yytext */
|
|
|
|
if (my_yytext)
|
|
|
|
*my_yytext = '\0';
|
|
|
|
my_yyleng = 0;
|
|
|
|
lineno = myylineno;
|
|
|
|
}
|
|
|
|
|
|
|
|
\' { /* character constant */
|
2023-08-04 15:09:58 -04:00
|
|
|
if (sdl == false)
|
2023-07-27 14:04:50 -04:00
|
|
|
BEGIN(IN_SQUOTE);
|
|
|
|
goto more;
|
2023-08-04 15:09:58 -04:00
|
|
|
/* falseTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
2023-08-04 14:34:51 -04:00
|
|
|
<IN_SQUOTE>\' {
|
2023-07-27 14:04:50 -04:00
|
|
|
BEGIN(INITIAL);
|
|
|
|
goto more;
|
2023-08-04 15:09:58 -04:00
|
|
|
/* falseTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
\" { /* string constant */
|
|
|
|
BEGIN(IN_DQUOTE);
|
|
|
|
goto more;
|
2023-08-04 15:09:58 -04:00
|
|
|
/* falseTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
2023-08-04 14:34:51 -04:00
|
|
|
<IN_DQUOTE>\" {
|
2023-07-27 14:04:50 -04:00
|
|
|
BEGIN(INITIAL);
|
|
|
|
goto more;
|
2023-08-04 15:09:58 -04:00
|
|
|
/* falseTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
<IN_DQUOTE,IN_SQUOTE>{
|
|
|
|
\n { /* syntax error: unexpected EOL */
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
goto eol;
|
2023-08-04 15:09:58 -04:00
|
|
|
/* falseTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
\\. |
|
|
|
|
. {
|
|
|
|
goto more;
|
2023-08-04 15:09:58 -04:00
|
|
|
/* falseTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
\\\n { /* line continuation inside a string! */
|
|
|
|
myylineno++;
|
|
|
|
goto more;
|
2023-08-04 15:09:58 -04:00
|
|
|
/* falseTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
}
|
2023-08-04 14:34:51 -04:00
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
^{ws}+ { /* don't save leading white space */
|
|
|
|
}
|
2023-08-04 14:34:51 -04:00
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
{ws}+\n { /* eat whitespace at end of line */
|
|
|
|
unput('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
[\t\r\v\f]+ { /* eat non-blank whitespace sequences, replace
|
|
|
|
* by single blank */
|
|
|
|
unput(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
{ws}{2,} { /* compress sequential whitespace here, not in putcrossref() */
|
|
|
|
unput(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
"/*" yy_push_state(COMMENT);
|
|
|
|
<COMMENT>{
|
|
|
|
[^*\n]* |
|
|
|
|
"*"+[^*/\n]* ; /* do nothing */
|
|
|
|
[^*\n]*\n |
|
|
|
|
"*"+[^*/\n]*\n {
|
2023-08-04 15:09:58 -04:00
|
|
|
if (ppdefine == false) {
|
2023-07-27 14:04:50 -04:00
|
|
|
goto eol;
|
|
|
|
} else {
|
|
|
|
++myylineno;
|
|
|
|
}
|
2023-08-04 15:09:58 -04:00
|
|
|
/* falseTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
"*"+"/" {
|
|
|
|
/* replace the comment by a single blank */
|
|
|
|
unput(' ');
|
|
|
|
yy_pop_state();
|
|
|
|
}
|
2023-08-04 14:34:51 -04:00
|
|
|
}
|
2023-07-27 14:04:50 -04:00
|
|
|
|
|
|
|
"//".*\n? {
|
|
|
|
/* C++-style one-line comment */
|
|
|
|
goto eol;
|
2023-08-04 15:09:58 -04:00
|
|
|
/* falseTREACHED */
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
{number} | /* number */
|
|
|
|
<SDL>STATE[ \t]+ | /* ... and other syntax error catchers... */
|
|
|
|
. { /* punctuation and operators */
|
2023-08-04 14:34:51 -04:00
|
|
|
more:
|
2023-07-27 14:04:50 -04:00
|
|
|
my_yymore();
|
|
|
|
first = my_yyleng;
|
|
|
|
}
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
void
|
|
|
|
initscanner(char *srcfile)
|
|
|
|
{
|
|
|
|
char *s;
|
2023-08-04 14:34:51 -04:00
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
if (maxifbraces == NULL) {
|
|
|
|
maxifbraces = malloc(miflevel * sizeof(*maxifbraces));
|
|
|
|
preifbraces = malloc(miflevel * sizeof(*preifbraces));
|
|
|
|
}
|
|
|
|
first = 0; /* buffer index for first char of symbol */
|
|
|
|
last = 0; /* buffer index for last char of symbol */
|
|
|
|
lineno = 1; /* symbol line number */
|
|
|
|
myylineno = 1; /* input line number */
|
2023-08-04 15:09:58 -04:00
|
|
|
arraydimension = false; /* inside array dimension declaration */
|
|
|
|
bplisting = false; /* breakpoint listing */
|
2023-07-27 14:04:50 -04:00
|
|
|
braces = 0; /* unmatched left brace count */
|
2023-08-04 15:09:58 -04:00
|
|
|
classdef = false; /* c++ class definition */
|
|
|
|
elseelif = false; /* #else or #elif found */
|
|
|
|
esudef = false; /* enum/struct/union global definition */
|
|
|
|
external = false; /* external definition */
|
2023-07-27 14:04:50 -04:00
|
|
|
externalbraces = -1; /* external definition outer brace count */
|
2023-08-04 15:09:58 -04:00
|
|
|
fcndef = false; /* function definition */
|
|
|
|
global = true; /* file global scope (outside functions) */
|
2023-07-27 14:04:50 -04:00
|
|
|
iflevel = 0; /* #if nesting level */
|
2023-08-04 15:09:58 -04:00
|
|
|
initializer = false; /* data initializer */
|
2023-07-27 14:04:50 -04:00
|
|
|
initializerbraces = -1; /* data initializer outer brace count */
|
2023-08-04 15:09:58 -04:00
|
|
|
lex = false; /* lex file */
|
2023-07-27 14:04:50 -04:00
|
|
|
parens = 0; /* unmatched left parenthesis count */
|
2023-08-04 15:09:58 -04:00
|
|
|
ppdefine = false; /* preprocessor define statement */
|
|
|
|
pseudoelif = false; /* pseudo-#elif */
|
|
|
|
oldtype = false; /* next identifier is an old type */
|
|
|
|
rules = false; /* lex/yacc rules */
|
|
|
|
sdl = false; /* sdl file */
|
|
|
|
structfield = false; /* structure field declaration */
|
2023-07-27 14:04:50 -04:00
|
|
|
tagdef = '\0'; /* class/enum/struct/union tag definition */
|
2023-08-04 15:09:58 -04:00
|
|
|
template = false; /* function template */
|
2023-07-27 14:04:50 -04:00
|
|
|
templateparens = -1; /* function template outer parentheses count */
|
|
|
|
typedefbraces = -1; /* initial typedef braces count */
|
|
|
|
ident_start = 0; /* start of previously found identifier */
|
|
|
|
|
|
|
|
if (my_yytext)
|
|
|
|
*my_yytext = '\0';
|
|
|
|
my_yyleng = 0;
|
2023-08-04 14:34:51 -04:00
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
BEGIN(INITIAL);
|
|
|
|
|
|
|
|
/* if this is not a C file */
|
|
|
|
if ((s = strrchr(srcfile, '.')) != NULL) {
|
|
|
|
switch (*++s) { /* this switch saves time on C files */
|
|
|
|
case 'b':
|
|
|
|
if (strcmp(s, "bp") == 0) { /* breakpoint listing */
|
2023-08-04 15:09:58 -04:00
|
|
|
bplisting = true;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
if (strcmp(s, "l") == 0) { /* lex */
|
2023-08-04 15:09:58 -04:00
|
|
|
lex = true;
|
|
|
|
global = false;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
if (strcmp(s, "sd") == 0) { /* sdl */
|
2023-08-04 15:09:58 -04:00
|
|
|
sdl = true;
|
2023-07-27 14:04:50 -04:00
|
|
|
BEGIN(SDL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'y':
|
|
|
|
if (strcmp(s, "y") == 0) { /* yacc */
|
2023-08-04 15:09:58 -04:00
|
|
|
global = false;
|
2023-07-27 14:04:50 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MY_YY_ALLOCSTEP 1000
|
|
|
|
static void
|
|
|
|
my_yymore(void)
|
|
|
|
{
|
|
|
|
static size_t yytext_size = 0;
|
2023-08-04 14:34:51 -04:00
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
/* my_yytext is an ever-growing buffer. It will not ever
|
|
|
|
* shrink, nor will it be freed at end of program, for now */
|
|
|
|
while (my_yyleng + yyleng + 1 >= yytext_size) {
|
|
|
|
my_yytext = realloc(my_yytext, yytext_size += MY_YY_ALLOCSTEP);
|
|
|
|
}
|
2023-08-04 14:34:51 -04:00
|
|
|
|
2023-07-27 14:04:50 -04:00
|
|
|
strncpy (my_yytext + my_yyleng, yytext, yyleng+1);
|
|
|
|
my_yyleng += yyleng;
|
|
|
|
}
|