Merge pull request #2291 from Capostrophic/parser

Improve compiler messages
pull/541/head
Andrei Kortunov 6 years ago committed by GitHub
commit 6de75f60bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -125,7 +125,7 @@ namespace Compiler
if (loop.size()!=loop2.size()) if (loop.size()!=loop2.size())
throw std::logic_error ( throw std::logic_error (
"internal compiler error: failed to generate a while loop"); "Internal compiler error: failed to generate a while loop");
std::copy (loop2.begin(), loop2.end(), std::back_inserter (mCode)); std::copy (loop2.begin(), loop2.end(), std::back_inserter (mCode));
@ -181,7 +181,7 @@ namespace Compiler
} }
else if (mState==IfElseJunkState) else if (mState==IfElseJunkState)
{ {
getErrorHandler().warning ("Ignoring extra text after else", loc); getErrorHandler().warning ("Extra text after else", loc);
SkipParser skip (getErrorHandler(), getContext()); SkipParser skip (getErrorHandler(), getContext());
scanner.scan (skip); scanner.scan (skip);
mState = IfElseBodyState; mState = IfElseBodyState;
@ -227,7 +227,7 @@ namespace Compiler
} }
else if (mState==IfElseJunkState) else if (mState==IfElseJunkState)
{ {
getErrorHandler().warning ("Ignoring extra text after else", loc); getErrorHandler().warning ("Extra text after else", loc);
SkipParser skip (getErrorHandler(), getContext()); SkipParser skip (getErrorHandler(), getContext());
scanner.scan (skip); scanner.scan (skip);
mState = IfElseBodyState; mState = IfElseBodyState;
@ -267,7 +267,7 @@ namespace Compiler
} }
else if (mState==IfElseJunkState) else if (mState==IfElseJunkState)
{ {
getErrorHandler().warning ("Ignoring extra text after else", loc); getErrorHandler().warning ("Extra text after else", loc);
SkipParser skip (getErrorHandler(), getContext()); SkipParser skip (getErrorHandler(), getContext());
scanner.scan (skip); scanner.scan (skip);
mState = IfElseBodyState; mState = IfElseBodyState;

@ -22,7 +22,7 @@ bool Compiler::DeclarationParser::parseName (const std::string& name, const Toke
char type = mLocals.getType (name2); char type = mLocals.getType (name2);
if (type!=' ') if (type!=' ')
getErrorHandler().warning ("ignoring local variable re-declaration", loc); getErrorHandler().warning ("Local variable re-declaration", loc);
else else
mLocals.declare (mType, name2); mLocals.declare (mType, name2);
@ -31,7 +31,7 @@ bool Compiler::DeclarationParser::parseName (const std::string& name, const Toke
} }
else if (mState==State_End) else if (mState==State_End)
{ {
getErrorHandler().warning ("Ignoring extra text after local variable declaration", loc); getErrorHandler().warning ("Extra text after local variable declaration", loc);
SkipParser skip (getErrorHandler(), getContext()); SkipParser skip (getErrorHandler(), getContext());
scanner.scan (skip); scanner.scan (skip);
return false; return false;
@ -65,7 +65,7 @@ bool Compiler::DeclarationParser::parseKeyword (int keyword, const TokenLoc& loc
} }
else if (mState==State_End) else if (mState==State_End)
{ {
getErrorHandler().warning ("Ignoring extra text after local variable declaration", loc); getErrorHandler().warning ("Extra text after local variable declaration", loc);
SkipParser skip (getErrorHandler(), getContext()); SkipParser skip (getErrorHandler(), getContext());
scanner.scan (skip); scanner.scan (skip);
return false; return false;
@ -80,7 +80,7 @@ bool Compiler::DeclarationParser::parseSpecial (int code, const TokenLoc& loc, S
{ {
if (code!=Scanner::S_newline) if (code!=Scanner::S_newline)
{ {
getErrorHandler().warning ("Ignoring extra text after local variable declaration", loc); getErrorHandler().warning ("Extra text after local variable declaration", loc);
SkipParser skip (getErrorHandler(), getContext()); SkipParser skip (getErrorHandler(), getContext());
scanner.scan (skip); scanner.scan (skip);
} }

@ -11,7 +11,7 @@ namespace Compiler
{ {
public: public:
virtual const char *what() const throw() { return "compile error";} virtual const char *what() const throw() { return "Compile error";}
///< Return error message ///< Return error message
}; };
@ -21,7 +21,7 @@ namespace Compiler
{ {
public: public:
virtual const char *what() const throw() { return "can't read file"; } virtual const char *what() const throw() { return "Can't read file"; }
///< Return error message ///< Return error message
}; };
@ -31,7 +31,7 @@ namespace Compiler
{ {
public: public:
virtual const char *what() const throw() { return "end of file"; } virtual const char *what() const throw() { return "End of file"; }
///< Return error message ///< Return error message
}; };
} }

@ -99,7 +99,7 @@ namespace Compiler
else if (t1=='f' || t2=='f') else if (t1=='f' || t2=='f')
mOperands.push_back ('f'); mOperands.push_back ('f');
else else
throw std::logic_error ("failed to determine result operand type"); throw std::logic_error ("Failed to determine result operand type");
} }
void ExprParser::pop() void ExprParser::pop()
@ -158,7 +158,7 @@ namespace Compiler
default: default:
throw std::logic_error ("unknown operator"); throw std::logic_error ("Unknown operator");
} }
} }
@ -287,7 +287,7 @@ namespace Compiler
else else
{ {
mExplicit.clear(); mExplicit.clear();
getErrorHandler().warning ("Ignoring stray explicit reference", loc); getErrorHandler().warning ("Stray explicit reference", loc);
} }
} }
@ -430,7 +430,7 @@ namespace Compiler
{ {
if (!hasExplicit) if (!hasExplicit)
{ {
getErrorHandler().warning ("ignoring stray explicit reference", loc); getErrorHandler().warning ("Stray explicit reference", loc);
mExplicit.clear(); mExplicit.clear();
} }
@ -735,13 +735,13 @@ namespace Compiler
{ {
if (mOperands.empty() && mOperators.empty()) if (mOperands.empty() && mOperators.empty())
{ {
getErrorHandler().error ("missing expression", mTokenLoc); getErrorHandler().error ("Missing expression", mTokenLoc);
return 'l'; return 'l';
} }
if (mNextOperand || mOperands.empty()) if (mNextOperand || mOperands.empty())
{ {
getErrorHandler().error ("syntax error in expression", mTokenLoc); getErrorHandler().error ("Syntax error in expression", mTokenLoc);
return 'l'; return 'l';
} }
@ -799,7 +799,7 @@ namespace Compiler
++optionalCount; ++optionalCount;
} }
else else
getErrorHandler().warning ("ignoring extra argument", getErrorHandler().warning ("Extra argument",
stringParser.getTokenLoc()); stringParser.getTokenLoc());
} }
else if (*iter=='X') else if (*iter=='X')
@ -813,7 +813,7 @@ namespace Compiler
if (parser.isEmpty()) if (parser.isEmpty())
break; break;
else else
getErrorHandler().warning("ignoring extra argument", parser.getTokenLoc()); getErrorHandler().warning("Extra argument", parser.getTokenLoc());
} }
else if (*iter=='z') else if (*iter=='z')
{ {
@ -825,7 +825,7 @@ namespace Compiler
if (discardParser.isEmpty()) if (discardParser.isEmpty())
break; break;
else else
getErrorHandler().warning("ignoring extra argument", discardParser.getTokenLoc()); getErrorHandler().warning("Extra argument", discardParser.getTokenLoc());
} }
else if (*iter=='j') else if (*iter=='j')
{ {

@ -98,7 +98,7 @@ namespace Compiler
if (mState == BeginState) if (mState == BeginState)
{ {
if (code != Scanner::S_newline) if (code != Scanner::S_newline)
reportWarning ("Ignoring stray special character before begin statement", loc); reportWarning ("Stray special character before begin statement", loc);
return true; return true;
} }

@ -29,7 +29,7 @@ bool Compiler::JunkParser::parseName (const std::string& name, const TokenLoc& l
bool Compiler::JunkParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner) bool Compiler::JunkParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
{ {
if (keyword==mIgnoreKeyword) if (keyword==mIgnoreKeyword)
reportWarning ("ignoring found junk", loc); reportWarning ("Ignoring found junk", loc);
else else
scanner.putbackKeyword (keyword, loc); scanner.putbackKeyword (keyword, loc);
@ -39,7 +39,7 @@ bool Compiler::JunkParser::parseKeyword (int keyword, const TokenLoc& loc, Scann
bool Compiler::JunkParser::parseSpecial (int code, const TokenLoc& loc, Scanner& scanner) bool Compiler::JunkParser::parseSpecial (int code, const TokenLoc& loc, Scanner& scanner)
{ {
if (code==Scanner::S_member) if (code==Scanner::S_member)
reportWarning ("ignoring found junk", loc); reportWarning ("Ignoring found junk", loc);
else else
scanner.putbackSpecial (code, loc); scanner.putbackSpecial (code, loc);

@ -48,7 +48,7 @@ namespace Compiler
default: default:
throw std::runtime_error ("unknown expression result type"); throw std::runtime_error ("Unknown expression result type");
} }
} }
@ -88,7 +88,7 @@ namespace Compiler
{ {
if (mState==PotentialEndState) if (mState==PotentialEndState)
{ {
getErrorHandler().warning ("ignoring stray string argument", loc); getErrorHandler().warning ("Stray string argument", loc);
mState = EndState; mState = EndState;
return true; return true;
} }
@ -132,7 +132,7 @@ namespace Compiler
return true; return true;
} }
getErrorHandler().error ("unknown variable", loc); getErrorHandler().error ("Unknown variable", loc);
SkipParser skip (getErrorHandler(), getContext()); SkipParser skip (getErrorHandler(), getContext());
scanner.scan (skip); scanner.scan (skip);
return false; return false;
@ -233,7 +233,7 @@ namespace Compiler
if (mState==SetPotentialMemberVarState && keyword==Scanner::K_to) if (mState==SetPotentialMemberVarState && keyword==Scanner::K_to)
{ {
getErrorHandler().warning ("unknown variable, ignoring set instruction", loc); getErrorHandler().warning ("Unknown variable", loc);
SkipParser skip (getErrorHandler(), getContext()); SkipParser skip (getErrorHandler(), getContext());
scanner.scan (skip); scanner.scan (skip);
return false; return false;
@ -286,7 +286,7 @@ namespace Compiler
{ {
if (!hasExplicit && mState==ExplicitState) if (!hasExplicit && mState==ExplicitState)
{ {
getErrorHandler().warning ("ignoring stray explicit reference", loc); getErrorHandler().warning ("Stray explicit reference", loc);
mExplicit.clear(); mExplicit.clear();
} }
@ -344,7 +344,7 @@ namespace Compiler
{ {
if (!hasExplicit && !mExplicit.empty()) if (!hasExplicit && !mExplicit.empty())
{ {
getErrorHandler().warning ("ignoring stray explicit reference", loc); getErrorHandler().warning ("Stray explicit reference", loc);
mExplicit.clear(); mExplicit.clear();
} }
@ -360,7 +360,7 @@ namespace Compiler
if (mState==ExplicitState) if (mState==ExplicitState)
{ {
// drop stray explicit reference // drop stray explicit reference
getErrorHandler().warning ("ignoring stray explicit reference", loc); getErrorHandler().warning ("Stray explicit reference", loc);
mState = BeginState; mState = BeginState;
mExplicit.clear(); mExplicit.clear();
} }
@ -375,8 +375,7 @@ namespace Compiler
{ {
if (!getContext().canDeclareLocals()) if (!getContext().canDeclareLocals())
{ {
getErrorHandler().error ( getErrorHandler().error("Local variables cannot be declared in this context", loc);
"local variables can't be declared in this context", loc);
SkipParser skip (getErrorHandler(), getContext()); SkipParser skip (getErrorHandler(), getContext());
scanner.scan (skip); scanner.scan (skip);
return true; return true;
@ -412,19 +411,19 @@ namespace Compiler
case Scanner::K_else: case Scanner::K_else:
getErrorHandler().warning ("ignoring stray else", loc); getErrorHandler().warning ("Stray else", loc);
mState = EndState; mState = EndState;
return true; return true;
case Scanner::K_endif: case Scanner::K_endif:
getErrorHandler().warning ("ignoring stray endif", loc); getErrorHandler().warning ("Stray endif", loc);
mState = EndState; mState = EndState;
return true; return true;
case Scanner::K_begin: case Scanner::K_begin:
getErrorHandler().warning ("ignoring stray begin", loc); getErrorHandler().warning ("Stray begin", loc);
mState = EndState; mState = EndState;
return true; return true;
} }
@ -491,7 +490,7 @@ namespace Compiler
{ {
if (mState==EndState && code==Scanner::S_open) if (mState==EndState && code==Scanner::S_open)
{ {
getErrorHandler().warning ("ignoring stray '[' or '(' at the end of the line", getErrorHandler().warning ("Stray '[' or '(' at the end of the line",
loc); loc);
return true; return true;
} }
@ -508,7 +507,7 @@ namespace Compiler
if (code==Scanner::S_ref && mState==SetPotentialMemberVarState) if (code==Scanner::S_ref && mState==SetPotentialMemberVarState)
{ {
getErrorHandler().warning ("Ignoring stray explicit reference", loc); getErrorHandler().warning ("Stray explicit reference", loc);
mState = SetState; mState = SetState;
return true; return true;
} }

@ -18,7 +18,7 @@ namespace Compiler
case 'f': return mFloats; case 'f': return mFloats;
} }
throw std::logic_error ("unknown variable type"); throw std::logic_error ("Unknown variable type");
} }
int Locals::searchIndex (char type, const std::string& name) const int Locals::searchIndex (char type, const std::string& name) const
@ -48,7 +48,7 @@ namespace Compiler
case 'f': return mFloats; case 'f': return mFloats;
} }
throw std::logic_error ("unknown variable type"); throw std::logic_error ("Unknown variable type");
} }
char Locals::getType (const std::string& name) const char Locals::getType (const std::string& name) const

@ -158,7 +158,7 @@ namespace Compiler
TokenLoc loc (mLoc); TokenLoc loc (mLoc);
mLoc.mLiteral.clear(); mLoc.mLiteral.clear();
mErrorHandler.error ("syntax error", loc); mErrorHandler.error ("Syntax error", loc);
throw SourceException(); throw SourceException();
} }
@ -521,7 +521,7 @@ namespace Compiler
else if (c == '<' || c == '>') // Treat <> and << as < else if (c == '<' || c == '>') // Treat <> and << as <
{ {
special = S_cmpLT; special = S_cmpLT;
mErrorHandler.warning (std::string("invalid operator <") + c + ", treating it as <", mLoc); mErrorHandler.warning ("Invalid operator, treating it as <", mLoc);
} }
else else
{ {
@ -549,7 +549,7 @@ namespace Compiler
else if (c == '<' || c == '>') // Treat >< and >> as > else if (c == '<' || c == '>') // Treat >< and >> as >
{ {
special = S_cmpGT; special = S_cmpGT;
mErrorHandler.warning (std::string("invalid operator >") + c + ", treating it as >", mLoc); mErrorHandler.warning ("Invalid operator, treating it as >", mLoc);
} }
else else
{ {

Loading…
Cancel
Save