%{ // // The Termprocessor Kimwitu++ // // Copyright (C) 1991 University of Twente, Dept TIOS. // Copyright (C) 1997-2003 Humboldt-University at Berlin, Institute of Informatics // All rights reserved. // // Kimwitu++ is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // Kimwitu++ is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Kimwitu++; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // %} %option noyywrap %option never-interactive %{ /* * kimwl.l */ static char kimwl_lAccesSid[] = "@(#)$Id: kimwl.l,v 1.39 2003/08/19 14:45:47 piefel Exp $"; /* For windows (NT at least) we need to redefine fileno */ #if defined(_WIN32) && ! defined (__GNUC__) # define fileno _fileno #endif /***************************************************************************/ /* * Name conventions: tokens and states are in CAPITALS * operators are capitalized * */ %} %start NORMAL INCL INCLSTART CEXPR CEXPRDQ CEXPRSQ C OPNAME %x OPTION %{ #include #include #include "k.h" #include "yystype.h" #include "kimwy.h" namespace { std::string cinclude(""); int cinit_paren_nesting =0; int cinit_array_nesting =0; void reset_nestcount(); int eat_comment(casestring); void eat_line_comment(); void count(bool = true); } // namespace %} special [\_] ident (([[:alpha:]]|{special})([[:alnum:]]|{special})*) nonident [^a-zA-Z0-9\_] int ([[:digit:]]+) exp ([Ee][-+]?[[:digit:]]+) float ([-+]?[[:digit:]]+\.?[[:digit:]]*) wsnl [\ \n\t\v\f] ws [\ \t] op_name (\+|-|\*|\/|%|^|&|\||~|!|=|<|>|\+=|-=|\*=|\/=|%=|^=|&=|\|=|<<|>>|<<=|>>=|==|!=|<=|>=|&&|\|\||\+\+|--|,|->\*|->) operator_name ({op_name}|new(\[\])?|delete(\[\])?|\[\]|\(\)) %% {wsnl} { count(false); } ^%uview { count(); return T_PERCENTUVIEW; } %uviewvar { count(); return T_PERCENTUVIEWVAR; } ^%rview { count(); return T_PERCENTRVIEW; } %rviewvar { count(); return T_PERCENTRVIEWVAR; } ^%storageclass { count(); return T_PERCENTSTORAGECLASS; } ^%language { count(); return T_PERCENTLANGUAGE; } ^%option { count(); BEGIN OPTION; } ^\%\{{ws}* { count(); BEGIN INCLSTART; return T_INCLUDESTART; } {ident} { count(); yylval.yt_casestring = mkcasestring(yytext); return T_ID; } {ws} { count(false); } \n { count(); cinclude = ""; cinclude.reserve(1024); BEGIN INCL; return T_ENDOFINCLUDESTART; } .|\n { count(); cinclude += yytext[0]; } ^\%\{{ws}* { count(); v_report(Warning(FileLine(pg_filename, pg_lineno), Problem1S("Opening '%{' (nested C++ includes; preceding closing '%}' not found)"))); cinclude += yytext; } ^\%\}{ws}*\n { count(); BEGIN NORMAL; yylval.yt_casestring = mkcasestring(cinclude.c_str()); return T_INCLUDEEND; } \/\* { count(); yylval.yt_integer = mkinteger(eat_comment(pg_filename)); return T_CNEWLINES; } \/\* { count(); eat_comment(pg_filename); } \/\/ { count(); eat_line_comment(); yylval.yt_integer = mkinteger(1); return T_CNEWLINES; } \/\/ { count(); eat_line_comment(); } \-\> { count(); return T_ARROW; } provided { count(); return T_PROVIDED; } default { count(); return T_DEFAULT; } \-?{int} { count(); yylval.yt_integer = mkinteger(atoi(yytext)); return T_INT; } list { count(); return T_LIST; } static { count(); return T_STATIC; } auto { count(); return T_AUTO; } register { count(); return T_REGISTER; } extern { count(); return T_EXTERN; } typedef { count(); return T_TYPEDEF; } const { count(); return T_CONST; } volatile { count(); return T_VOLATILE; } unsigned { count(); return T_UNSIGNED; } virtual { count(); return T_VIRTUAL; } operator { count(); BEGIN OPNAME; return T_OPERATOR; } ^%ctor { count(); return T_CONSTRUCTOR; } ^%dtor { count(); return T_DESTRUCTOR; } ^%member { count(); return T_MEMBER; } ^%attr { count(); return T_ATTR; } ^%base { count(); return T_BASECLASS; } \.\.\. { count(); return T_DOTDOTDOT; } :: { count(); return T_COLONCOLON; } {wsnl}* { count(false); } {operator_name} { count(); BEGIN NORMAL; yylval.yt_casestring = mkcasestring(yytext); return T_OPNAME ; } {ident} { count(); BEGIN NORMAL; yylval.yt_casestring = mkcasestring(yytext); return T_ID ; } {ident} { count(); yylval.yt_casestring = mkcasestring(yytext); return T_ID ; } [^\n\\"';,\(\)\[\]$]+ { count(); yylval.yt_casestring = mkcasestring(yytext); return T_CEXPRESSION; } \${int} { count(); yylval.yt_integer = mkinteger(atoi(yytext+1)); return T_DOLLARVAR; } \$\{ { count(); return T_UNPBLOCKSTART; } \$\} { count(); return T_UNPBLOCKEND; } \$ { count(); yylval.yt_casestring = mkcasestring(yytext); return T_CEXPRESSION; } \n { count(); return yytext[0]; } \\ { count(); yylval.yt_casestring = mkcasestring("\\"); return T_CEXPRESSION; } \\\\ { count(); yylval.yt_casestring = mkcasestring("\\\\"); return T_CEXPRESSION; } \" { count(); BEGIN CEXPRDQ; return yytext[0]; } ' { count(); BEGIN CEXPRSQ; return yytext[0]; } ; { count(); BEGIN NORMAL; reset_nestcount(); return yytext[0]; } \, { count(); return yytext[0]; } \( { count(); cinit_paren_nesting++; yylval.yt_casestring = mkcasestring("("); return yytext[0]; } \) { count(); if (cinit_paren_nesting == 0) { BEGIN NORMAL; reset_nestcount(); return yytext[0]; } else { cinit_paren_nesting--; yylval.yt_casestring = mkcasestring(")"); return yytext[0]; } } \[ { count(); cinit_array_nesting++; yylval.yt_casestring = mkcasestring("["); return yytext[0]; } \] { count(); if (cinit_array_nesting == 0) { BEGIN NORMAL; reset_nestcount(); return yytext[0]; } else { cinit_array_nesting--; yylval.yt_casestring = mkcasestring("]"); return yytext[0]; } } [^\n\\"]+ { count(); yylval.yt_casestring = mkcasestring(yytext); return T_CEXPRESSION; } \" { count(); BEGIN CEXPR; return yytext[0]; } \\\" { count(); yylval.yt_casestring = mkcasestring("\\\""); return T_CEXPRESSION; } ' { count(); BEGIN CEXPR; return yytext[0]; } \\' { count(); yylval.yt_casestring = mkcasestring("\\'"); return T_CEXPRESSION; } [^\n\\']+ { count(); yylval.yt_casestring = mkcasestring(yytext); return T_CEXPRESSION; } \$\$ { count(); yylval.yt_casestring = mkcasestring("$"); return T_CLINE; } \\\\ { count(); yylval.yt_casestring = mkcasestring("\\\\"); return T_CLINE; } \\ { count(); yylval.yt_casestring = mkcasestring("\\"); return T_CLINE ; } \$\{ { count(); yylval.yt_casestring = mkcasestring("{"); /*WARNING-NO LONGER SUPPORTED*/ return T_CLINE ; } \$\} { count(); yylval.yt_casestring = mkcasestring("}"); /*WARNING-NO LONGER SUPPORTED*/ return T_CLINE ; } \$[0-9]* { count(); if (strcmp(yytext, "$") == 0) return yytext[0]; yylval.yt_integer = mkinteger(atoi(yytext+1)); return T_DOLLARVAR; } {wsnl}*afterforeach/{nonident} { count(); return T_FOREACH_AFTER; } {ident} { count(); if (strcmp(yytext, "foreach") ==0) { return T_FOREACH; } else if (strcmp(yytext, "afterforeach") ==0) { return T_FOREACH_AFTER; } else if (strcmp(yytext, "with") ==0) { return T_WITH; } else { yylval.yt_casestring = mkcasestring(yytext); return T_CLINE ; } } [^\n{}w/"'a-zA-Z_\$\\]+ { count(); yylval.yt_casestring = mkcasestring(yytext); return T_CLINE; } \/ { count(); yylval.yt_casestring = mkcasestring(yytext); return T_CLINE; } \/\*[ \t]*EMPTY[ \t]*\*\/ { count(); yylval.yt_casestring = mkcasestring(yytext); return T_CLINE; } \/\*[ \t]*NOTREACHED[ \t]*\*\/ { count(); yylval.yt_casestring = mkcasestring(yytext); return T_CLINE; } \/\*[ \t]*SUPPRESS[ \t]*[0-9]+[ \t]*\*\/ { count(); yylval.yt_casestring = mkcasestring(yytext); return T_CLINE; } . { count(); return yytext[0]; }