Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/lex.ll

    rc1c1112 r08061589  
    99 * Author           : Peter A. Buhr
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    11  * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Wed Aug 24 13:27:04 2016
    13  * Update Count     : 487
     11 * Last Modified By :
     12 * Last Modified On : Sun Jul 31 07:19:36 2016
     13 * Update Count     : 459
    1414 */
    1515
     
    2525
    2626#include <string>
    27 #include <cstdio>                                                                               // FILENAME_MAX
    2827
    2928#include "lex.h"
     
    3736#define RETURN_LOCN(x)          yylval.tok.loc.file = yyfilename; yylval.tok.loc.line = yylineno; return( x )
    3837#define RETURN_VAL(x)           yylval.tok.str = new std::string( yytext ); RETURN_LOCN( x )
    39 #define RETURN_CHAR(x)          yylval.tok.str = nullptr; RETURN_LOCN( x )
     38#define RETURN_CHAR(x)          yylval.tok.str = NULL; RETURN_LOCN( x )
    4039#define RETURN_STR(x)           yylval.tok.str = strtext; RETURN_LOCN( x )
    4140
    42 #define WHITE_RETURN(x)         // do nothing
     41#define WHITE_RETURN(x)                                                                 // do nothing
    4342#define NEWLINE_RETURN()        WHITE_RETURN( '\n' )
    4443#define ASCIIOP_RETURN()        RETURN_CHAR( (int)yytext[0] ) // single character operator
    45 #define NAMEDOP_RETURN(x)       RETURN_CHAR( x )                        // multichar operator, with a name
     44#define NAMEDOP_RETURN(x)       RETURN_VAL( x )                         // multichar operator, with a name
    4645#define NUMERIC_RETURN(x)       rm_underscore(); RETURN_VAL( x ) // numeric constant
    4746#define KEYWORD_RETURN(x)       RETURN_CHAR( x )                        // keyword
     
    141140^{h_white}*"#"{h_white}*[0-9]+{h_white}*["][^"\n]+["].*"\n" {
    142141        /* " stop highlighting */
    143         static char filename[FILENAME_MAX];                                     // temporarily store current source-file name
    144142        char *end_num;
    145143        char *begin_string, *end_string;
     144        char *filename;
    146145        long lineno, length;
    147146        lineno = strtol( yytext + 1, &end_num, 0 );
    148147        begin_string = strchr( end_num, '"' );
    149         if ( begin_string ) {                                                           // file name ?
    150                 end_string = strchr( begin_string + 1, '"' );   // look for ending delimiter
    151                 assert( end_string );                                                   // closing quote ?
    152                 length = end_string - begin_string - 1;                 // file-name length without quotes or sentinel
    153                 assert( length < FILENAME_MAX );                                // room for sentinel ?
    154                 memcpy( &filename, begin_string + 1, length );  // copy file name from yytext
    155                 filename[ length ] = '\0';                                              // terminate string with sentinel
    156                 //std::cout << "file " << filename << " line " << lineno << std::endl;
    157                 yylineno = lineno;
    158                 yyfilename = filename;
     148        if ( begin_string ) {
     149                end_string = strchr( begin_string + 1, '"' );
     150                if ( end_string ) {
     151                        length = end_string - begin_string - 1;
     152                        filename = new char[ length + 1 ];
     153                        memcpy( filename, begin_string + 1, length );
     154                        filename[ length ] = '\0';
     155                        //std::cout << "file " << filename << " line " << lineno << std::endl;
     156                        yylineno = lineno;
     157                        yyfilename = filename;
     158                } // if
    159159        } // if
    160160}
     
    288288
    289289                                /* character constant, allows empty value */
    290 ({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new std::string( yytext, yyleng ); }
    291 <QUOTE>[^'\\\n]* { strtext->append( yytext, yyleng ); }
    292 <QUOTE>['\n]    { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); }
     290({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new std::string; *strtext += std::string( yytext ); }
     291<QUOTE>[^'\\\n]* { *strtext += std::string( yytext ); }
     292<QUOTE>['\n]    { BEGIN 0; *strtext += std::string( yytext); RETURN_STR(CHARACTERconstant); }
    293293                                /* ' stop highlighting */
    294294
    295295                                /* string constant */
    296 ({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new std::string( yytext, yyleng ); }
    297 <STRING>[^"\\\n]* { strtext->append( yytext, yyleng ); }
    298 <STRING>["\n]   { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); }
     296({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new std::string; *strtext += std::string( yytext ); }
     297<STRING>[^"\\\n]* { *strtext += std::string( yytext ); }
     298<STRING>["\n]   { BEGIN 0; *strtext += std::string( yytext ); RETURN_STR(STRINGliteral); }
    299299                                /* " stop highlighting */
    300300
    301301                                /* common character/string constant */
    302 <QUOTE,STRING>{escape_seq} { rm_underscore(); strtext->append( yytext, yyleng ); }
     302<QUOTE,STRING>{escape_seq} { rm_underscore(); *strtext += std::string( yytext ); }
    303303<QUOTE,STRING>"\\"{h_white}*"\n" {}                                             // continuation (ALSO HANDLED BY CPP)
    304 <QUOTE,STRING>"\\" { strtext->append( yytext, yyleng ); } // unknown escape character
     304<QUOTE,STRING>"\\" { *strtext += std::string( yytext ); } // unknown escape character
    305305
    306306                                /* punctuation */
Note: See TracChangeset for help on using the changeset viewer.