Skip to content

Commit

Permalink
made requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dsLeks committed Jan 26, 2024
1 parent 67c2e3e commit 563e28f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "xos.h"

namespace xos {

Result<std::unique_ptr<ast::Str>> Parser::parseStr() {
Result<Token> res = lexer_.Lex();
if (res.hasError()) {
Expand Down Expand Up @@ -46,14 +47,14 @@ Result<std::unique_ptr<ast::Expr>> Parser::parseExpr() {
return Result<std::unique_ptr<ast::Expr>>(std::move(out.get()));
}

// TODO(dsLeks): Implement this.
return Result<std::unique_ptr<ast::Expr>>::BuildError()
<< "Expected '(' on row " << tok.getRow() << ", col " << tok.getCol()
<< "!!!";
; // TODO(dsLeks): Implement this.
<< "Unable to parse expression for token `" << tok.getKind()
<< "` on row " << tok.getRow() << ", col " << tok.getCol();
}

Result<std::unique_ptr<ast::Prototype>> Parser::parsePrototype(
std::string name) {
std::string &name) {
Result<Token> res = lexer_.Lex();
if (res.hasError()) return res;
Token tok = res.get();
Expand All @@ -62,12 +63,11 @@ Result<std::unique_ptr<ast::Prototype>> Parser::parsePrototype(
<< "Expected '(' on row " << tok.getRow() << ", col "
<< tok.getCol();
}
// PARSE RETURN TYPE HERE
while (tok.getKind() != Token::rparen) {
res = lexer_.Lex();
tok = res.get();
}
// PARSE ARROW

res = lexer_.Lex();
tok = res.get();
if (tok.getKind() != Token::arrow) {
Expand All @@ -77,7 +77,7 @@ Result<std::unique_ptr<ast::Prototype>> Parser::parsePrototype(
}
res = lexer_.Lex();
tok = res.get();
// PARSE ARGUMENTS HERE

while (tok.getKind() != Token::rparen) {
res = lexer_.Lex();
tok = res.get();
Expand All @@ -99,11 +99,11 @@ Result<std::unique_ptr<ast::Func>> Parser::parseFunc() {
pres = parsePrototype(name);
if (pres.hasError()) return pres;
}
Result<std::unique_ptr<ast::Expr>> exptr = parseExpr();
if (exptr.hasError()) return exptr;
Result<std::unique_ptr<ast::Expr>> expr = parseExpr();
if (expr.hasError()) return expr;

return Result<std::unique_ptr<ast::Func>>(std::make_unique<ast::Func>(
std::move(pres.get()), std::move(exptr.get())));
std::move(pres.get()), std::move(expr.get())));
}

} // namespace xos
10 changes: 5 additions & 5 deletions xos.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <stdio.h>
#include <stdlib.h>

#include <cassert>
#include <iostream>
#include <istream>
#include <memory>
Expand Down Expand Up @@ -144,11 +145,10 @@ namespace ast {
class Expr {
public:
virtual ~Expr() = default;
bool operator==(
const Expr &other) const // TODO(PiJoules): add rtti and implement the
// comparison operator here.
bool operator==([[maybe_unused]] const Expr &other)
const // TODO(PiJoules): add rtti and implement the comparison operator
// here.
{
const auto l = other;
return true;
};
};
Expand Down Expand Up @@ -209,7 +209,7 @@ class Parser {
Parser(Lexer &lexer) : lexer_(lexer) {}
Result<std::unique_ptr<ast::Str>> parseStr();
Result<std::unique_ptr<ast::Out>> parseOut();
Result<std::unique_ptr<ast::Prototype>> parsePrototype(std::string name);
Result<std::unique_ptr<ast::Prototype>> parsePrototype(std::string &name);
Result<std::unique_ptr<ast::Expr>> parseExpr();
Result<std::unique_ptr<ast::Func>> parseFunc();

Expand Down

0 comments on commit 563e28f

Please sign in to comment.