From: Vern Paxson Date: Mon, 27 Dec 1993 10:36:59 +0000 (+0000) Subject: Modified to use scon scopes X-Git-Tag: flex-2-5-5b~221 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0f34dc3933484a44c49f00b1ba2b64377f293323;p=flex Modified to use scon scopes --- diff --git a/scan.l b/scan.l index ee8d866..786b938 100644 --- a/scan.l +++ b/scan.l @@ -88,20 +88,21 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) Char nmdef[MAXLINE], myesc(); -^{WS} indented_code = true; BEGIN(CODEBLOCK); -^"/*" ACTION_ECHO; yy_push_state( COMMENT ); -^"%s"{NAME}? return SCDECL; -^"%x"{NAME}? return XSCDECL; -^"%{".*{NL} { +{ + ^{WS} indented_code = true; BEGIN(CODEBLOCK); + ^"/*" ACTION_ECHO; yy_push_state( COMMENT ); + ^"%s"{NAME}? return SCDECL; + ^"%x"{NAME}? return XSCDECL; + ^"%{".*{NL} { ++linenum; line_directive_out( (FILE *) 0, 1 ); indented_code = false; BEGIN(CODEBLOCK); } -{WS} /* discard */ + {WS} /* discard */ -^"%%".* { + ^"%%".* { sectnum = 2; bracelevel = 0; mark_defs1(); @@ -110,14 +111,14 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) return SECTEND; } -^"%pointer".*{NL} { + ^"%pointer".*{NL} { if ( lex_compat ) warn( "%pointer incompatible with -l option" ); else yytext_is_array = false; ++linenum; } -^"%array".*{NL} { + ^"%array".*{NL} { if ( C_plus_plus ) warn( "%array incompatible with -+ option" ); else @@ -125,50 +126,57 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) ++linenum; } -^"%used" { + ^"%used" { warn( "%used/%unused have been deprecated" ); checking_used = REALLY_USED; BEGIN(USED_LIST); } -^"%unused" { + ^"%unused" { warn( "%used/%unused have been deprecated" ); checking_used = REALLY_NOT_USED; BEGIN(USED_LIST); } -^"%"[aceknopr]{OPTWS}[0-9]*{OPTWS}{NL} ++linenum; /* ignore */ + ^"%"[aceknopr]{OPTWS}[0-9]*{OPTWS}{NL} ++linenum; /* ignore */ -^"%"[^sxanpekotcru{}].* synerr( "unrecognized '%' directive" ); + ^"%"[^sxanpekotcru{}].* synerr( "unrecognized '%' directive" ); -^{NAME} { + ^{NAME} { strcpy( nmstr, yytext ); didadef = false; BEGIN(PICKUPDEF); } -{SCNAME} RETURNNAME; -^{OPTWS}{NL} ++linenum; /* allows blank lines in section 1 */ -{OPTWS}{NL} ACTION_ECHO; ++linenum; /* maybe end of comment line */ + {SCNAME} RETURNNAME; + ^{OPTWS}{NL} ++linenum; /* allows blank lines in section 1 */ + {OPTWS}{NL} ACTION_ECHO; ++linenum; /* maybe end of comment line */ +} -"*/" ACTION_ECHO; yy_pop_state(); -"*" ACTION_ECHO; -[^*\n]+ ACTION_ECHO; -[^*\n]*{NL} ++linenum; ACTION_ECHO; +{ + "*/" ACTION_ECHO; yy_pop_state(); + "*" ACTION_ECHO; + [^*\n]+ ACTION_ECHO; + [^*\n]*{NL} ++linenum; ACTION_ECHO; +} +{ + ^"%}".*{NL} ++linenum; BEGIN(INITIAL); -^"%}".*{NL} ++linenum; BEGIN(INITIAL); -{NAME}|{NOT_NAME}|. ACTION_ECHO; -{NL} { + {NAME}|{NOT_NAME}|. ACTION_ECHO; + + {NL} { ++linenum; ACTION_ECHO; if ( indented_code ) BEGIN(INITIAL); } +} -{WS} /* separates name and definition */ +{ + {WS} /* separates name and definition */ -{NOT_WS}.* { + {NOT_WS}.* { strcpy( (char *) nmdef, yytext ); /* Skip trailing whitespace. */ @@ -183,12 +191,13 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) didadef = true; } -{NL} { + {NL} { if ( ! didadef ) synerr( "incomplete name definition" ); BEGIN(INITIAL); ++linenum; } +} .*{NL} ++linenum; BEGIN(INITIAL); RETURNNAME; @@ -212,12 +221,13 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) {NOT_WS}+ synerr( "unrecognized %used/%unused construct" ); -^"%{".* ++bracelevel; yyless( 2 ); /* eat only %{ */ -^"%}".* --bracelevel; yyless( 2 ); /* eat only %} */ +{ + ^"%{".* ++bracelevel; yyless( 2 ); /* eat only %{ */ + ^"%}".* --bracelevel; yyless( 2 ); /* eat only %} */ -^{WS}.* ACTION_ECHO; /* indented code in prolog */ + ^{WS}.* ACTION_ECHO; /* indented code in prolog */ -^{NOT_WS}.* { /* non-indented code */ + ^{NOT_WS}.* { /* non-indented code */ if ( bracelevel <= 0 ) { /* not in %{ ... %} */ yyless( 0 ); /* put it all back */ @@ -228,31 +238,33 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) ACTION_ECHO; } -.* ACTION_ECHO; -{NL} ++linenum; ACTION_ECHO; + .* ACTION_ECHO; + {NL} ++linenum; ACTION_ECHO; -<> { + <> { mark_prolog(); sectnum = 0; yyterminate(); /* to stop the parser */ } +} -^{OPTWS}{NL} ++linenum; /* allow blank lines in section 2 */ +{ + ^{OPTWS}{NL} ++linenum; /* allow blank lines in section 2 */ -^{OPTWS}"%{" { + ^{OPTWS}"%{" { indented_code = false; doing_codeblock = true; bracelevel = 1; BEGIN(CODEBLOCK_2); } -^{OPTWS}"<" BEGIN(SC); return '<'; -^{OPTWS}"^" return '^'; -\" BEGIN(QUOTE); return '"'; -"{"/[0-9] BEGIN(NUM); return '{'; -"$"/([ \t]|{NL}) return '$'; + ^{OPTWS}"<" BEGIN(SC); return '<'; + ^{OPTWS}"^" return '^'; + \" BEGIN(QUOTE); return '"'; + "{"/[0-9] BEGIN(NUM); return '{'; + "$"/([ \t]|{NL}) return '$'; -{WS}"%{" { + {WS}"%{" { bracelevel = 1; BEGIN(PERCENT_BRACE_ACTION); @@ -263,18 +275,18 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) return '\n'; } } -{WS}"|".*{NL} continued_action = true; ++linenum; return '\n'; + {WS}"|".*{NL} continued_action = true; ++linenum; return '\n'; -^{WS}"/*" { + ^{WS}"/*" { yyless( yyleng - 2 ); /* put back '/', '*' */ bracelevel = 0; continued_action = false; BEGIN(ACTION); } -^{WS} /* allow indented rules */ + ^{WS} /* allow indented rules */ -{WS} { + {WS} { /* This rule is separate from the one below because * otherwise we get variable trailing context, so * we can't build the scanner using -{f,F}. @@ -291,7 +303,7 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) } } -{OPTWS}{NL} { + {OPTWS}{NL} { bracelevel = 0; continued_action = false; BEGIN(ACTION); @@ -305,16 +317,16 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) } } -^{OPTWS}"<>" | -"<>" return EOF_OP; + ^{OPTWS}"<>" | + "<>" return EOF_OP; -^"%%".* { + ^"%%".* { sectnum = 3; BEGIN(SECT3); yyterminate(); /* to stop the parser */ } -"["{FIRST_CCL_CHAR}{CCL_CHAR}* { + "["{FIRST_CCL_CHAR}{CCL_CHAR}* { int cclval; strcpy( nmstr, yytext ); @@ -348,7 +360,7 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) } } -"{"{NAME}"}" { + "{"{NAME}"}" { register Char *nmdefptr; Char *ndlookup(); @@ -381,84 +393,101 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) } } -[/|*+?.(){}] return (unsigned char) yytext[0]; -. RETURNCHAR; + [/|*+?.(){}] return (unsigned char) yytext[0]; + . RETURNCHAR; +} -[,*] return (unsigned char) yytext[0]; -">" BEGIN(SECT2); return '>'; -">"/^ BEGIN(CARETISBOL); return '>'; -{SCNAME} RETURNNAME; -. { - format_synerr( "bad : %s", yytext ); - } +{ + [,*] return (unsigned char) yytext[0]; + ">" BEGIN(SECT2); return '>'; + ">"/^ BEGIN(CARETISBOL); return '>'; + {SCNAME} RETURNNAME; + . format_synerr( "bad : %s", yytext ); +} "^" BEGIN(SECT2); return '^'; -[^"\n] RETURNCHAR; -\" BEGIN(SECT2); return '"'; +{ + [^"\n] RETURNCHAR; + \" BEGIN(SECT2); return '"'; -{NL} { + {NL} { synerr( "missing quote" ); BEGIN(SECT2); ++linenum; return '"'; } +} -"^"/[^-\]\n] BEGIN(CCL); return '^'; -"^"/("-"|"]") return '^'; -. BEGIN(CCL); RETURNCHAR; +{ + "^"/[^-\]\n] BEGIN(CCL); return '^'; + "^"/("-"|"]") return '^'; + . BEGIN(CCL); RETURNCHAR; +} --/[^\]\n] return '-'; -[^\]\n] RETURNCHAR; -"]" BEGIN(SECT2); return ']'; -.|{NL} { +{ + -/[^\]\n] return '-'; + [^\]\n] RETURNCHAR; + "]" BEGIN(SECT2); return ']'; + .|{NL} { synerr( "bad character class" ); BEGIN(SECT2); return ']'; } +} -[0-9]+ { +{ + [0-9]+ { yylval = myctoi( yytext ); return NUMBER; } -"," return ','; -"}" BEGIN(SECT2); return '}'; + "," return ','; + "}" BEGIN(SECT2); return '}'; -. { + . { synerr( "bad character inside {}'s" ); BEGIN(SECT2); return '}'; } -{NL} { + {NL} { synerr( "missing }" ); BEGIN(SECT2); ++linenum; return '}'; } +} -"}" synerr( "bad name in {}'s" ); BEGIN(SECT2); -{NL} synerr( "missing }" ); ++linenum; BEGIN(SECT2); +{ + "}" synerr( "bad name in {}'s" ); BEGIN(SECT2); + {NL} synerr( "missing }" ); ++linenum; BEGIN(SECT2); +} "/*" ACTION_ECHO; yy_push_state( COMMENT ); -{OPTWS}"%}".* bracelevel = 0; -"reject" { + +{ + {OPTWS}"%}".* bracelevel = 0; + + { + "reject" { ACTION_ECHO; CHECK_REJECT(yytext); } -"yymore" { + "yymore" { ACTION_ECHO; CHECK_YYMORE(yytext); } -{NAME}|{NOT_NAME}|. ACTION_ECHO; -{NL} { + } + + {NAME}|{NOT_NAME}|. ACTION_ECHO; + {NL} { ++linenum; ACTION_ECHO; if ( bracelevel == 0 || @@ -471,16 +500,18 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) BEGIN(SECT2); } } +} /* Reject and YYmore() are checked for above, in PERCENT_BRACE_ACTION */ -"{" ACTION_ECHO; ++bracelevel; -"}" ACTION_ECHO; --bracelevel; -[^a-z_{}"'/\n]+ ACTION_ECHO; -{NAME} ACTION_ECHO; -"'"([^'\\\n]|\\.)*"'" ACTION_ECHO; /* character constant */ -\" ACTION_ECHO; BEGIN(ACTION_STRING); -{NL} { +{ + "{" ACTION_ECHO; ++bracelevel; + "}" ACTION_ECHO; --bracelevel; + [^a-z_{}"'/\n]+ ACTION_ECHO; + {NAME} ACTION_ECHO; + "'"([^'\\\n]|\\.)*"'" ACTION_ECHO; /* character constant */ + \" ACTION_ECHO; BEGIN(ACTION_STRING); + {NL} { ++linenum; ACTION_ECHO; if ( bracelevel == 0 ) @@ -492,13 +523,16 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) BEGIN(SECT2); } } -. ACTION_ECHO; + . ACTION_ECHO; +} -[^"\\\n]+ ACTION_ECHO; -\\. ACTION_ECHO; -{NL} ++linenum; ACTION_ECHO; -\" ACTION_ECHO; BEGIN(ACTION); -. ACTION_ECHO; +{ + [^"\\\n]+ ACTION_ECHO; + \\. ACTION_ECHO; + {NL} ++linenum; ACTION_ECHO; + \" ACTION_ECHO; BEGIN(ACTION); + . ACTION_ECHO; +} <> { synerr( "EOF encountered inside an action" ); @@ -518,8 +552,10 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) } -.*(\n?) ECHO; -<> sectnum = 0; yyterminate(); +{ + .*(\n?) ECHO; + <> sectnum = 0; yyterminate(); +} <*>.|\n format_synerr( "bad character: %s", yytext );