Skip to content

Commit

Permalink
Merge pull request #7 from blorente/debugger
Browse files Browse the repository at this point in the history
Debugger
  • Loading branch information
blorente authored Apr 12, 2017
2 parents 4da7938 + 18fea99 commit 3525452
Show file tree
Hide file tree
Showing 49 changed files with 266 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ deploy:
branch: master
env:
global:
secure: cEgIAN379G8SJa+JFJhzpa6vBbdjDdgz7PXXakgYh+voGJkPZ63JBNSQYKFqrGGrlV0YiLRAhjopHxrqsmmg/W6Y47QWzMipB2koMABabmFFUlmXT9WmDqTVguUEZVxw5y2MNGEtGrJ9nUOXB6Mo4PiGSbOiEX8CB4FQ+CLM602+j0Skj9C5ToPKxRufK6j9ZqG1QNjauexK3LavcVvnAD8Twl1svkb+nqypwNQKLsfoURgZicQmXDUig0zp32j4WfTnw13ndHTElPZTxYi2+diT61GEIJMEg0a9TjIPn0tLG0KEEqUkpipWUXiLU1i/hTBAHZ3PTv+iTFFJtBMlJdk3BFkmml+h6krvugguiEtQh5gMkwN/uGyaOxuZCSFpsKm/leDuCCcFl8WRLn1h3bZFXwRr7JIfVrAHKOrMuXbyg4zZXDN/GRRYExkx9vgmQRg3Gf0TF9GY1S2aFtcgt/8z9GD0r9/J8vkW5hfAa+0Fv6FDtiPRegNE1cKR4Jaa1WkXJUqeNgUVQogfKi5WhiH1gg9jAKrxts34dB5kM5n3NGgfgbgmQzA75JnCmJOyEwqPHnttApl1TRCEsJat6ajFF2xoD/cBlLZu9jNmIKAALoTgr+N6c7y9+v19DrZslAp2NY3G8TcBmKZzJZwuPXnDKsORXn9AmM/m2qbjXzQ=
secure: cEgIAN379G8SJa+JFJhzpa6vBbdjDdgz7PXXakgYh+voGJkPZ63JBNSQYKFqrGGrlV0YiLRAhjopHxrqsmmg/W6Y47QWzMipB2koMABabmFFUlmXT9WmDqTVguUEZVxw5y2MNGEtGrJ9nUOXB6Mo4PiGSbOiEX8CB4FQ+CLM602+j0Skj9C5ToPKxRufK6j9ZqG1QNjauexK3LavcVvnAD8Twl1svkb+nqypwNQKLsfoURgZicQmXDUig0zp32j4WfTnw13ndHTElPZTxYi2+diT61GEIJMEg0a9TjIPn0tLG0KEEqUkpipWUXiLU1i/hTBAHZ3PTv+iTFFJtBMlJdk3BFkmml+h6krvugguiEtQh5gMkwN/uGyaOxuZCSFpsKm/leDuCCcFl8WRLn1h3bZFXwRr7JIfVrAHKOrMuXbyg4zZXDN/GRRYExkx9vgmQRg3Gf0TF9GY1S2aFtcgt/8z9GD0r9/J8vkW5hfAa+0Fv6FDtiPRegNE1cKR4Jaa1WkXJUqeNgUVQogfKi5WhiH1gg9jAKrxts34dB5kM5n3NGgfgbgmQzA75JnCmJOyEwqPHnttApl1TRCEsJat6ajFF2xoD/cBlLZu9jNmIKAALoTgr+N6c7y9+v19DrZslAp2NY3G8TcBmKZzJZwuPXnDKsORXn9AmM/m2qbjXzQ=
2 changes: 1 addition & 1 deletion examples/Declarations.grace
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ def x = "Hello";
def y = x.++(" World");
def obj = object {
method add(n) to(t) {
n + t
n + t;
}
var val := 2;
};
2 changes: 1 addition & 1 deletion examples/Variables.grace
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ def x = "Hello";
def y = x.++(" World");
def obj = object {
method add(n) to(t) {
n + t
n + t;
}
var val := add(2)to(3);
};
Expand Down
4 changes: 2 additions & 2 deletions grammars/GraceParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void doAfter() {}
* Parser Rules
*/
program: (statement)*;
statement: expression | declaration; //| control;
statement: expression DELIMITER | declaration; //| control;

declaration : variableDeclaration
| constantDeclaration
Expand All @@ -92,7 +92,7 @@ formalParameterList: formalParameter (COMMA formalParameter)*;
formalParameter: identifier;

methodBody: OPEN_BRACE methodBodyLine* CLOSE_BRACE;
methodBodyLine: variableDeclaration | constantDeclaration | expression; //| control;
methodBodyLine: variableDeclaration | constantDeclaration | expression DELIMITER; //| control;

// Using left-recursion and implicit operator precendence. ANTLR 4 Reference, page 70
expression : rec=expression op=(MUL | DIV) param=expression #MulDivExp
Expand Down
2 changes: 1 addition & 1 deletion interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ include_directories(${antlr4cpp_include_dirs_naylang})

add_executable(interpreter ${SOURCE_FILES} ${antlr4cpp_src_files_naylang})
add_dependencies(interpreter antlr4cpp antlr4cpp_generation_naylang)
target_link_libraries(interpreter antlr4-runtime)
target_link_libraries(interpreter libantlr4-runtime.a)
11 changes: 11 additions & 0 deletions interpreter/src/core/model/ast/Statement.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,20 @@ class Statement;
typedef std::shared_ptr<Statement> StatementPtr;

class Statement {
protected:

int _line;
int _col;

public:

Statement() : _line{-1}, _col{-1} {}
Statement(int line, int col) : _line{line}, _col{col} {}

virtual void accept(Evaluator &evaluator) = 0;

int line() {return _line;}
int col() {return _col;}
};

}
Expand Down
5 changes: 4 additions & 1 deletion interpreter/src/core/model/ast/control/IfThen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
#include "IfThen.h"

namespace naylang {
IfThen::IfThen(ExpressionPtr condition, BlockPtr thenExp, int line, int col) :
_condition{condition}, _then{thenExp}, IfThen::Statement(line, col) {}

IfThen::IfThen(ExpressionPtr condition, BlockPtr thenExp) :
_condition{condition}, _then{thenExp} {}
IfThen(condition, thenExp, -1, -1) {}

void IfThen::accept(Evaluator &evaluator) {
evaluator.evaluate(*this);
Expand Down
5 changes: 5 additions & 0 deletions interpreter/src/core/model/ast/control/IfThen.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class IfThen : public Statement {

public:

IfThen(
ExpressionPtr condition,
BlockPtr thenExp,
int line, int col);

IfThen(
ExpressionPtr condition,
BlockPtr thenExp);
Expand Down
6 changes: 5 additions & 1 deletion interpreter/src/core/model/ast/control/IfThenElse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ namespace naylang {
IfThenElse::IfThenElse(
ExpressionPtr condition,
BlockPtr thenExp,
BlockPtr elseExp) {
BlockPtr elseExp) :
IfThenElse(condition, thenExp, elseExp, -1, -1) {}

IfThenElse::IfThenElse(ExpressionPtr condition, BlockPtr thenExp, BlockPtr elseExp, int line, int col) :
IfThenElse::Statement(line, col) {
_condition = std::move(condition);
_then = std::move(thenExp);
_else = std::move(elseExp);
Expand Down
5 changes: 5 additions & 0 deletions interpreter/src/core/model/ast/control/IfThenElse.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class IfThenElse : public Statement {

public:

IfThenElse(
ExpressionPtr condition,
BlockPtr thenExp,
BlockPtr elseExp,
int line, int col);
IfThenElse(
ExpressionPtr condition,
BlockPtr thenExp,
Expand Down
6 changes: 6 additions & 0 deletions interpreter/src/core/model/ast/control/Return.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@

namespace naylang {

Return::Return(int line, int col) :
Return::Statement(line, col) {}

Return::Return() : Return::Statement() {}

void Return::accept(Evaluator &evaluator) {
evaluator.evaluate(*this);
}

}
3 changes: 3 additions & 0 deletions interpreter/src/core/model/ast/control/Return.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ namespace naylang {
class Return : public Statement {
public:

Return(int line, int col);
Return();

virtual void accept(Evaluator &evaluator);
};
} // end namespace naylang
Expand Down
6 changes: 4 additions & 2 deletions interpreter/src/core/model/ast/control/While.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

namespace naylang {

While::While(BlockPtr condition, BlockPtr body, int line, int col) :
_condition{condition}, _body{body}, While::Statement(line, col) {}

While::While(BlockPtr condition, BlockPtr body) :
_condition{condition}, _body{body} {}
While(condition, body, -1, -1) {}

void While::accept(Evaluator &evaluator) {
evaluator.evaluate(*this);
Expand All @@ -24,5 +27,4 @@ const std::shared_ptr<Block> &While::condition() const {
const std::shared_ptr<Block> &While::body() const {
return _body;
}

}
1 change: 1 addition & 0 deletions interpreter/src/core/model/ast/control/While.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class While : public Statement {
BlockPtr _body;

public:
While(BlockPtr condition, BlockPtr body, int line, int col);
While(BlockPtr condition, BlockPtr body);

void accept(Evaluator &evaluator) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

namespace naylang {

ConstantDeclaration::ConstantDeclaration(const std::string &identifier, ExpressionPtr value, int line, int col) :
_name{identifier}, _value(value), Declaration::Declaration(line, col) {}

ConstantDeclaration::ConstantDeclaration(const std::string &name, ExpressionPtr value) :
_name(name), _value(value) {}
ConstantDeclaration(name, value, -1, -1){}

void ConstantDeclaration::accept(Evaluator &evaluator) {
evaluator.evaluate(*this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class ConstantDeclaration : public Declaration {

public:

ConstantDeclaration(
const std::string &identifier,
ExpressionPtr value,
int line, int col);
ConstantDeclaration(const std::string &identifier, ExpressionPtr value);

virtual void accept(Evaluator &evaluator);
Expand Down
2 changes: 2 additions & 0 deletions interpreter/src/core/model/ast/declarations/Declaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ typedef std::shared_ptr<Declaration> DeclarationPtr;
class Declaration : public Statement {
public:

Declaration(int line, int col) : Statement(line, col) {}

virtual void accept(Evaluator &evaluator) = 0;
virtual const std::string &name() const = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ namespace naylang {

MethodDeclaration::MethodDeclaration(const std::string &name, const std::vector<DeclarationPtr> &params,
const std::vector<StatementPtr> &body) :
_name{name}, _params{params}, _body{body}{}
MethodDeclaration(name, params, body, -1, -1) {}

MethodDeclaration::MethodDeclaration(const std::string &name, const std::vector<DeclarationPtr> &params,
const std::vector<StatementPtr> &body, int line, int col) :
_name{name}, _params{params}, _body{body}, MethodDeclaration::Declaration(line, col) {}

void MethodDeclaration::accept(Evaluator &evaluator) {
evaluator.evaluate(*this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class MethodDeclaration : public Declaration {
std::vector<StatementPtr> _body;

public:
MethodDeclaration(
const std::string &name,
const std::vector<DeclarationPtr> &params,
const std::vector<StatementPtr> &body,
int line, int col);

MethodDeclaration(
const std::string &name,
const std::vector<DeclarationPtr> &params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@

namespace naylang {

VariableDeclaration::VariableDeclaration(const std::string &identifier)
: _identifier(identifier) {}
VariableDeclaration::VariableDeclaration(const std::string &identifier, ExpressionPtr initialValue, int line, int col) :
_identifier{identifier}, _initialValue{initialValue},
VariableDeclaration::Declaration(line, col) {}

VariableDeclaration::VariableDeclaration(const std::string &identifier, ExpressionPtr intialValue) :
_identifier{identifier}, _initialValue{intialValue} {}
VariableDeclaration::VariableDeclaration(const std::string &identifier, int line, int col) :
VariableDeclaration(identifier, nullptr, line, col) {}

VariableDeclaration::VariableDeclaration(const std::string &identifier, ExpressionPtr initialValue) :
VariableDeclaration(identifier, initialValue, -1, -1) {}

VariableDeclaration::VariableDeclaration(const std::string &identifier) :
VariableDeclaration(identifier, -1, -1) {}

void VariableDeclaration::accept(Evaluator &evaluator) {
evaluator.evaluate(*this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ class VariableDeclaration : public Declaration {

public:

VariableDeclaration(const std::string &identifier);
VariableDeclaration(const std::string &identifier, ExpressionPtr intialValue, int line, int col);
VariableDeclaration(const std::string &identifier, ExpressionPtr intialValue);
VariableDeclaration(const std::string &identifier, int line, int col);
VariableDeclaration(const std::string &identifier);

virtual void accept(Evaluator &evaluator);
const std::string &name() const;
Expand Down
9 changes: 4 additions & 5 deletions interpreter/src/core/model/ast/expressions/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

namespace naylang {

Block::Block(int line, int col) : Expression(line, col) {}

Block::Block() : Block(-1, -1) {}

void Block::accept(Evaluator &evaluator) {
evaluator.evaluate(*this);
}
Expand All @@ -29,9 +33,4 @@ void Block::addStatement(StatementPtr statement) {
void Block::addParameter(DeclarationPtr param) {
_params.push_back(param);
}

BlockPtr Block::get_shared() {
return shared_from_this();
}

}
4 changes: 2 additions & 2 deletions interpreter/src/core/model/ast/expressions/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class Block : public Expression, public std::enable_shared_from_this<Block> {

public:

Block() = default;
Block(int line, int col);
Block();

void accept(Evaluator &evaluator) override;

Expand All @@ -33,7 +34,6 @@ class Block : public Expression, public std::enable_shared_from_this<Block> {

void addStatement(StatementPtr statement);
void addParameter(DeclarationPtr param);
BlockPtr get_shared();
};

} // end namespace naylang
Expand Down
2 changes: 2 additions & 0 deletions interpreter/src/core/model/ast/expressions/Expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ typedef std::shared_ptr<Expression> ExpressionPtr;
class Expression : public Statement {
public:

Expression(int line, int col) : Statement(line, col) {}

virtual void accept(Evaluator &evaluator) = 0;
};
}
Expand Down
15 changes: 12 additions & 3 deletions interpreter/src/core/model/ast/expressions/Lineup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@

namespace naylang {

Lineup::Lineup(const std::vector<ExpressionPtr> &values, int line, int col) :
_contents{values}, Expression(line, col) {}

Lineup::Lineup(int line, int col) :
Lineup({}, line, col) {}

Lineup::Lineup(const std::vector<ExpressionPtr> &values) :
Lineup(values, -1, -1) {}

Lineup::Lineup() :
Lineup({}, -1, -1) {}

void Lineup::accept(Evaluator &evaluator) {
evaluator.evaluate(*this);
}

Lineup::Lineup(const std::vector<ExpressionPtr> &values) :
_contents{values} {}

const std::vector<ExpressionPtr> &Lineup::contents() const {
return _contents;
}
Expand Down
4 changes: 3 additions & 1 deletion interpreter/src/core/model/ast/expressions/Lineup.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ class Lineup : public Expression {

public:

Lineup() = default;
Lineup(const std::vector<ExpressionPtr> &values, int line, int col);
Lineup(const std::vector<ExpressionPtr> &values);
Lineup(int line, int col);
Lineup();

virtual void accept(Evaluator &evaluator);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

namespace naylang {

ObjectConstructor::ObjectConstructor(const std::vector<StatementPtr> &statements) : _statements{statements} {}
ObjectConstructor::ObjectConstructor(const std::vector<StatementPtr> &statements, int line, int col) :
_statements{statements}, Expression(line, col) {}

ObjectConstructor::ObjectConstructor(const std::vector<StatementPtr> &statements) :
ObjectConstructor(statements, -1, -1){}

void ObjectConstructor::accept(Evaluator &evaluator) {
evaluator.evaluate(*this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ObjectConstructor : public Expression {
std::vector<StatementPtr> _statements;

public:
ObjectConstructor(const std::vector<StatementPtr> &statements, int line, int col);
ObjectConstructor(const std::vector<StatementPtr> &statements);

virtual void accept(Evaluator &evaluator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
#include "BooleanLiteral.h"

namespace naylang {
BooleanLiteral::BooleanLiteral(bool value) : _value(value) {}
BooleanLiteral::BooleanLiteral(bool value) : BooleanLiteral(value, -1, -1) {}

BooleanLiteral::BooleanLiteral(bool value, int line, int col) :
_value(value), Expression(line, col) {}

void BooleanLiteral::accept(Evaluator &evaluator) {
evaluator.evaluate(*this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BooleanLiteral : public Expression {

public:

BooleanLiteral(bool value, int line, int col);
BooleanLiteral(bool value);

virtual void accept(Evaluator &evaluator);
Expand Down
Loading

0 comments on commit 3525452

Please sign in to comment.