-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a9605e
commit 88095bc
Showing
11 changed files
with
731 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "Parser.hpp" | ||
|
||
namespace pdal | ||
{ | ||
namespace expr | ||
{ | ||
|
||
bool Parser::parse(Expression& expr) | ||
{ | ||
m_lexer.reset(s); | ||
m_error.clear(); | ||
|
||
expr.clear(); | ||
bool ok = expression(expr); | ||
if (ok) | ||
{ | ||
// If we're at the end, we should have exhausted all tokens. | ||
Token tok = m_lexer.get(); | ||
if (tok != TokenType::Eof) | ||
{ | ||
m_error = "Found '" + tok.sval() + "' after valid expression."; | ||
return false; | ||
} | ||
} | ||
return ok; | ||
} | ||
|
||
Token Parser::curToken() const | ||
{ | ||
return m_curTok; | ||
} | ||
|
||
bool Parser::match(TokenType type) | ||
{ | ||
Token t = m_lexer.get(); | ||
if (t.type() == type) | ||
{ | ||
m_curTok = t; | ||
return true; | ||
} | ||
m_lexer.put(t); | ||
return false; | ||
} | ||
|
||
void Parser::setError(const std::string& err) | ||
{ | ||
if (m_error.empty()) | ||
m_error = err; | ||
} | ||
|
||
} // namespace expr | ||
} // namespace pdal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
#include <queue> | ||
#include <stack> | ||
#include <iostream> | ||
#include <iomanip> | ||
|
||
#include "Lexer.hpp" | ||
#include "Expression.hpp" | ||
|
||
namespace pdal | ||
{ | ||
namespace expr | ||
{ | ||
|
||
class BaseParser | ||
{ | ||
public: | ||
Parser(Lexer& lexer) : m_lexer(lexer) | ||
{} | ||
|
||
bool parse(Expression& expr); | ||
std::string error() const | ||
{ return m_error; } | ||
|
||
protected: | ||
bool match(TokenType type); | ||
Token curToken() const; | ||
Token lastToken() const; | ||
void setError(const std::string& err); | ||
Lexer& lexer() | ||
{ return m_lexer; } | ||
|
||
private: | ||
Lexer& m_lexer; | ||
Token m_curTok; | ||
std::string m_error; | ||
}; | ||
|
||
} // namespace expr | ||
} // namespace pdal |
Oops, something went wrong.