Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/lex.cc

    r08061589 rc1c1112  
    14681468 * Author           : Peter A. Buhr
    14691469 * Created On       : Sat Sep 22 08:58:10 2001
    1470  * Last Modified By :
    1471  * Last Modified On : Sun Jul 31 07:19:36 2016
    1472  * Update Count     : 459
     1470 * Last Modified By : Peter A. Buhr
     1471 * Last Modified On : Wed Aug 24 13:27:04 2016
     1472 * Update Count     : 487
    14731473 */
    14741474#line 20 "lex.ll"
     
    14801480
    14811481#include <string>
     1482#include <cstdio>                                                                               // FILENAME_MAX
    14821483
    14831484#include "lex.h"
     
    14911492#define RETURN_LOCN(x)          yylval.tok.loc.file = yyfilename; yylval.tok.loc.line = yylineno; return( x )
    14921493#define RETURN_VAL(x)           yylval.tok.str = new std::string( yytext ); RETURN_LOCN( x )
    1493 #define RETURN_CHAR(x)          yylval.tok.str = NULL; RETURN_LOCN( x )
     1494#define RETURN_CHAR(x)          yylval.tok.str = nullptr; RETURN_LOCN( x )
    14941495#define RETURN_STR(x)           yylval.tok.str = strtext; RETURN_LOCN( x )
    14951496
    1496 #define WHITE_RETURN(x)                                                                 // do nothing
     1497#define WHITE_RETURN(x)         // do nothing
    14971498#define NEWLINE_RETURN()        WHITE_RETURN( '\n' )
    14981499#define ASCIIOP_RETURN()        RETURN_CHAR( (int)yytext[0] ) // single character operator
    1499 #define NAMEDOP_RETURN(x)       RETURN_VAL( x )                         // multichar operator, with a name
     1500#define NAMEDOP_RETURN(x)       RETURN_CHAR( x )                        // multichar operator, with a name
    15001501#define NUMERIC_RETURN(x)       rm_underscore(); RETURN_VAL( x ) // numeric constant
    15011502#define KEYWORD_RETURN(x)       RETURN_CHAR( x )                        // keyword
     
    15311532
    15321533
    1533 #line 1534 "Parser/lex.cc"
     1534#line 1535 "Parser/lex.cc"
    15341535
    15351536#define INITIAL 0
     
    17231724        register int yy_act;
    17241725   
    1725 #line 138 "lex.ll"
     1726#line 139 "lex.ll"
    17261727
    17271728                                   /* line directives */
    1728 #line 1729 "Parser/lex.cc"
     1729#line 1730 "Parser/lex.cc"
    17291730
    17301731        if ( !(yy_init) )
     
    18231824/* rule 1 can match eol */
    18241825YY_RULE_SETUP
    1825 #line 140 "lex.ll"
     1826#line 141 "lex.ll"
    18261827{
    18271828        /* " stop highlighting */
     1829        static char filename[FILENAME_MAX];                                     // temporarily store current source-file name
    18281830        char *end_num;
    18291831        char *begin_string, *end_string;
    1830         char *filename;
    18311832        long lineno, length;
    18321833        lineno = strtol( yytext + 1, &end_num, 0 );
    18331834        begin_string = strchr( end_num, '"' );
    1834         if ( begin_string ) {
    1835                 end_string = strchr( begin_string + 1, '"' );
    1836                 if ( end_string ) {
    1837                         length = end_string - begin_string - 1;
    1838                         filename = new char[ length + 1 ];
    1839                         memcpy( filename, begin_string + 1, length );
    1840                         filename[ length ] = '\0';
    1841                         //std::cout << "file " << filename << " line " << lineno << std::endl;
    1842                         yylineno = lineno;
    1843                         yyfilename = filename;
    1844                 } // if
     1835        if ( begin_string ) {                                                           // file name ?
     1836                end_string = strchr( begin_string + 1, '"' );   // look for ending delimiter
     1837                assert( end_string );                                                   // closing quote ?
     1838                length = end_string - begin_string - 1;                 // file-name length without quotes or sentinel
     1839                assert( length < FILENAME_MAX );                                // room for sentinel ?
     1840                memcpy( &filename, begin_string + 1, length );  // copy file name from yytext
     1841                filename[ length ] = '\0';                                              // terminate string with sentinel
     1842                //std::cout << "file " << filename << " line " << lineno << std::endl;
     1843                yylineno = lineno;
     1844                yyfilename = filename;
    18451845        } // if
    18461846}
     
    24262426YY_RULE_SETUP
    24272427#line 290 "lex.ll"
    2428 { BEGIN QUOTE; rm_underscore(); strtext = new std::string; *strtext += std::string( yytext ); }
     2428{ BEGIN QUOTE; rm_underscore(); strtext = new std::string( yytext, yyleng ); }
    24292429        YY_BREAK
    24302430case 116:
    24312431YY_RULE_SETUP
    24322432#line 291 "lex.ll"
    2433 { *strtext += std::string( yytext ); }
     2433{ strtext->append( yytext, yyleng ); }
    24342434        YY_BREAK
    24352435case 117:
     
    24372437YY_RULE_SETUP
    24382438#line 292 "lex.ll"
    2439 { BEGIN 0; *strtext += std::string( yytext); RETURN_STR(CHARACTERconstant); }
     2439{ BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); }
    24402440        YY_BREAK
    24412441/* ' stop highlighting */
     
    24442444YY_RULE_SETUP
    24452445#line 296 "lex.ll"
    2446 { BEGIN STRING; rm_underscore(); strtext = new std::string; *strtext += std::string( yytext ); }
     2446{ BEGIN STRING; rm_underscore(); strtext = new std::string( yytext, yyleng ); }
    24472447        YY_BREAK
    24482448case 119:
    24492449YY_RULE_SETUP
    24502450#line 297 "lex.ll"
    2451 { *strtext += std::string( yytext ); }
     2451{ strtext->append( yytext, yyleng ); }
    24522452        YY_BREAK
    24532453case 120:
     
    24552455YY_RULE_SETUP
    24562456#line 298 "lex.ll"
    2457 { BEGIN 0; *strtext += std::string( yytext ); RETURN_STR(STRINGliteral); }
     2457{ BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); }
    24582458        YY_BREAK
    24592459/* " stop highlighting */
     
    24622462YY_RULE_SETUP
    24632463#line 302 "lex.ll"
    2464 { rm_underscore(); *strtext += std::string( yytext ); }
     2464{ rm_underscore(); strtext->append( yytext, yyleng ); }
    24652465        YY_BREAK
    24662466case 122:
     
    24732473YY_RULE_SETUP
    24742474#line 304 "lex.ll"
    2475 { *strtext += std::string( yytext ); } // unknown escape character
     2475{ strtext->append( yytext, yyleng ); } // unknown escape character
    24762476        YY_BREAK
    24772477/* punctuation */
Note: See TracChangeset for help on using the changeset viewer.