From: Vern Paxson Date: Sun, 5 Mar 1995 20:37:26 +0000 (+0000) Subject: added yyclass X-Git-Tag: flex-2-5-5b~97 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6534e3e967a4478c79b3622140a55b0d1c27b1b8;p=flex added yyclass --- diff --git a/flexdef.h b/flexdef.h index cc241a7..0ebff13 100644 --- a/flexdef.h +++ b/flexdef.h @@ -406,6 +406,7 @@ extern int yymore_really_used, reject_really_used; * outfilename - name of output file * did_outfilename - whether outfilename was explicitly set * prefix - the prefix used for externally visible names ("yy" by default) + * yyclass - yyFlexLexer subclass to use for YY_DECL * do_stdinit - whether to initialize yyin/yyout to stdin/stdout * use_stdout - the -t flag * input_files - array holding names of input files @@ -428,7 +429,7 @@ extern const char *skel[]; extern int skel_ind; extern char *infilename, *outfilename; extern int did_outfilename; -extern char *prefix; +extern char *prefix, *yyclass; extern int do_stdinit, use_stdout; extern char **input_files; extern int num_input_files; diff --git a/main.c b/main.c index 2a1902d..40bd769 100644 --- a/main.c +++ b/main.c @@ -66,7 +66,7 @@ char *action_array; int action_size, defs1_offset, prolog_offset, action_offset, action_index; char *infilename = NULL, *outfilename = NULL; int did_outfilename; -char *prefix; +char *prefix, *yyclass; int do_stdinit, use_stdout; int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE]; int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp; @@ -576,6 +576,7 @@ char **argv; performance_report = 0; did_outfilename = 0; prefix = "yy"; + yyclass = 0; use_read = use_stdout = false; sawcmpflag = false; @@ -965,8 +966,22 @@ _( "Variable trailing context rules entail a large performance penalty\n" ) ); } if ( C_plus_plus ) + { outn( "\n#include " ); + if ( yyclass ) + { + outn( "int yyFlexLexer::yylex()" ); + outn( "\t{" ); + outn( +"\tLexerError( \"yyFlexLexer::yylex invoked but %option yyclass used\" );" ); + outn( "\t}" ); + + out_str( "\n#define YY_DECL int %s::yylex()\n", + yyclass ); + } + } + else { if ( yytext_is_array ) @@ -977,6 +992,10 @@ _( "Variable trailing context rules entail a large performance penalty\n" ) ); outn( "extern char *yytext;" ); outn( "#define yytext_ptr yytext" ); } + + if ( yyclass ) + flexerror( + _( "%option yyclass only meaningful for C++ scanners" ) ); } if ( useecs ) diff --git a/scan.l b/scan.l index 748a0cb..2bff1b2 100644 --- a/scan.l +++ b/scan.l @@ -273,6 +273,7 @@ LEXOPT [aceknopr] outfile return OPT_OUTFILE; prefix return OPT_PREFIX; + yyclass return OPT_YYCLASS; \"[^"\n]*\" { strcpy( nmstr, yytext + 1 );