Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,27 @@ Program* Parser::Parse()
Expression* Parser::ParseExpression()
{
getsym();
return expression();
Expression* e = expression();

// Add a warning (error?) for all trailing tokens, because we only wanted to parse
// a single expression
if(sym != finished) {
stringstream ss;
string empty_string{};

while(sym != finished) {
ss << "ignoring unexpected symbol '" << last.ToString() << "' after expression";
Warning(ss.str(), line);

// Reset error text
ss.str(empty_string);

// Advance to the next token
getsym();
}
}

return e;
}


Expand Down Expand Up @@ -514,4 +534,4 @@ Expression* Parser::primaryexpr() {
ss << "symbol '" << last.ToString() << "'";
Error(ss.str(), last.line);
return new ErrorExpr(last.line, "unexpected symbol '" + last.ToString() + "'");
}
}