From: Vern Paxson Date: Mon, 15 Jan 1990 18:02:29 +0000 (+0000) Subject: 8-bit char support. X-Git-Tag: flex-2-5-5b~568 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f61a9c1928cd6229d1560a5d6a16ef01efe9bcb1;p=flex 8-bit char support. Arbitrary indented/%{} code allowed in section 2. \x escapes. %t support. Minor POSIX-compliance changes. BEGIN(0) -> BEGIN(INITIAL). yywrap() and set_input_file() for multiple input files. C_COMMENT_2 removed. 2.2 Release. --- diff --git a/scan.l b/scan.l index 8c40174..dfc1d47 100644 --- a/scan.l +++ b/scan.l @@ -49,12 +49,12 @@ static char rcsid[] = return ( CHAR ); #define RETURNNAME \ - (void) strcpy( nmstr, yytext ); \ + (void) strcpy( nmstr, (char *) yytext ); \ return ( NAME ); #define PUT_BACK_STRING(str, start) \ - for ( i = strlen( str ) - 1; i >= start; --i ) \ - unput(str[i]) + for ( i = strlen( (char *) str ) - 1; i >= start; --i ) \ + unput((str)[i]) #define CHECK_REJECT(str) \ if ( all_upper( str ) ) \ @@ -63,11 +63,13 @@ static char rcsid[] = #define CHECK_YYMORE(str) \ if ( all_lower( str ) ) \ yymore_used = true; + +#undef yywrap %} %x SECT2 SECT2PROLOG SECT3 CODEBLOCK PICKUPDEF SC CARETISBOL NUM QUOTE -%x FIRSTCCL CCL ACTION RECOVER BRACEERROR C_COMMENT C_COMMENT_2 ACTION_COMMENT -%x ACTION_STRING PERCENT_BRACE_ACTION USED_LIST +%x FIRSTCCL CCL ACTION RECOVER BRACEERROR C_COMMENT ACTION_COMMENT +%x ACTION_STRING PERCENT_BRACE_ACTION USED_LIST CODEBLOCK_2 XLATION WS [ \t\f]+ OPTWS [ \t\f]* @@ -78,18 +80,19 @@ NOT_NAME [^a-z_\n]+ SCNAME {NAME} -ESCSEQ \\([^\n]|[0-9]{1,3}) +ESCSEQ \\([^\n]|[0-9]{1,3}|x[0-9a-f]{1,2}) %% static int bracelevel, didadef; - int i, indented_code, checking_used; - char nmdef[MAXLINE], myesc(); + int i, indented_code, checking_used, new_xlation; + int doing_codeblock = false; + Char nmdef[MAXLINE], myesc(); ^{WS} indented_code = true; BEGIN(CODEBLOCK); ^#.*\n ++linenum; ECHO; /* treat as a comment */ ^"/*" ECHO; BEGIN(C_COMMENT); -^"%s"(tart)? return ( SCDECL ); -^"%x" return ( XSCDECL ); +^"%s"{NAME}? return ( SCDECL ); +^"%x"{NAME}? return ( XSCDECL ); ^"%{".*\n { ++linenum; line_directive_out( stdout ); @@ -106,37 +109,68 @@ ESCSEQ \\([^\n]|[0-9]{1,3}) return ( SECTEND ); } -^"%used" checking_used = REALLY_USED; BEGIN(USED_LIST); -^"%unused" checking_used = REALLY_NOT_USED; BEGIN(USED_LIST); +^"%used" { + pinpoint_message( "Warning, %%used/%%unused have been deprecated" ); + checking_used = REALLY_USED; BEGIN(USED_LIST); + } +^"%unused" { + checking_used = REALLY_NOT_USED; BEGIN(USED_LIST); + pinpoint_message( "Warning, %%used/%%unused have been deprecated" ); + checking_used = REALLY_NOT_USED; BEGIN(USED_LIST); + } -^"%"[^sx]" ".*\n { +^"%"[aeknopt]" ".*\n { +#ifdef NOTDEF fprintf( stderr, "old-style lex command at line %d ignored:\n\t%s", linenum, yytext ); +#endif ++linenum; } +^"%"[cr]{OPTWS} /* ignore old lex directive */ + +%t{OPTWS}\n { + char *malloc(); + + ++linenum; + xlation = (int *) malloc( sizeof( int ) * (csize + 1) ); + + for ( i = 1; i <= csize; ++i ) + xlation[i] = 0; + + if ( ! xlation ) + flexfatal( + "dynamic memory failure building %t table" ); + + num_xlations = 0; + + BEGIN(XLATION); + } + +^"%"[^sxanpekotcru{}]{OPTWS} synerr( "unrecognized '%' directive" ); + ^{NAME} { - (void) strcpy( nmstr, yytext ); + (void) strcpy( nmstr, (char *) yytext ); didadef = false; BEGIN(PICKUPDEF); } {SCNAME} RETURNNAME; ^{OPTWS}\n ++linenum; /* allows blank lines in section 1 */ -\n ++linenum; return ( '\n' ); +{OPTWS}\n ++linenum; return ( '\n' ); . synerr( "illegal character" ); BEGIN(RECOVER); -"*/" ECHO; BEGIN(0); -"*/".*\n ++linenum; ECHO; BEGIN(0); +"*/" ECHO; BEGIN(INITIAL); +"*/".*\n ++linenum; ECHO; BEGIN(INITIAL); [^*\n]+ ECHO; "*" ECHO; \n ++linenum; ECHO; -^"%}".*\n ++linenum; BEGIN(0); +^"%}".*\n ++linenum; BEGIN(INITIAL); "reject" ECHO; CHECK_REJECT(yytext); "yymore" ECHO; CHECK_YYMORE(yytext); {NAME}|{NOT_NAME}|. ECHO; @@ -144,16 +178,16 @@ ESCSEQ \\([^\n]|[0-9]{1,3}) ++linenum; ECHO; if ( indented_code ) - BEGIN(0); + BEGIN(INITIAL); } {WS} /* separates name and definition */ {NOT_WS}.* { - (void) strcpy( nmdef, yytext ); + (void) strcpy( (char *) nmdef, (char *) yytext ); - for ( i = strlen( nmdef ) - 1; + for ( i = strlen( (char *) nmdef ) - 1; i >= 0 && nmdef[i] == ' ' || nmdef[i] == '\t'; --i ) @@ -168,14 +202,14 @@ ESCSEQ \\([^\n]|[0-9]{1,3}) \n { if ( ! didadef ) synerr( "incomplete name definition" ); - BEGIN(0); + BEGIN(INITIAL); ++linenum; } -.*\n ++linenum; BEGIN(0); RETURNNAME; +.*\n ++linenum; BEGIN(INITIAL); RETURNNAME; -\n ++linenum; BEGIN(0); +\n ++linenum; BEGIN(INITIAL); {WS} "reject" { if ( all_upper( yytext ) ) @@ -192,6 +226,25 @@ ESCSEQ \\([^\n]|[0-9]{1,3}) {NOT_WS}+ synerr( "unrecognized %used/%unused construct" ); +"%t"{OPTWS}\n ++linenum; BEGIN(INITIAL); +^{OPTWS}[0-9]+ ++num_xlations; new_xlation = true; +^. synerr( "bad row in translation table" ); +{WS} /* ignore whitespace */ + +{ESCSEQ} { + xlation[myesc( yytext )] = + (new_xlation ? num_xlations : -num_xlations); + new_xlation = false; + } +. { + xlation[yytext[0]] = + (new_xlation ? num_xlations : -num_xlations); + new_xlation = false; + } + +\n ++linenum; + + .*\n/{NOT_WS} { ++linenum; ACTION_ECHO; @@ -205,14 +258,15 @@ ESCSEQ \\([^\n]|[0-9]{1,3}) ^{OPTWS}\n ++linenum; /* allow blank lines in section 2 */ - /* this horrible mess of a rule matches indented lines which - * do not contain "/*". We need to make the distinction because - * otherwise this rule will be taken instead of the rule which - * matches the beginning of comments like this one - */ -^{WS}([^/\n]|"/"[^*\n])*("/"?)\n { - synerr( "indented code found outside of action" ); - ++linenum; +^({WS}|"%{") { + indented_code = (yytext[0] != '%'); + doing_codeblock = true; + bracelevel = 1; + + if ( indented_code ) + ACTION_ECHO; + + BEGIN(CODEBLOCK_2); } "<" BEGIN(SC); return ( '<' ); @@ -229,8 +283,6 @@ ESCSEQ \\([^\n]|[0-9]{1,3}) } {WS}"|".*\n continued_action = true; ++linenum; return ( '\n' ); -^{OPTWS}"/*" ACTION_ECHO; BEGIN(C_COMMENT_2); - {WS} { /* this rule is separate from the one below because * otherwise we get variable trailing context, so @@ -262,10 +314,10 @@ ESCSEQ \\([^\n]|[0-9]{1,3}) "["([^\\\]\n]|{ESCSEQ})+"]" { int cclval; - (void) strcpy( nmstr, yytext ); + (void) strcpy( nmstr, (char *) yytext ); /* check to see if we've already encountered this ccl */ - if ( (cclval = ccllookup( nmstr )) ) + if ( (cclval = ccllookup( (Char *) nmstr )) ) { yylval = cclval; ++cclreuse; @@ -276,12 +328,12 @@ ESCSEQ \\([^\n]|[0-9]{1,3}) /* we fudge a bit. We know that this ccl will * soon be numbered as lastccl + 1 by cclinit */ - cclinstal( nmstr, lastccl + 1 ); + cclinstal( (Char *) nmstr, lastccl + 1 ); /* push back everything but the leading bracket * so the ccl can be rescanned */ - PUT_BACK_STRING(nmstr, 1); + PUT_BACK_STRING((char *) nmstr, 1); BEGIN(FIRSTCCL); return ( '[' ); @@ -289,10 +341,10 @@ ESCSEQ \\([^\n]|[0-9]{1,3}) } "{"{NAME}"}" { - register char *nmdefptr; - char *ndlookup(); + register Char *nmdefptr; + Char *ndlookup(); - (void) strcpy( nmstr, yytext ); + (void) strcpy( nmstr, (char *) yytext ); nmstr[yyleng - 1] = '\0'; /* chop trailing brace */ /* lookup from "nmstr + 1" to chop leading brace */ @@ -368,21 +420,32 @@ ESCSEQ \\([^\n]|[0-9]{1,3}) \n synerr( "missing }" ); ++linenum; BEGIN(SECT2); -{OPTWS}"%}".* bracelevel = 0; -"reject" ACTION_ECHO; CHECK_REJECT(yytext); -"yymore" ACTION_ECHO; CHECK_YYMORE(yytext); -{NAME}|{NOT_NAME}|. ACTION_ECHO; -\n { +{OPTWS}"%}".* bracelevel = 0; +"reject" { + ACTION_ECHO; + CHECK_REJECT(yytext); + } +"yymore" { + ACTION_ECHO; + CHECK_YYMORE(yytext); + } +{NAME}|{NOT_NAME}|. ACTION_ECHO; +\n { ++linenum; ACTION_ECHO; - if ( bracelevel == 0 ) + if ( bracelevel == 0 || + (doing_codeblock && indented_code) ) { - fputs( "\tYY_BREAK\n", temp_action_file ); + if ( ! doing_codeblock ) + fputs( "\tYY_BREAK\n", temp_action_file ); + + doing_codeblock = false; BEGIN(SECT2); } } - /* REJECT and yymore() are checked for above, in PERCENT_BRACE_ACTION */ + + /* Reject and YYmore() are checked for above, in PERCENT_BRACE_ACTION */ "{" ACTION_ECHO; ++bracelevel; "}" ACTION_ECHO; --bracelevel; [^a-z_{}"'/\n]+ ACTION_ECHO; @@ -407,12 +470,6 @@ ESCSEQ \\([^\n]|[0-9]{1,3}) \n ++linenum; ACTION_ECHO; . ACTION_ECHO; -"*/" ACTION_ECHO; BEGIN(SECT2); -"*/".*\n ++linenum; ACTION_ECHO; BEGIN(SECT2); -[^*\n]+ ACTION_ECHO; -"*" ACTION_ECHO; -\n ++linenum; ACTION_ECHO; - [^"\\\n]+ ACTION_ECHO; \\. ACTION_ECHO; \n ++linenum; ACTION_ECHO; @@ -434,3 +491,40 @@ ESCSEQ \\([^\n]|[0-9]{1,3}) .*(\n?) ECHO; %% + + +int yywrap() + + { + if ( --num_input_files > 0 ) + { + set_input_file( *++input_files ); + return ( 0 ); + } + + else + return ( 1 ); + } + + +/* set_input_file - open the given file (if NULL, stdin) for scanning */ + +set_input_file( file ) +char *file; + + { + if ( file ) + { + infilename = file; + yyin = fopen( infilename, "r" ); + + if ( yyin == NULL ) + lerrsf( "can't open %s", file ); + } + + else + { + yyin = stdin; + infilename = ""; + } + }