Changeset 9ed4f94 for src/Parser


Ignore:
Timestamp:
Aug 30, 2017, 8:08:01 AM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
e5fccf4
Parents:
fc1ef62
Message:

update error message printing and add column to parsing errors

Location:
src/Parser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/lex.ll

    rfc1ef62 r9ed4f94  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Tue Aug 22 22:43:39 2017
    13  * Update Count     : 558
     12 * Last Modified On : Wed Aug 30 07:53:24 2017
     13 * Update Count     : 583
    1414 */
    1515
     
    1919
    2020%{
    21 // This lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor directive have been
     21// The lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor directive have been
    2222// performed and removed from the source. The only exceptions are preprocessor directives passed to the compiler (e.g.,
    2323// line-number directives) and C/C++ style comments, which are ignored.
     
    2525//**************************** Includes and Defines ****************************
    2626
     27unsigned int column = 0;                                                                // position of the end of the last token parsed
     28#define YY_USER_ACTION column += yyleng;                                // trigger before each matching rule's action
     29
    2730#include <string>
    2831#include <cstdio>                                                                               // FILENAME_MAX
     32using namespace std;
    2933
    3034#include "ParseNode.h"
     
    3236
    3337char *yyfilename;
    34 std::string *strtext;                                                                   // accumulate parts of character and string constant value
     38string *strtext;                                                                                // accumulate parts of character and string constant value
    3539
    3640#define RETURN_LOCN(x)          yylval.tok.loc.file = yyfilename; yylval.tok.loc.line = yylineno; return( x )
    37 #define RETURN_VAL(x)           yylval.tok.str = new std::string( yytext ); RETURN_LOCN( x )
     41#define RETURN_VAL(x)           yylval.tok.str = new string( yytext ); RETURN_LOCN( x )
    3842#define RETURN_CHAR(x)          yylval.tok.str = nullptr; RETURN_LOCN( x )
    3943#define RETURN_STR(x)           yylval.tok.str = strtext; RETURN_LOCN( x )
    4044
    4145#define WHITE_RETURN(x)         // do nothing
    42 #define NEWLINE_RETURN()        WHITE_RETURN( '\n' )
     46#define NEWLINE_RETURN()        column = 0; WHITE_RETURN( '\n' )
    4347#define ASCIIOP_RETURN()        RETURN_CHAR( (int)yytext[0] ) // single character operator
    4448#define NAMEDOP_RETURN(x)       RETURN_CHAR( x )                        // multichar operator, with a name
     
    154158                memcpy( &filename, begin_string + 1, length );  // copy file name from yytext
    155159                filename[ length ] = '\0';                                              // terminate string with sentinel
    156                 //std::cout << "file " << filename << " line " << lineno << std::endl;
     160                //cout << "file " << filename << " line " << lineno << endl;
    157161                yylineno = lineno;
    158162                yyfilename = filename;
     
    302306
    303307                                /* character constant, allows empty value */
    304 ({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new std::string( yytext, yyleng ); }
     308({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new string( yytext, yyleng ); }
    305309<QUOTE>[^'\\\n]* { strtext->append( yytext, yyleng ); }
    306310<QUOTE>['\n]    { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); }
     
    308312
    309313                                /* string constant */
    310 ({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new std::string( yytext, yyleng ); }
     314({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new string( yytext, yyleng ); }
    311315<STRING>[^"\\\n]* { strtext->append( yytext, yyleng ); }
    312316<STRING>["\n]   { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); }
     
    422426}
    423427
    424                                 /* unknown characters */
    425 .                               { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }
     428                                /* unknown character */
     429.                               { yyerror( "unknown character" ); }
    426430
    427431%%
     432// ----end of lexer----
     433
     434void yyerror( const char * errmsg ) {
     435        cout << (yyfilename ? yyfilename : "*unknown file*") << ':' << yylineno << ':' << column - yyleng + 1
     436                 << ':' << SemanticError::error_str() << errmsg << " at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << '"' << endl;
     437}
    428438
    429439// Local Variables: //
  • src/Parser/parser.yy

    rfc1ef62 r9ed4f94  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 28 13:24:10 2017
    13 // Update Count     : 2720
     12// Last Modified On : Wed Aug 30 07:04:19 2017
     13// Update Count     : 2740
    1414//
    1515
     
    4848#include <cstdio>
    4949#include <stack>
     50using namespace std;
     51
    5052#include "ParseNode.h"
    5153#include "TypedefTable.h"
    5254#include "TypeData.h"
    5355#include "LinkageSpec.h"
    54 using namespace std;
     56#include "Common/SemanticError.h"                                               // error_str
    5557
    5658extern DeclarationNode * parseTree;
     
    31333135// ----end of grammar----
    31343136
    3135 extern char *yytext;
    3136 
    3137 void yyerror( const char * ) {
    3138         if ( yyfilename ) {
    3139                 cout << yyfilename << ":";
    3140         } // if
    3141         cout << yylineno << ":1 syntax error at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << endl;
    3142 }
    3143 
    31443137// Local Variables: //
    31453138// mode: c++ //
Note: See TracChangeset for help on using the changeset viewer.