Skip to content

Commit

Permalink
decl pt.1
Browse files Browse the repository at this point in the history
  • Loading branch information
amanuel2 committed Jun 24, 2024
1 parent 45a1716 commit b5ee9d2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
5 changes: 3 additions & 2 deletions include/reader/reader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ namespace rift
return false;
}

inline bool match_kw(T expected, std::string kw) {
inline bool match_kw(T expected/*, std::string kw*/) {
if (peek(expected)) {
for (size_t i=0; i<=kw.size(); i++) advance();
// for (size_t i=0; i<=kw.size(); i++) advance();
advance();
return true;
}
return false;
Expand Down
8 changes: 1 addition & 7 deletions lib/ast/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ namespace rift
error::runTimeError(e.what());
}

for (const auto& r : res)
std::cout << r << std::endl;
return res;
}

Expand Down Expand Up @@ -211,7 +209,7 @@ namespace rift
Token Visitor::visit_print_stmt(const StmtPrint& stmt) const
{
Token val = stmt.expr->accept(*this);
std::cout << val << std::endl;
std::cout << castString(val) << std::endl;
return val;
}

Expand All @@ -225,10 +223,6 @@ namespace rift
Tokens Visitor::visit_program(const Program& prgm) const
{
std::vector<Token> tokens = {};
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
auto test = prgm.statements.get()->at(0).get();
#pragma clang diagnostic pop
for (auto it=prgm.statements->begin(); it!=prgm.statements->end(); it++) {
tokens.push_back((*it)->accept(*this));
}
Expand Down
17 changes: 6 additions & 11 deletions lib/ast/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,11 @@ namespace rift

std::unique_ptr<StmtPrint> Parser::statement_print()
{
if (match({Token(TokenType::PRINT, "", "", line)})) {
consume(Token(TokenType::LEFT_PAREN, "(", "", line), std::unique_ptr<ParserException>(new ParserException("Expected '(' after print")));
auto expr = expression();
consume(Token(TokenType::RIGHT_PAREN, ")", "", line), std::unique_ptr<ParserException>(new ParserException("Expected ')' after print")));

return std::unique_ptr<StmtPrint>(new StmtPrint(expr));

}

return nullptr;
consume(Token(TokenType::LEFT_PAREN, "(", "", line), std::unique_ptr<ParserException>(new ParserException("Expected '(' after print")));
auto expr = expression();
consume(Token(TokenType::RIGHT_PAREN, ")", "", line), std::unique_ptr<ParserException>(new ParserException("Expected ')' after print")));
consume(Token(TokenType::SEMICOLON, ";", "", line), std::unique_ptr<ParserException>(new ParserException("Expected ';' after print statement")));
return std::unique_ptr<StmtPrint>(new StmtPrint(expr));
}

#pragma mark - Program Parsing
Expand All @@ -183,7 +178,7 @@ namespace rift
vec_prog statements = std::make_unique<std::vector<std::unique_ptr<Stmt>>>();

while (!atEnd()) {
if (match_kw (Token(TokenType::PRINT, "", "", line), "print")) {
if (match_kw (Token(TokenType::PRINT, "", "", line))) {
statements->push_back(statement_print());
} else if (match ({Token(TokenType::EOFF, "", "", line)})) {
break;
Expand Down
2 changes: 1 addition & 1 deletion lib/driver/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace rift
while(true)
{
std::string input = "";
std::cout << "> ";
std::cout << "🦊 > ";
std::getline(std::cin >> std::ws, input);
if (input.empty()) break;
run(input);
Expand Down

0 comments on commit b5ee9d2

Please sign in to comment.