Skip to content

Commit 3525452

Browse files
authored
Merge pull request #7 from blorente/debugger
Debugger
2 parents 4da7938 + 18fea99 commit 3525452

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+266
-83
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ deploy:
4343
branch: master
4444
env:
4545
global:
46-
secure: cEgIAN379G8SJa+JFJhzpa6vBbdjDdgz7PXXakgYh+voGJkPZ63JBNSQYKFqrGGrlV0YiLRAhjopHxrqsmmg/W6Y47QWzMipB2koMABabmFFUlmXT9WmDqTVguUEZVxw5y2MNGEtGrJ9nUOXB6Mo4PiGSbOiEX8CB4FQ+CLM602+j0Skj9C5ToPKxRufK6j9ZqG1QNjauexK3LavcVvnAD8Twl1svkb+nqypwNQKLsfoURgZicQmXDUig0zp32j4WfTnw13ndHTElPZTxYi2+diT61GEIJMEg0a9TjIPn0tLG0KEEqUkpipWUXiLU1i/hTBAHZ3PTv+iTFFJtBMlJdk3BFkmml+h6krvugguiEtQh5gMkwN/uGyaOxuZCSFpsKm/leDuCCcFl8WRLn1h3bZFXwRr7JIfVrAHKOrMuXbyg4zZXDN/GRRYExkx9vgmQRg3Gf0TF9GY1S2aFtcgt/8z9GD0r9/J8vkW5hfAa+0Fv6FDtiPRegNE1cKR4Jaa1WkXJUqeNgUVQogfKi5WhiH1gg9jAKrxts34dB5kM5n3NGgfgbgmQzA75JnCmJOyEwqPHnttApl1TRCEsJat6ajFF2xoD/cBlLZu9jNmIKAALoTgr+N6c7y9+v19DrZslAp2NY3G8TcBmKZzJZwuPXnDKsORXn9AmM/m2qbjXzQ=
46+
secure: cEgIAN379G8SJa+JFJhzpa6vBbdjDdgz7PXXakgYh+voGJkPZ63JBNSQYKFqrGGrlV0YiLRAhjopHxrqsmmg/W6Y47QWzMipB2koMABabmFFUlmXT9WmDqTVguUEZVxw5y2MNGEtGrJ9nUOXB6Mo4PiGSbOiEX8CB4FQ+CLM602+j0Skj9C5ToPKxRufK6j9ZqG1QNjauexK3LavcVvnAD8Twl1svkb+nqypwNQKLsfoURgZicQmXDUig0zp32j4WfTnw13ndHTElPZTxYi2+diT61GEIJMEg0a9TjIPn0tLG0KEEqUkpipWUXiLU1i/hTBAHZ3PTv+iTFFJtBMlJdk3BFkmml+h6krvugguiEtQh5gMkwN/uGyaOxuZCSFpsKm/leDuCCcFl8WRLn1h3bZFXwRr7JIfVrAHKOrMuXbyg4zZXDN/GRRYExkx9vgmQRg3Gf0TF9GY1S2aFtcgt/8z9GD0r9/J8vkW5hfAa+0Fv6FDtiPRegNE1cKR4Jaa1WkXJUqeNgUVQogfKi5WhiH1gg9jAKrxts34dB5kM5n3NGgfgbgmQzA75JnCmJOyEwqPHnttApl1TRCEsJat6ajFF2xoD/cBlLZu9jNmIKAALoTgr+N6c7y9+v19DrZslAp2NY3G8TcBmKZzJZwuPXnDKsORXn9AmM/m2qbjXzQ=

examples/Declarations.grace

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ def x = "Hello";
22
def y = x.++(" World");
33
def obj = object {
44
method add(n) to(t) {
5-
n + t
5+
n + t;
66
}
77
var val := 2;
88
};

examples/Variables.grace

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ def x = "Hello";
22
def y = x.++(" World");
33
def obj = object {
44
method add(n) to(t) {
5-
n + t
5+
n + t;
66
}
77
var val := add(2)to(3);
88
};

grammars/GraceParser.g4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void doAfter() {}
7070
* Parser Rules
7171
*/
7272
program: (statement)*;
73-
statement: expression | declaration; //| control;
73+
statement: expression DELIMITER | declaration; //| control;
7474

7575
declaration : variableDeclaration
7676
| constantDeclaration
@@ -92,7 +92,7 @@ formalParameterList: formalParameter (COMMA formalParameter)*;
9292
formalParameter: identifier;
9393

9494
methodBody: OPEN_BRACE methodBodyLine* CLOSE_BRACE;
95-
methodBodyLine: variableDeclaration | constantDeclaration | expression; //| control;
95+
methodBodyLine: variableDeclaration | constantDeclaration | expression DELIMITER; //| control;
9696

9797
// Using left-recursion and implicit operator precendence. ANTLR 4 Reference, page 70
9898
expression : rec=expression op=(MUL | DIV) param=expression #MulDivExp

interpreter/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ include_directories(${antlr4cpp_include_dirs_naylang})
3030

3131
add_executable(interpreter ${SOURCE_FILES} ${antlr4cpp_src_files_naylang})
3232
add_dependencies(interpreter antlr4cpp antlr4cpp_generation_naylang)
33-
target_link_libraries(interpreter antlr4-runtime)
33+
target_link_libraries(interpreter libantlr4-runtime.a)

interpreter/src/core/model/ast/Statement.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,20 @@ class Statement;
1717
typedef std::shared_ptr<Statement> StatementPtr;
1818

1919
class Statement {
20+
protected:
21+
22+
int _line;
23+
int _col;
24+
2025
public:
2126

27+
Statement() : _line{-1}, _col{-1} {}
28+
Statement(int line, int col) : _line{line}, _col{col} {}
29+
2230
virtual void accept(Evaluator &evaluator) = 0;
31+
32+
int line() {return _line;}
33+
int col() {return _col;}
2334
};
2435

2536
}

interpreter/src/core/model/ast/control/IfThen.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
#include "IfThen.h"
77

88
namespace naylang {
9+
IfThen::IfThen(ExpressionPtr condition, BlockPtr thenExp, int line, int col) :
10+
_condition{condition}, _then{thenExp}, IfThen::Statement(line, col) {}
11+
912
IfThen::IfThen(ExpressionPtr condition, BlockPtr thenExp) :
10-
_condition{condition}, _then{thenExp} {}
13+
IfThen(condition, thenExp, -1, -1) {}
1114

1215
void IfThen::accept(Evaluator &evaluator) {
1316
evaluator.evaluate(*this);

interpreter/src/core/model/ast/control/IfThen.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ class IfThen : public Statement {
1818

1919
public:
2020

21+
IfThen(
22+
ExpressionPtr condition,
23+
BlockPtr thenExp,
24+
int line, int col);
25+
2126
IfThen(
2227
ExpressionPtr condition,
2328
BlockPtr thenExp);

interpreter/src/core/model/ast/control/IfThenElse.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ namespace naylang {
99
IfThenElse::IfThenElse(
1010
ExpressionPtr condition,
1111
BlockPtr thenExp,
12-
BlockPtr elseExp) {
12+
BlockPtr elseExp) :
13+
IfThenElse(condition, thenExp, elseExp, -1, -1) {}
14+
15+
IfThenElse::IfThenElse(ExpressionPtr condition, BlockPtr thenExp, BlockPtr elseExp, int line, int col) :
16+
IfThenElse::Statement(line, col) {
1317
_condition = std::move(condition);
1418
_then = std::move(thenExp);
1519
_else = std::move(elseExp);

interpreter/src/core/model/ast/control/IfThenElse.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ class IfThenElse : public Statement {
1919

2020
public:
2121

22+
IfThenElse(
23+
ExpressionPtr condition,
24+
BlockPtr thenExp,
25+
BlockPtr elseExp,
26+
int line, int col);
2227
IfThenElse(
2328
ExpressionPtr condition,
2429
BlockPtr thenExp,

interpreter/src/core/model/ast/control/Return.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010

1111
namespace naylang {
1212

13+
Return::Return(int line, int col) :
14+
Return::Statement(line, col) {}
15+
16+
Return::Return() : Return::Statement() {}
17+
1318
void Return::accept(Evaluator &evaluator) {
1419
evaluator.evaluate(*this);
1520
}
21+
1622
}

interpreter/src/core/model/ast/control/Return.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ namespace naylang {
1212
class Return : public Statement {
1313
public:
1414

15+
Return(int line, int col);
16+
Return();
17+
1518
virtual void accept(Evaluator &evaluator);
1619
};
1720
} // end namespace naylang

interpreter/src/core/model/ast/control/While.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010

1111
namespace naylang {
1212

13+
While::While(BlockPtr condition, BlockPtr body, int line, int col) :
14+
_condition{condition}, _body{body}, While::Statement(line, col) {}
15+
1316
While::While(BlockPtr condition, BlockPtr body) :
14-
_condition{condition}, _body{body} {}
17+
While(condition, body, -1, -1) {}
1518

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

interpreter/src/core/model/ast/control/While.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class While : public Statement {
1919
BlockPtr _body;
2020

2121
public:
22+
While(BlockPtr condition, BlockPtr body, int line, int col);
2223
While(BlockPtr condition, BlockPtr body);
2324

2425
void accept(Evaluator &evaluator) override;

interpreter/src/core/model/ast/declarations/ConstantDeclaration.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77

88
namespace naylang {
99

10+
ConstantDeclaration::ConstantDeclaration(const std::string &identifier, ExpressionPtr value, int line, int col) :
11+
_name{identifier}, _value(value), Declaration::Declaration(line, col) {}
12+
1013
ConstantDeclaration::ConstantDeclaration(const std::string &name, ExpressionPtr value) :
11-
_name(name), _value(value) {}
14+
ConstantDeclaration(name, value, -1, -1){}
1215

1316
void ConstantDeclaration::accept(Evaluator &evaluator) {
1417
evaluator.evaluate(*this);

interpreter/src/core/model/ast/declarations/ConstantDeclaration.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ class ConstantDeclaration : public Declaration {
2121

2222
public:
2323

24+
ConstantDeclaration(
25+
const std::string &identifier,
26+
ExpressionPtr value,
27+
int line, int col);
2428
ConstantDeclaration(const std::string &identifier, ExpressionPtr value);
2529

2630
virtual void accept(Evaluator &evaluator);

interpreter/src/core/model/ast/declarations/Declaration.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ typedef std::shared_ptr<Declaration> DeclarationPtr;
1818
class Declaration : public Statement {
1919
public:
2020

21+
Declaration(int line, int col) : Statement(line, col) {}
22+
2123
virtual void accept(Evaluator &evaluator) = 0;
2224
virtual const std::string &name() const = 0;
2325
};

interpreter/src/core/model/ast/declarations/MethodDeclaration.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ namespace naylang {
99

1010
MethodDeclaration::MethodDeclaration(const std::string &name, const std::vector<DeclarationPtr> &params,
1111
const std::vector<StatementPtr> &body) :
12-
_name{name}, _params{params}, _body{body}{}
12+
MethodDeclaration(name, params, body, -1, -1) {}
13+
14+
MethodDeclaration::MethodDeclaration(const std::string &name, const std::vector<DeclarationPtr> &params,
15+
const std::vector<StatementPtr> &body, int line, int col) :
16+
_name{name}, _params{params}, _body{body}, MethodDeclaration::Declaration(line, col) {}
1317

1418
void MethodDeclaration::accept(Evaluator &evaluator) {
1519
evaluator.evaluate(*this);

interpreter/src/core/model/ast/declarations/MethodDeclaration.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ class MethodDeclaration : public Declaration {
1919
std::vector<StatementPtr> _body;
2020

2121
public:
22+
MethodDeclaration(
23+
const std::string &name,
24+
const std::vector<DeclarationPtr> &params,
25+
const std::vector<StatementPtr> &body,
26+
int line, int col);
27+
2228
MethodDeclaration(
2329
const std::string &name,
2430
const std::vector<DeclarationPtr> &params,

interpreter/src/core/model/ast/declarations/VariableDeclaration.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@
77

88
namespace naylang {
99

10-
VariableDeclaration::VariableDeclaration(const std::string &identifier)
11-
: _identifier(identifier) {}
10+
VariableDeclaration::VariableDeclaration(const std::string &identifier, ExpressionPtr initialValue, int line, int col) :
11+
_identifier{identifier}, _initialValue{initialValue},
12+
VariableDeclaration::Declaration(line, col) {}
1213

13-
VariableDeclaration::VariableDeclaration(const std::string &identifier, ExpressionPtr intialValue) :
14-
_identifier{identifier}, _initialValue{intialValue} {}
14+
VariableDeclaration::VariableDeclaration(const std::string &identifier, int line, int col) :
15+
VariableDeclaration(identifier, nullptr, line, col) {}
16+
17+
VariableDeclaration::VariableDeclaration(const std::string &identifier, ExpressionPtr initialValue) :
18+
VariableDeclaration(identifier, initialValue, -1, -1) {}
19+
20+
VariableDeclaration::VariableDeclaration(const std::string &identifier) :
21+
VariableDeclaration(identifier, -1, -1) {}
1522

1623
void VariableDeclaration::accept(Evaluator &evaluator) {
1724
evaluator.evaluate(*this);

interpreter/src/core/model/ast/declarations/VariableDeclaration.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ class VariableDeclaration : public Declaration {
1919

2020
public:
2121

22-
VariableDeclaration(const std::string &identifier);
22+
VariableDeclaration(const std::string &identifier, ExpressionPtr intialValue, int line, int col);
2323
VariableDeclaration(const std::string &identifier, ExpressionPtr intialValue);
24+
VariableDeclaration(const std::string &identifier, int line, int col);
25+
VariableDeclaration(const std::string &identifier);
2426

2527
virtual void accept(Evaluator &evaluator);
2628
const std::string &name() const;

interpreter/src/core/model/ast/expressions/Block.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
namespace naylang {
1212

13+
Block::Block(int line, int col) : Expression(line, col) {}
14+
15+
Block::Block() : Block(-1, -1) {}
16+
1317
void Block::accept(Evaluator &evaluator) {
1418
evaluator.evaluate(*this);
1519
}
@@ -29,9 +33,4 @@ void Block::addStatement(StatementPtr statement) {
2933
void Block::addParameter(DeclarationPtr param) {
3034
_params.push_back(param);
3135
}
32-
33-
BlockPtr Block::get_shared() {
34-
return shared_from_this();
35-
}
36-
3736
}

interpreter/src/core/model/ast/expressions/Block.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class Block : public Expression, public std::enable_shared_from_this<Block> {
2424

2525
public:
2626

27-
Block() = default;
27+
Block(int line, int col);
28+
Block();
2829

2930
void accept(Evaluator &evaluator) override;
3031

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

3435
void addStatement(StatementPtr statement);
3536
void addParameter(DeclarationPtr param);
36-
BlockPtr get_shared();
3737
};
3838

3939
} // end namespace naylang

interpreter/src/core/model/ast/expressions/Expression.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ typedef std::shared_ptr<Expression> ExpressionPtr;
1717
class Expression : public Statement {
1818
public:
1919

20+
Expression(int line, int col) : Statement(line, col) {}
21+
2022
virtual void accept(Evaluator &evaluator) = 0;
2123
};
2224
}

interpreter/src/core/model/ast/expressions/Lineup.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,22 @@
1010

1111
namespace naylang {
1212

13+
Lineup::Lineup(const std::vector<ExpressionPtr> &values, int line, int col) :
14+
_contents{values}, Expression(line, col) {}
15+
16+
Lineup::Lineup(int line, int col) :
17+
Lineup({}, line, col) {}
18+
19+
Lineup::Lineup(const std::vector<ExpressionPtr> &values) :
20+
Lineup(values, -1, -1) {}
21+
22+
Lineup::Lineup() :
23+
Lineup({}, -1, -1) {}
24+
1325
void Lineup::accept(Evaluator &evaluator) {
1426
evaluator.evaluate(*this);
1527
}
1628

17-
Lineup::Lineup(const std::vector<ExpressionPtr> &values) :
18-
_contents{values} {}
19-
2029
const std::vector<ExpressionPtr> &Lineup::contents() const {
2130
return _contents;
2231
}

interpreter/src/core/model/ast/expressions/Lineup.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ class Lineup : public Expression {
1818

1919
public:
2020

21-
Lineup() = default;
21+
Lineup(const std::vector<ExpressionPtr> &values, int line, int col);
2222
Lineup(const std::vector<ExpressionPtr> &values);
23+
Lineup(int line, int col);
24+
Lineup();
2325

2426
virtual void accept(Evaluator &evaluator);
2527

interpreter/src/core/model/ast/expressions/ObjectConstructor.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111
namespace naylang {
1212

13-
ObjectConstructor::ObjectConstructor(const std::vector<StatementPtr> &statements) : _statements{statements} {}
13+
ObjectConstructor::ObjectConstructor(const std::vector<StatementPtr> &statements, int line, int col) :
14+
_statements{statements}, Expression(line, col) {}
15+
16+
ObjectConstructor::ObjectConstructor(const std::vector<StatementPtr> &statements) :
17+
ObjectConstructor(statements, -1, -1){}
1418

1519
void ObjectConstructor::accept(Evaluator &evaluator) {
1620
evaluator.evaluate(*this);

interpreter/src/core/model/ast/expressions/ObjectConstructor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class ObjectConstructor : public Expression {
1515
std::vector<StatementPtr> _statements;
1616

1717
public:
18+
ObjectConstructor(const std::vector<StatementPtr> &statements, int line, int col);
1819
ObjectConstructor(const std::vector<StatementPtr> &statements);
1920

2021
virtual void accept(Evaluator &evaluator);

interpreter/src/core/model/ast/expressions/primitives/BooleanLiteral.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
#include "BooleanLiteral.h"
77

88
namespace naylang {
9-
BooleanLiteral::BooleanLiteral(bool value) : _value(value) {}
9+
BooleanLiteral::BooleanLiteral(bool value) : BooleanLiteral(value, -1, -1) {}
10+
11+
BooleanLiteral::BooleanLiteral(bool value, int line, int col) :
12+
_value(value), Expression(line, col) {}
1013

1114
void BooleanLiteral::accept(Evaluator &evaluator) {
1215
evaluator.evaluate(*this);

interpreter/src/core/model/ast/expressions/primitives/BooleanLiteral.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class BooleanLiteral : public Expression {
1515

1616
public:
1717

18+
BooleanLiteral(bool value, int line, int col);
1819
BooleanLiteral(bool value);
1920

2021
virtual void accept(Evaluator &evaluator);

0 commit comments

Comments
 (0)