From 80884d8e43f75e84c4acba363849d0b0803c55ae Mon Sep 17 00:00:00 2001 From: milenanedeljkovic <80540793+milenanedeljkovic@users.noreply.github.com> Date: Tue, 9 Nov 2021 11:31:41 +0100 Subject: [PATCH 01/43] draft of classes --- Algorithm-visualizer/mainwindow.h | 140 ++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/Algorithm-visualizer/mainwindow.h b/Algorithm-visualizer/mainwindow.h index 4643e32..15553c6 100644 --- a/Algorithm-visualizer/mainwindow.h +++ b/Algorithm-visualizer/mainwindow.h @@ -18,4 +18,144 @@ class MainWindow : public QMainWindow private: Ui::MainWindow *ui; }; + +class Program { + Program(); + ~Program(); + //list of statements or the + //program block - not sure yet +}; + +class Block { + Block(); + ~Block(); + //list of statements +}; + +class Statement { + Statement(); + ~Statement(); +}; + +class Expression { + Expression(); + ~Expression(); +}; + +enum var_type { + string = 0, + integer = 1, + character = 2, + floating_point = 3 + +}; + +enum un_op { + negation = 0, + plusplus = 1 + //inverse = 2 (if we add this as a unary operation for number -> -number) +}; + +enum bin_op { + conjunction = 0, + disjunction = 1, + addition = 2, + subtraction = 3, + multiplication = 4, + division = 5, + lthan = 6, + mthan = 7, + leq = 8, + meq = 9, + eq = 10, + eqeq = 11 +}; + +class Declaration : Statement { + Declaration(); + ~Declaration(); + //int x = 7, bool y = False + //attributes: + //name + value of the variable or Variable + sth +}; + +class Assignment : Statement { + Assignment(); + ~Assignment(); + //x = 5; x = y +}; + +class Return : Statement { + Return(); + ~Return(); + //attribute: expression being returned +}; + +class Print : Statement { + Print(); + ~Print(); + //attirbute: expression to be printed +}; + +class Jump : Statement { + Jump(); + Jump(char value); + ~Jump(); + void set_value(); + private: + char value; // values are CONT or BREAK +}; + +class IfElse : Statement { + IfElse(); + ~IfElse(); + //attributes: condition(expression), IfRest +}; + +class IfRest : Statement { + IfRest(); + ~IfRest(); + //atrributes: a block, or another IfElse +}; + +class While : Statement { + While(); + ~While(); + //attributes: condition, block +}; + +class Variable : Expression { + Variable(); + ~Variable(); +private: + char name; + var_type type; +}; + +class UnOp : Expression { + UnOp(); + ~UnOp(); +private: + un_op operation; + Expression expression; +}; + +class BinOp : Expression { + BinOp(); + ~BinOp(); +private: + bin_op operation; + Expression left_exp; + Expression right_exp; +}; + +class Boolean : Expression { + //not sure if this is necessary but putting + //it down for now + Boolean(); + ~Boolean(); +private: + bool value; +}; + #endif // MAINWINDOW_H From 9010f5b2c8e6c4c6626b996c36e9fd6508d54c1d Mon Sep 17 00:00:00 2001 From: milenanedeljkovic <80540793+milenanedeljkovic@users.noreply.github.com> Date: Tue, 9 Nov 2021 12:13:10 +0100 Subject: [PATCH 02/43] Update ast.hpp draft of classes, AGAIN --- Algorithm-visualizer/AST/ast.hpp | 139 +++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/Algorithm-visualizer/AST/ast.hpp b/Algorithm-visualizer/AST/ast.hpp index fbd6763..90e1cbf 100644 --- a/Algorithm-visualizer/AST/ast.hpp +++ b/Algorithm-visualizer/AST/ast.hpp @@ -26,4 +26,143 @@ class AST : public QAbstractItemModel private: }; +class Program { + Program(); + ~Program(); + //list of statements or the + //program block - not sure yet +}; + +class Block { + Block(); + ~Block(); + //list of statements +}; + +class Statement { + Statement(); + ~Statement(); +}; + +class Expression { + Expression(); + ~Expression(); +}; + +enum var_type { + string = 0, + integer = 1, + character = 2, + floating_point = 3 + +}; + +enum un_op { + negation = 0, + plusplus = 1 + //inverse = 2 (if we add this as a unary operation for number -> -number) +}; + +enum bin_op { + conjunction = 0, + disjunction = 1, + addition = 2, + subtraction = 3, + multiplication = 4, + division = 5, + lthan = 6, + mthan = 7, + leq = 8, + meq = 9, + eq = 10, + eqeq = 11 +}; + +class Declaration : Statement { + Declaration(); + ~Declaration(); + //int x = 7, bool y = False + //attributes: + //name + value of the variable or Variable + sth +}; + +class Assignment : Statement { + Assignment(); + ~Assignment(); + //x = 5; x = y +}; + +class Return : Statement { + Return(); + ~Return(); + //attribute: expression being returned +}; + +class Print : Statement { + Print(); + ~Print(); + //attirbute: expression to be printed +}; + +class Jump : Statement { + Jump(); + Jump(char value); + ~Jump(); + void set_value(); + private: + char value; // values are CONT or BREAK +}; + +class IfElse : Statement { + IfElse(); + ~IfElse(); + //attributes: condition(expression), IfRest +}; + +class IfRest : Statement { + IfRest(); + ~IfRest(); + //atrributes: a block, or another IfElse +}; + +class While : Statement { + While(); + ~While(); + //attributes: condition, block +}; + +class Variable : Expression { + Variable(); + ~Variable(); +private: + char name; + var_type type; +}; + +class UnOp : Expression { + UnOp(); + ~UnOp(); +private: + un_op operation; + Expression expression; +}; + +class BinOp : Expression { + BinOp(); + ~BinOp(); +private: + bin_op operation; + Expression left_exp; + Expression right_exp; +}; + +class Boolean : Expression { + //not sure if this is necessary but putting + //it down for now + Boolean(); + ~Boolean(); +private: + bool value; +}; + #endif // AST_H From 1b26506e4e235eedb562ef6bd756c4c621b69d61 Mon Sep 17 00:00:00 2001 From: elena-mrdja <91255937+elena-mrdja@users.noreply.github.com> Date: Sun, 14 Nov 2021 14:53:51 +0100 Subject: [PATCH 03/43] Delete Mina_Goranovic.txt --- Reports/Week 2/Mina_Goranovic.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Reports/Week 2/Mina_Goranovic.txt diff --git a/Reports/Week 2/Mina_Goranovic.txt b/Reports/Week 2/Mina_Goranovic.txt deleted file mode 100644 index 8b13789..0000000 --- a/Reports/Week 2/Mina_Goranovic.txt +++ /dev/null @@ -1 +0,0 @@ - From b0a12b227ae783b4895318e02ba5c2d891299513 Mon Sep 17 00:00:00 2001 From: elena-mrdja <91255937+elena-mrdja@users.noreply.github.com> Date: Sun, 14 Nov 2021 15:50:58 +0100 Subject: [PATCH 04/43] Create reports.md --- Reports/Week2/reports.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Reports/Week2/reports.md diff --git a/Reports/Week2/reports.md b/Reports/Week2/reports.md new file mode 100644 index 0000000..2166223 --- /dev/null +++ b/Reports/Week2/reports.md @@ -0,0 +1,40 @@ +# Week 2 - Reports + +#### Elena Mrdja +This week I worked on grasping all the necessary knowledge in Qt graphics we will need. As planned, I finished the Qt Graphics course we found, and I implemented the gathered skills through making a trial project where I created a main window with different shapes and their class methods, which will be of great help as I progress with coding the project. + +After everyone in GUI team was done with the course, I set up a meeting to decide on all the custom classes and the shape types we want to have in our project. When this was decided, I started coding the main window of our project's GUI, adding the classes and creating a simple structure we plan to build upon next week. Next week our goal is to finish the text editor cell and implement all the shapes we decided to use. + +As the git leader, I created a tutorial document with all of the important git hub commands, so that everyone was sure on how to use it, and was there to help my teammates out with any git hub problems. + + +#### Matea Gjika + +This week was dedicated to research. Since this is a complex project, where we need to build a parser and interpreter and learn about multiple libraries and complex data structures, it is very important for everyone to take some time to study and understand the main principles. I had 3 jobs this week: research a parses, research the antlr library, and research parser trees. + +The first resource I studied was a 19-part article “Let’s build an Interpreter”, which walks you through parsing, tokenising, grammars, parser trees and ASTs. I have completed 8/19 parts, so my goal is to finish this series by Tuesday. + +I also browsed the ANTLR documentation, and looked at some functions that specifically deal with parser trees. +The next step is to start building the AST classes and methods with the rest of my team. + +#### Elsa Bismuth + +This week, I deepened my knowledge in ANTLR and tokenization by doing some research on internet. I defined more in details the grammar and I started to code the first token. Next week, I will try to finish to code the first 2 tokens. + +#### Virgile Martin + +This week I worked on the implementation of tests to understand and verify that our library works. This also allows us to check the different functionalities of the library and what it returns. I created different tests of different complexity. The goal is to have the library 100% functional by the end of the week. + +#### Milena Nedeljkovic + +#### John Levy + +#### Evdokia Gneusheva + +#### Stefan Vayl + +#### Ekaterina Borisova + +#### Mina Goranovic + +#### Darya Zarkotova From 5f671198d7fec5800f3a2481caf89f2668f235b0 Mon Sep 17 00:00:00 2001 From: milenanedeljkovic <80540793+milenanedeljkovic@users.noreply.github.com> Date: Sun, 14 Nov 2021 15:59:05 +0100 Subject: [PATCH 05/43] Update ast.hpp beginning of AST class, updated classes from the last commit --- Algorithm-visualizer/AST/ast.hpp | 108 ++++++++++++++++++++++++------- 1 file changed, 85 insertions(+), 23 deletions(-) diff --git a/Algorithm-visualizer/AST/ast.hpp b/Algorithm-visualizer/AST/ast.hpp index 90e1cbf..cd949b9 100644 --- a/Algorithm-visualizer/AST/ast.hpp +++ b/Algorithm-visualizer/AST/ast.hpp @@ -26,29 +26,6 @@ class AST : public QAbstractItemModel private: }; -class Program { - Program(); - ~Program(); - //list of statements or the - //program block - not sure yet -}; - -class Block { - Block(); - ~Block(); - //list of statements -}; - -class Statement { - Statement(); - ~Statement(); -}; - -class Expression { - Expression(); - ~Expression(); -}; - enum var_type { string = 0, integer = 1, @@ -78,6 +55,79 @@ enum bin_op { eqeq = 11 }; +//AST CLASS + +class AST { + AST(); + ~AST(); +private: + AST* left_child; + AST* right_child; + AST* parent; +}; + +class NodeBinOp(AST) { + NodeBinOp(); + ~NodeBinOp(); +private: + bin_op operation; +}; + +class NodeUnOp(AST) { + NodeUnOp(); + ~NodeUnOp(); +private: + un_op operation; +}; + +class NodeVar(AST) { + NodeVar(); + ~NodeVar(); +private: + var_type type; + char var_name; +}; + +class NodeIf(AST) { + NodeIf(); + ~NodeIf(); +private: + AST condition; +}; + +class NodeIf(AST) { + NodeIf(); + ~NodeIf(); +private: + AST condition; +}; + + +//THESE WILL BE POTENTIALLY USEFUL FOR CLASSIFYING THINGS WHILE READING THE AST + +class Program { + Program(); + ~Program(); + //list of statements or the + //program block - not sure yet +}; + +class Block { + Block(); + ~Block(); + //list of statements +}; + +class Statement { + Statement(); + ~Statement(); +}; + +class Expression { + Expression(); + ~Expression(); +}; + class Declaration : Statement { Declaration(); ~Declaration(); @@ -96,12 +146,16 @@ class Return : Statement { Return(); ~Return(); //attribute: expression being returned +private: + Expression exp; }; class Print : Statement { Print(); ~Print(); //attirbute: expression to be printed +private: + Expression exp; }; class Jump : Statement { @@ -117,18 +171,26 @@ class IfElse : Statement { IfElse(); ~IfElse(); //attributes: condition(expression), IfRest +private: + Expression condition; + IfRest else_stmt; }; class IfRest : Statement { IfRest(); ~IfRest(); //atrributes: a block, or another IfElse +private: + Block block_stmt; }; class While : Statement { While(); ~While(); //attributes: condition, block +private: + Expression condition; + Block block_stmt; }; class Variable : Expression { From 8e12fc0f687067790b22c98161e629aed0280e13 Mon Sep 17 00:00:00 2001 From: mattea777 Date: Sun, 14 Nov 2021 16:41:15 +0100 Subject: [PATCH 06/43] Setters and Getters of classes Wrote setters and Getters for all classes inheriting from Statement. --- Algorithm-visualizer/AST/ast.hpp | 43 ++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/Algorithm-visualizer/AST/ast.hpp b/Algorithm-visualizer/AST/ast.hpp index cd949b9..0a7840e 100644 --- a/Algorithm-visualizer/AST/ast.hpp +++ b/Algorithm-visualizer/AST/ast.hpp @@ -129,22 +129,43 @@ class Expression { }; class Declaration : Statement { +public: Declaration(); ~Declaration(); + void set_var_type(var_type t){type = t;}; + var_type get_var_type(){return type}; + char get_value(){return value;}; + void set_value(char v){value = v;}; + + +private: + var_type type; + char value; //int x = 7, bool y = False //attributes: //name + value of the variable or Variable + sth }; class Assignment : Statement { + public: Assignment(); ~Assignment(); + char get_value(){return value;}; + void set_value(char v){value= v;} + char get_name(){return name;}; + void set_name(char n){name= n;} + //x = 5; x = y +private: + char name; + char value; }; class Return : Statement { Return(); ~Return(); + void set_exp(Expression e){exp = e;}; + Experssion get_exp(){return exp;}; //attribute: expression being returned private: Expression exp; @@ -153,17 +174,22 @@ class Return : Statement { class Print : Statement { Print(); ~Print(); + void set_exp(Expression e){exp = e;}; + Experssion get_exp(){return exp;}; //attirbute: expression to be printed private: Expression exp; }; class Jump : Statement { +public: Jump(); Jump(char value); ~Jump(); - void set_value(); - private: + void set_value(char v){value = v;}; + char get_value(){return value;}; + +private: char value; // values are CONT or BREAK }; @@ -171,22 +197,35 @@ class IfElse : Statement { IfElse(); ~IfElse(); //attributes: condition(expression), IfRest + void set_condition(Expression c){condition = c;}; + Expression get_condition(){return condition;}; + void set_else_stmt(IfRest stmt){else_stmt = stmt;}; + IfRest get_else_stmt(){return else_stmt;}; private: Expression condition; IfRest else_stmt; }; class IfRest : Statement { +public: IfRest(); ~IfRest(); + Block get_block_stmt(){return block_stmt;}; + void set_block_stmt(Block stmt){block_stmt = stmt;}; //atrributes: a block, or another IfElse private: Block block_stmt; }; class While : Statement { +public: While(); ~While(); + void set_condition(Expression c){condition = c;}; + Expression get_condition(){return condition;}; + Block get_block_stmt(){return block_stmt;}; + void set_block_stmt(Block stmt){block_stmt = stmt;}; + //attributes: condition, block private: Expression condition; From 67b7d56b86e75a098e1510b1eeb3eac671d2370c Mon Sep 17 00:00:00 2001 From: Evdokia Gneusheva Date: Sun, 14 Nov 2021 16:58:08 +0100 Subject: [PATCH 07/43] adding get() and set() to Expression in ast.hpp I added methods get() and set() to every class inherited from Expression in ast.hpp file --- .vscode/c_cpp_properties.json | 19 +++++++++++++++++++ Algorithm-visualizer/AST/ast.hpp | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 .vscode/c_cpp_properties.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..b6501eb --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,19 @@ +{ + "configurations": [ + { + "name": "Mac", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "macFrameworkPath": [ + "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks" + ], + "compilerPath": "/usr/bin/clang", + "cStandard": "c17", + "cppStandard": "c++98", + "intelliSenseMode": "macos-clang-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/Algorithm-visualizer/AST/ast.hpp b/Algorithm-visualizer/AST/ast.hpp index cd949b9..2d81cfb 100644 --- a/Algorithm-visualizer/AST/ast.hpp +++ b/Algorithm-visualizer/AST/ast.hpp @@ -196,6 +196,11 @@ class While : Statement { class Variable : Expression { Variable(); ~Variable(); + void set_name(char n){name = n;}; + void set_type(var_type t){type = t;}; + char get_name(){return name;}; + var_type get_type(){return type;}; + private: char name; var_type type; @@ -204,6 +209,10 @@ class Variable : Expression { class UnOp : Expression { UnOp(); ~UnOp(); + void set_operation(un_op op){operation = op;}; + void set_expression(Expression e){expression = e;}; + un_op get_operation(){return operation;}; + Expression get_expression(){return expression;}; private: un_op operation; Expression expression; @@ -212,6 +221,12 @@ class UnOp : Expression { class BinOp : Expression { BinOp(); ~BinOp(); + void set_operation(bin_op op){operation = op;}; + void set_left_expression(Expression l_e){left_exp = l_e;}; + void set_right_expression(Expression r_e){right_exp = r_e;}; + bin_op get_operation(){return operation;}; + Expression get_right_expression(){return left_exp;}; + Expression get_left_expression(){return right_exp;}; private: bin_op operation; Expression left_exp; @@ -223,6 +238,8 @@ class Boolean : Expression { //it down for now Boolean(); ~Boolean(); + void set_value(bool v){value = v;}; + bool get_value(){return value;}; private: bool value; }; From 7ce43d47fdac38216acd70dc28a5a90618ee2416 Mon Sep 17 00:00:00 2001 From: Evdokia Gneusheva Date: Sun, 14 Nov 2021 17:02:32 +0100 Subject: [PATCH 08/43] I fixed one synax error in get() method of bin_Op class --- Algorithm-visualizer/AST/ast.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Algorithm-visualizer/AST/ast.hpp b/Algorithm-visualizer/AST/ast.hpp index d809a56..4025b48 100644 --- a/Algorithm-visualizer/AST/ast.hpp +++ b/Algorithm-visualizer/AST/ast.hpp @@ -264,8 +264,8 @@ class BinOp : Expression { void set_left_expression(Expression l_e){left_exp = l_e;}; void set_right_expression(Expression r_e){right_exp = r_e;}; bin_op get_operation(){return operation;}; - Expression get_right_expression(){return left_exp;}; - Expression get_left_expression(){return right_exp;}; + Expression get_left_expression(){return left_exp;}; + Expression get_right_expression(){return right_exp;}; private: bin_op operation; Expression left_exp; From 0394403b577f095aeaa82caf83ff6c672fe18b80 Mon Sep 17 00:00:00 2001 From: elena-mrdja <91255937+elena-mrdja@users.noreply.github.com> Date: Sun, 14 Nov 2021 17:10:48 +0100 Subject: [PATCH 09/43] Added custom classes and mainwindow --- Algorithm-visualizer/Algorithm-visualizer.pro | 6 ++ Algorithm-visualizer/GUI/codecell.cpp | 6 ++ Algorithm-visualizer/GUI/codecell.h | 16 +++++ Algorithm-visualizer/GUI/varcell.cpp | 6 ++ Algorithm-visualizer/GUI/varcell.h | 11 +++ Algorithm-visualizer/GUI/viewer.cpp | 6 ++ Algorithm-visualizer/GUI/viewer.h | 16 +++++ Algorithm-visualizer/mainwindow.ui | 69 +++++++++++++++++-- 8 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 Algorithm-visualizer/GUI/codecell.cpp create mode 100644 Algorithm-visualizer/GUI/codecell.h create mode 100644 Algorithm-visualizer/GUI/varcell.cpp create mode 100644 Algorithm-visualizer/GUI/varcell.h create mode 100644 Algorithm-visualizer/GUI/viewer.cpp create mode 100644 Algorithm-visualizer/GUI/viewer.h diff --git a/Algorithm-visualizer/Algorithm-visualizer.pro b/Algorithm-visualizer/Algorithm-visualizer.pro index b0b1b11..46d4090 100644 --- a/Algorithm-visualizer/Algorithm-visualizer.pro +++ b/Algorithm-visualizer/Algorithm-visualizer.pro @@ -10,14 +10,20 @@ CONFIG += c++11 SOURCES += \ AST/ast.cpp \ + GUI/codecell.cpp \ GUI/gui.cpp \ + GUI/varcell.cpp \ + GUI/viewer.cpp \ Parsing/parsing.cpp \ main.cpp \ mainwindow.cpp HEADERS += \ AST/ast.hpp \ + GUI/codecell.h \ GUI/gui.hpp \ + GUI/varcell.h \ + GUI/viewer.h \ Parsing/parsing.hpp \ mainwindow.h diff --git a/Algorithm-visualizer/GUI/codecell.cpp b/Algorithm-visualizer/GUI/codecell.cpp new file mode 100644 index 0000000..583709b --- /dev/null +++ b/Algorithm-visualizer/GUI/codecell.cpp @@ -0,0 +1,6 @@ +#include "codecell.h" + +CodeCell::CodeCell(QWidget *parent) : QWidget(parent) +{ + +} diff --git a/Algorithm-visualizer/GUI/codecell.h b/Algorithm-visualizer/GUI/codecell.h new file mode 100644 index 0000000..6f8c8ec --- /dev/null +++ b/Algorithm-visualizer/GUI/codecell.h @@ -0,0 +1,16 @@ +#ifndef CODECELL_H +#define CODECELL_H + +#include + +class CodeCell : public QWidget +{ + Q_OBJECT +public: + explicit CodeCell(QWidget *parent = nullptr); + +signals: + +}; + +#endif // CODECELL_H diff --git a/Algorithm-visualizer/GUI/varcell.cpp b/Algorithm-visualizer/GUI/varcell.cpp new file mode 100644 index 0000000..4405212 --- /dev/null +++ b/Algorithm-visualizer/GUI/varcell.cpp @@ -0,0 +1,6 @@ +#include "varcell.h" + +VarCell::VarCell() +{ + +} diff --git a/Algorithm-visualizer/GUI/varcell.h b/Algorithm-visualizer/GUI/varcell.h new file mode 100644 index 0000000..0b691ef --- /dev/null +++ b/Algorithm-visualizer/GUI/varcell.h @@ -0,0 +1,11 @@ +#ifndef VARCELL_H +#define VARCELL_H + + +class VarCell +{ +public: + VarCell(); +}; + +#endif // VARCELL_H diff --git a/Algorithm-visualizer/GUI/viewer.cpp b/Algorithm-visualizer/GUI/viewer.cpp new file mode 100644 index 0000000..773ff00 --- /dev/null +++ b/Algorithm-visualizer/GUI/viewer.cpp @@ -0,0 +1,6 @@ +#include "viewer.h" + +Viewer::Viewer(QWidget *parent) : QWidget(parent) +{ + +} diff --git a/Algorithm-visualizer/GUI/viewer.h b/Algorithm-visualizer/GUI/viewer.h new file mode 100644 index 0000000..f953c2b --- /dev/null +++ b/Algorithm-visualizer/GUI/viewer.h @@ -0,0 +1,16 @@ +#ifndef VIEWER_H +#define VIEWER_H + +#include + +class Viewer : public QWidget +{ + Q_OBJECT +public: + explicit Viewer(QWidget *parent = nullptr); + +signals: + +}; + +#endif // VIEWER_H diff --git a/Algorithm-visualizer/mainwindow.ui b/Algorithm-visualizer/mainwindow.ui index b232854..6328253 100644 --- a/Algorithm-visualizer/mainwindow.ui +++ b/Algorithm-visualizer/mainwindow.ui @@ -6,17 +6,78 @@ 0 0 - 800 - 600 + 825 + 604 MainWindow - - + + + + + 30 + 40 + 771 + 491 + + + + + + + + + + + + + + + + Visualize + + + + + + + + + + + + + 0 + 0 + 825 + 26 + + + + + + CodeCell + QWidget +
codecell.h
+ 1 +
+ + Viewer + QWidget +
viewer.h
+ 1 +
+ + VarCell + QWidget +
varcell.h
+ 1 +
+
From bcedd85fe17980f0a064c196bbd7c59d921436aa Mon Sep 17 00:00:00 2001 From: darya-todoskova Date: Sun, 14 Nov 2021 18:01:09 +0100 Subject: [PATCH 10/43] Setters and getters of AST classes. + correction of few typos found --- Algorithm-visualizer/AST/ast.hpp | 34 ++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/Algorithm-visualizer/AST/ast.hpp b/Algorithm-visualizer/AST/ast.hpp index 4025b48..499c800 100644 --- a/Algorithm-visualizer/AST/ast.hpp +++ b/Algorithm-visualizer/AST/ast.hpp @@ -60,6 +60,12 @@ enum bin_op { class AST { AST(); ~AST(); + void set_left_child(AST* lc){left_child = lc;}; + AST* get_left_child(){return left_child;}; + void set_right_child(AST* rc){right_child = rc;}; + AST* get_right_child(){return right_child;}; + void set_parent(AST* par){parent = par;}; + AST* get_parent(){return parent;}; private: AST* left_child; AST* right_child; @@ -69,6 +75,8 @@ class AST { class NodeBinOp(AST) { NodeBinOp(); ~NodeBinOp(); + void set_bin_op(bin_op op){operation = op}; + bin_op get_bin_op(){return operation;}; private: bin_op operation; }; @@ -76,6 +84,8 @@ class NodeBinOp(AST) { class NodeUnOp(AST) { NodeUnOp(); ~NodeUnOp(); + void set_un_op(un_op op){operation = op;}; + un_op get_un_op(){return operation;}; private: un_op operation; }; @@ -83,6 +93,10 @@ class NodeUnOp(AST) { class NodeVar(AST) { NodeVar(); ~NodeVar(); + void set_var_type(var_type vt){type = vt;}; + var_type get_var_type(return type;); + void set_var_name(char vn){var_name = vn;}; + char get_var_name(){return var_name;}; private: var_type type; char var_name; @@ -91,17 +105,11 @@ class NodeVar(AST) { class NodeIf(AST) { NodeIf(); ~NodeIf(); + void set_condition(AST a){condition = a;}; + AST get_condition(){return condition;}; private: AST condition; }; - -class NodeIf(AST) { - NodeIf(); - ~NodeIf(); -private: - AST condition; -}; - //THESE WILL BE POTENTIALLY USEFUL FOR CLASSIFYING THINGS WHILE READING THE AST @@ -124,8 +132,8 @@ class Statement { }; class Expression { - Expression(); - ~Expression(); + Expression(); + ~Expression(); }; class Declaration : Statement { @@ -165,7 +173,7 @@ class Return : Statement { Return(); ~Return(); void set_exp(Expression e){exp = e;}; - Experssion get_exp(){return exp;}; + Expression get_exp(){return exp;}; //attribute: expression being returned private: Expression exp; @@ -175,8 +183,8 @@ class Print : Statement { Print(); ~Print(); void set_exp(Expression e){exp = e;}; - Experssion get_exp(){return exp;}; - //attirbute: expression to be printed + Expression get_exp(){return exp;}; + //attribute: expression to be printed private: Expression exp; }; From 9a067668da3e139cee30b8a6a559154000547c09 Mon Sep 17 00:00:00 2001 From: mattea777 Date: Mon, 15 Nov 2021 13:25:05 +0100 Subject: [PATCH 11/43] Practice writing interpreter I followed the tutorial by Ruslan Spivak "Let's Build a Tutorial". The tutorial is given in Python, so I have been working on converting the code to C++. This is not a completely debugged version in C++, but the Python code works. Although this is not directly relevant to the project, this helped me understand parsing, tokenizing and lexical analysis, which will be useful towards the completion of the rest of the project. --- .../Interpreter practice/calc1.cpp | 97 +++++++++++ .../Interpreter practice/calc1.hpp | 85 ++++++++++ .../Interpreter practice/calc1.py | 86 ++++++++++ .../Interpreter practice/calc2.py | 155 ++++++++++++++++++ 4 files changed, 423 insertions(+) create mode 100644 Algorithm-visualizer/Interpreter practice/calc1.cpp create mode 100644 Algorithm-visualizer/Interpreter practice/calc1.hpp create mode 100644 Algorithm-visualizer/Interpreter practice/calc1.py create mode 100644 Algorithm-visualizer/Interpreter practice/calc2.py diff --git a/Algorithm-visualizer/Interpreter practice/calc1.cpp b/Algorithm-visualizer/Interpreter practice/calc1.cpp new file mode 100644 index 0000000..80a30ba --- /dev/null +++ b/Algorithm-visualizer/Interpreter practice/calc1.cpp @@ -0,0 +1,97 @@ + +#include +#include +#include +#include + +char* INTEGER = "INTEGER"; +char* PLUS = "PLUS"; +char* eof = "EOF"; + +class Token{ +public: + Token(char* t, int v){type = t; value = v;}; + Token(){}; + Token(char* t){type = t;}; + char* get_type(){return type;}; + int get_value(){ + if (type != "PLUS"){ + return int(value); + } + }; + + + +private: + char* type; + int value; + + +}; + +class Interpreter{ +public: + Interpreter(char* t){text = t;}; + void error(){ + throw std::invalid_argument( "wrong format" ); + + } + Token get_next_token(){ + int len = 0; + int i = 0; + while (text[i] != '\n'){ + len ++; + i++; + } + if (pos > len - 1){ + return Token(eof); + } + if (isdigit(text[pos])){ + return Token(INTEGER, int(text[pos])); + } + if (text[pos] == 43){ + return Token(PLUS, text[pos]); + } + + error(); + } + + void eat(char* type){ + if (current_token.get_type() == type){ + current_token = (*this).get_next_token(); + } + else{ + error(); + } + } + + int expr(){ + current_token = (*this).get_next_token(); + Token left = current_token; + (*this).eat(INTEGER); + Token op = current_token; + (*this).eat(PLUS); + Token right = current_token; + (*this).eat(INTEGER); + return left.get_value() + right.get_value(); + + } + + + + +private: + char* text; + int pos = 0; + Token current_token; +}; + + +int main(){ + char* text; + std::cin>>text; + Interpreter interpreter = Interpreter(text); + interpreter.expr(); + return 0; + +} \ No newline at end of file diff --git a/Algorithm-visualizer/Interpreter practice/calc1.hpp b/Algorithm-visualizer/Interpreter practice/calc1.hpp new file mode 100644 index 0000000..cdd4e28 --- /dev/null +++ b/Algorithm-visualizer/Interpreter practice/calc1.hpp @@ -0,0 +1,85 @@ +#include +#include +#include + +char* INTEGER = "INTEGER"; +char* PLUS = "PLUS"; +char* eof = "EOF"; + +class Token{ +public: + Token(char* t, int v){type = t; value = v;}; + Token(){}; + Token(char* t){type = t;}; + char* get_type(){return type;}; + int get_value(){ + if (type != "PLUS"){ + return int(value); + } + }; + + + +private: + char* type; + int value; + + +}; + +class Interpreter{ +public: + Interpreter(char* t){text = t;}; + void error(){ + throw std::invalid_argument( "wrong format" ); + + } + Token get_next_token(){ + int len = 0; + int i = 0; + while (text[i] != '\n'){ + len ++; + i++; + } + if (pos > len - 1){ + return Token(eof); + } + if (isdigit(text[pos])){ + return Token(INTEGER, int(text[pos])); + } + if (text[pos] == 43){ + return Token(PLUS, text[pos]); + } + + error(); + } + + void eat(char* type){ + if (current_token.get_type() == type){ + current_token = (*this).get_next_token(); + } + else{ + error(); + } + } + + int expr(){ + current_token = (*this).get_next_token(); + Token left = current_token; + (*this).eat(INTEGER); + Token op = current_token; + (*this).eat(PLUS); + Token right = current_token; + (*this).eat(INTEGER); + return left.get_value() + right.get_value(); + + } + + + + +private: + char* text; + int pos = 0; + Token current_token; +}; \ No newline at end of file diff --git a/Algorithm-visualizer/Interpreter practice/calc1.py b/Algorithm-visualizer/Interpreter practice/calc1.py new file mode 100644 index 0000000..b745ec6 --- /dev/null +++ b/Algorithm-visualizer/Interpreter practice/calc1.py @@ -0,0 +1,86 @@ +INTEGER, MINUS, EOF = 'INTEGER', 'MINUS', 'EOF' + +class Token(object): + def __init__(self, type, value): + self.type = type + self.value = value + + def __str__(self): + return 'Token({type}, {value})'.format( + type=self.type, + value=repr(self.value) + ) + + def __repr__(self): + return self.__str__() + + + +class Interpreter(object): + def __init__(self, text): + self.text = text + self.pos = 0 + self.current_token = None + + def error(self): + raise Exception('Parsing error') + + + def get_next_token(self): + text = self.text + if self.pos > len(self.text) -1: + return Token(EOF, None) + while self.pos ') + except EOFError: + break + if not text: + continue + interpreter = Interpreter(text) + result = interpreter.expr() + print(result) + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/Algorithm-visualizer/Interpreter practice/calc2.py b/Algorithm-visualizer/Interpreter practice/calc2.py new file mode 100644 index 0000000..1dc7552 --- /dev/null +++ b/Algorithm-visualizer/Interpreter practice/calc2.py @@ -0,0 +1,155 @@ + +# Token types +# EOF (end-of-file) token is used to indicate that +# there is no more input left for lexical analysis +INTEGER, PLUS, MINUS, EOF = 'INTEGER', 'PLUS', 'MINUS', 'EOF' + + +class Token(object): + def __init__(self, type, value): + # token type: INTEGER, PLUS, MINUS, or EOF + self.type = type + # token value: non-negative integer value, '+', '-', or None + self.value = value + + def __str__(self): + """String representation of the class instance. + + Examples: + Token(INTEGER, 3) + Token(PLUS '+') + """ + return 'Token({type}, {value})'.format( + type=self.type, + value=repr(self.value) + ) + + def __repr__(self): + return self.__str__() + + +class Interpreter(object): + def __init__(self, text): + # client string input, e.g. "3 + 5", "12 - 5", etc + self.text = text + # self.pos is an index into self.text + self.pos = 0 + # current token instance + self.current_token = None + self.current_char = self.text[self.pos] + + def error(self): + raise Exception('Error parsing input') + + def advance(self): + """Advance the 'pos' pointer and set the 'current_char' variable.""" + self.pos += 1 + if self.pos > len(self.text) - 1: + self.current_char = None # Indicates end of input + else: + self.current_char = self.text[self.pos] + + def skip_whitespace(self): + while self.current_char is not None and self.current_char.isspace(): + self.advance() + + def integer(self): + """Return a (multidigit) integer consumed from the input.""" + result = '' + while self.current_char is not None and self.current_char.isdigit(): + result += self.current_char + self.advance() + return int(result) + + def get_next_token(self): + """Lexical analyzer (also known as scanner or tokenizer) + + This method is responsible for breaking a sentence + apart into tokens. + """ + while self.current_char is not None: + + if self.current_char.isspace(): + self.skip_whitespace() + continue + + if self.current_char.isdigit(): + return Token(INTEGER, self.integer()) + + if self.current_char == '+': + self.advance() + return Token(PLUS, '+') + + if self.current_char == '-': + self.advance() + return Token(MINUS, '-') + + self.error() + + return Token(EOF, None) + + def eat(self, token_type): + # compare the current token type with the passed token + # type and if they match then "eat" the current token + # and assign the next token to the self.current_token, + # otherwise raise an exception. + if self.current_token.type == token_type: + self.current_token = self.get_next_token() + else: + self.error() + + def expr(self): + """Parser / Interpreter + + expr -> INTEGER PLUS INTEGER + expr -> INTEGER MINUS INTEGER + """ + # set current token to the first token taken from the input + self.current_token = self.get_next_token() + + # we expect the current token to be an integer + left = self.current_token + self.eat(INTEGER) + + # we expect the current token to be either a '+' or '-' + op = self.current_token + if op.type == PLUS: + self.eat(PLUS) + else: + self.eat(MINUS) + + # we expect the current token to be an integer + right = self.current_token + self.eat(INTEGER) + # after the above call the self.current_token is set to + # EOF token + + # at this point either the INTEGER PLUS INTEGER or + # the INTEGER MINUS INTEGER sequence of tokens + # has been successfully found and the method can just + # return the result of adding or subtracting two integers, + # thus effectively interpreting client input + if op.type == PLUS: + result = left.value + right.value + else: + result = left.value - right.value + return result + + +def main(): + while True: + try: + # To run under Python3 replace 'raw_input' call + # with 'input' + text = raw_input('calc> ') + except EOFError: + break + if not text: + continue + interpreter = Interpreter(text) + result = interpreter.expr() + print(result) + + +if __name__ == '__main__': + main() \ No newline at end of file From 2da4b255940b8f9a7c91738e9959ee97bcc10d4e Mon Sep 17 00:00:00 2001 From: milenanedeljkovic <80540793+milenanedeljkovic@users.noreply.github.com> Date: Mon, 15 Nov 2021 13:28:07 +0100 Subject: [PATCH 12/43] Update ast.hpp --- Algorithm-visualizer/AST/ast.hpp | 63 +++++++++++++++----------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/Algorithm-visualizer/AST/ast.hpp b/Algorithm-visualizer/AST/ast.hpp index 499c800..adf0c29 100644 --- a/Algorithm-visualizer/AST/ast.hpp +++ b/Algorithm-visualizer/AST/ast.hpp @@ -55,12 +55,19 @@ enum bin_op { eqeq = 11 }; +enum jump_type { + jump = 0, + continue = 1 +}; + //AST CLASS class AST { AST(); ~AST(); - void set_left_child(AST* lc){left_child = lc;}; + +//this whole rest of the class will probably be deleted +/* void set_left_child(AST* lc){left_child = lc;}; AST* get_left_child(){return left_child;}; void set_right_child(AST* rc){right_child = rc;}; AST* get_right_child(){return right_child;}; @@ -69,9 +76,10 @@ class AST { private: AST* left_child; AST* right_child; - AST* parent; + AST* parent; */ }; +/* class NodeBinOp(AST) { NodeBinOp(); ~NodeBinOp(); @@ -109,32 +117,24 @@ class NodeIf(AST) { AST get_condition(){return condition;}; private: AST condition; -}; +}; */ -//THESE WILL BE POTENTIALLY USEFUL FOR CLASSIFYING THINGS WHILE READING THE AST +class Statement (AST) { + Statement(); + ~Statement(); +}; -class Program { - Program(); - ~Program(); - //list of statements or the - //program block - not sure yet +class Expression (AST) { + Expression(); + ~Expression(); }; -class Block { +class Block : Statement { Block(); ~Block(); //list of statements }; -class Statement { - Statement(); - ~Statement(); -}; - -class Expression { - Expression(); - ~Expression(); -}; class Declaration : Statement { public: @@ -158,15 +158,14 @@ class Assignment : Statement { public: Assignment(); ~Assignment(); - char get_value(){return value;}; - void set_value(char v){value= v;} - char get_name(){return name;}; - void set_name(char n){name= n;} - + Expression get_value(){return value;}; + void set_value(Expression v){value= v;} + string get_name(){return name;}; + void set_name(string n){name= n;} //x = 5; x = y private: - char name; - char value; + string name; + Expression value; }; class Return : Statement { @@ -174,7 +173,6 @@ class Return : Statement { ~Return(); void set_exp(Expression e){exp = e;}; Expression get_exp(){return exp;}; - //attribute: expression being returned private: Expression exp; }; @@ -195,10 +193,9 @@ class Jump : Statement { Jump(char value); ~Jump(); void set_value(char v){value = v;}; - char get_value(){return value;}; - + jump_type get_value(){return value;}; private: - char value; // values are CONT or BREAK + jump_type value; // values are CONT or BREAK }; class IfElse : Statement { @@ -245,11 +242,11 @@ class Variable : Expression { ~Variable(); void set_name(char n){name = n;}; void set_type(var_type t){type = t;}; - char get_name(){return name;}; + string get_name(){return name;}; var_type get_type(){return type;}; private: - char name; + string name; var_type type; }; @@ -286,7 +283,7 @@ class Boolean : Expression { Boolean(); ~Boolean(); void set_value(bool v){value = v;}; - bool get_value(){return value;}; + bool is_true(){return value;}; private: bool value; }; From 01c8aa02b91bf6641a5217576cb0213f96454d45 Mon Sep 17 00:00:00 2001 From: mattea777 Date: Mon, 15 Nov 2021 14:38:52 +0100 Subject: [PATCH 13/43] Added cache to AST and Block I added a cache to store the changes in variables. I created constructors where the cache is passed by reference so different blocks and operations all modify one cache. --- .vscode/settings.json | 66 ++++++++++++++++++++++++++++++++ Algorithm-visualizer/AST/ast.hpp | 22 +++++++++++ 2 files changed, 88 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..69ffce4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,66 @@ +{ + "files.associations": { + "__bit_reference": "cpp", + "__config": "cpp", + "__debug": "cpp", + "__errc": "cpp", + "__functional_base": "cpp", + "__hash_table": "cpp", + "__locale": "cpp", + "__mutex_base": "cpp", + "__node_handle": "cpp", + "__nullptr": "cpp", + "__split_buffer": "cpp", + "__string": "cpp", + "__threading_support": "cpp", + "__tree": "cpp", + "__tuple": "cpp", + "algorithm": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "cmath": "cpp", + "complex": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "exception": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "iterator": "cpp", + "limits": "cpp", + "locale": "cpp", + "map": "cpp", + "memory": "cpp", + "mutex": "cpp", + "new": "cpp", + "optional": "cpp", + "ostream": "cpp", + "ratio": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "utility": "cpp", + "vector": "cpp" + } +} \ No newline at end of file diff --git a/Algorithm-visualizer/AST/ast.hpp b/Algorithm-visualizer/AST/ast.hpp index adf0c29..7090b79 100644 --- a/Algorithm-visualizer/AST/ast.hpp +++ b/Algorithm-visualizer/AST/ast.hpp @@ -1,3 +1,5 @@ +#include +#include #ifndef AST_H #define AST_H @@ -63,8 +65,17 @@ enum jump_type { //AST CLASS class AST { +// mattea777: The AST class will contain a cache in the form of a dictionary that will keep track of all the changes to the +// variables during the various blocks. As each block may contain sub-blocks, but they still need information from the same dictionary, +// the cache will be passed by reference to sub-blocks. The cache will be passed by reference to every operation that involves +// changing the value of the variables, so Block, Declaration, Assignment, UnOp, and potentially expression. Constructors with a cache argument will +// be added to the classes by Milena. +public: AST(); + AST() ~AST(); +private: + std::map cache = {}; //this whole rest of the class will probably be deleted /* void set_left_child(AST* lc){left_child = lc;}; @@ -130,13 +141,22 @@ class Expression (AST) { }; class Block : Statement { + +public: Block(); + Block(std::map* c){cache = c;}; ~Block(); //list of statements +private: +// dictionary var_name, values[] +// Based on Dasha's changes, I need to verify the type of the array of stored values + std::map cache = {}; + }; class Declaration : Statement { +// Write method to add new varibale to cache of Block public: Declaration(); ~Declaration(); @@ -155,6 +175,7 @@ class Declaration : Statement { }; class Assignment : Statement { +// Write method to add new varibale to cache of Block public: Assignment(); ~Assignment(); @@ -251,6 +272,7 @@ class Variable : Expression { }; class UnOp : Expression { +// Write method to add new varibale to cache of Block UnOp(); ~UnOp(); void set_operation(un_op op){operation = op;}; From 4128555cd2e1418663891493f523e5d9dd27100d Mon Sep 17 00:00:00 2001 From: darya-todoskova Date: Mon, 15 Nov 2021 17:59:35 +0100 Subject: [PATCH 14/43] Update ast.hpp --- Algorithm-visualizer/AST/ast.hpp | 313 +++++++++++++++++++++++++++++++ 1 file changed, 313 insertions(+) diff --git a/Algorithm-visualizer/AST/ast.hpp b/Algorithm-visualizer/AST/ast.hpp index fbd6763..b8fb0cf 100644 --- a/Algorithm-visualizer/AST/ast.hpp +++ b/Algorithm-visualizer/AST/ast.hpp @@ -26,4 +26,317 @@ class AST : public QAbstractItemModel private: }; +<<<<<<< Updated upstream +======= +enum var_type { + string = 0, + integer = 1, + character = 2, + floating_point = 3 +}; + +enum un_op { + negation = 0, + plusplus = 1 + //inverse = 2 (if we add this as a unary operation for number -> -number) +}; + +enum bin_op { + conjunction = 0, + disjunction = 1, + addition = 2, + subtraction = 3, + multiplication = 4, + division = 5, + lthan = 6, + mthan = 7, + leq = 8, + meq = 9, + eq = 10, + eqeq = 11 +}; + +enum jump_type { + jump = 0, + continue = 1 +}; + +//AST CLASS + +class AST { + AST(); + ~AST(); + +//this whole rest of the class will probably be deleted +/* void set_left_child(AST* lc){left_child = lc;}; + AST* get_left_child(){return left_child;}; + void set_right_child(AST* rc){right_child = rc;}; + AST* get_right_child(){return right_child;}; + void set_parent(AST* par){parent = par;}; + AST* get_parent(){return parent;}; +private: + AST* left_child; + AST* right_child; + AST* parent; */ +}; + +/* +class NodeBinOp(AST) { + NodeBinOp(); + ~NodeBinOp(); + void set_bin_op(bin_op op){operation = op}; + bin_op get_bin_op(){return operation;}; +private: + bin_op operation; +}; + +class NodeUnOp(AST) { + NodeUnOp(); + ~NodeUnOp(); + void set_un_op(un_op op){operation = op;}; + un_op get_un_op(){return operation;}; +private: + un_op operation; +}; + +class NodeVar(AST) { + NodeVar(); + ~NodeVar(); + void set_var_type(var_type vt){type = vt;}; + var_type get_var_type(return type;); + void set_var_name(char vn){var_name = vn;}; + char get_var_name(){return var_name;}; +private: + var_type type; + char var_name; +}; + +class NodeIf(AST) { + NodeIf(); + ~NodeIf(); + void set_condition(AST a){condition = a;}; + AST get_condition(){return condition;}; +private: + AST condition; +}; */ + +class Statement (AST) { + Statement(); + ~Statement(); +}; + +class Expression (AST) { + Expression(); + ~Expression(); +}; + +class Block : Statement { + Block(); + ~Block(); + //list of statements +}; + + +class Declaration : Statement { +public: + Declaration(); + ~Declaration(); + void set_var_type(var_type t){type = t;}; + var_type get_var_type(){ + if type == 0: + return "string"; + elif type == 1: + return "integer"; + elif type == 2: + return "character"; + elif type == 3: + return "floating_point"; + }; + char get_value(){return value;}; + void set_value(char v){value = v;}; +private: + var_type type; + char value; + //int x = 7, bool y = False + //attributes: + //name + value of the variable or Variable + sth +}; + +class Assignment : Statement { + public: + Assignment(); + ~Assignment(); + Expression get_value(){return value;}; + void set_value(Expression v){value= v;} + string get_name(){return name;}; + void set_name(string n){name= n;} + //x = 5; x = y +private: + string name; + Expression value; +}; + +class Return : Statement { + Return(); + ~Return(); + void set_exp(Expression e){exp = e;}; + Expression get_exp(){return exp;}; +private: + Expression exp; +}; + +class Print : Statement { + Print(); + ~Print(); + void set_exp(Expression e){exp = e;}; + Expression get_exp(){return exp;}; + //attribute: expression to be printed +private: + Expression exp; +}; + +class Jump : Statement { +public: + Jump(); + Jump(char value); + ~Jump(); + void set_value(char v){value = v;}; + jump_type get_value(){ + if value == 0: + return "jump"; + elif value == 1: + return "continue"; + }; +private: + jump_type value; // values are CONT or BREAK +}; + +class IfElse : Statement { + IfElse(); + ~IfElse(); + //attributes: condition(expression), IfRest + void set_condition(Expression c){condition = c;}; + Expression get_condition(){return condition;}; + void set_else_stmt(IfRest stmt){else_stmt = stmt;}; + IfRest get_else_stmt(){return else_stmt;}; +private: + Expression condition; + IfRest else_stmt; +}; + +class IfRest : Statement { +public: + IfRest(); + ~IfRest(); + Block get_block_stmt(){return block_stmt;}; + void set_block_stmt(Block stmt){block_stmt = stmt;}; + //atrributes: a block, or another IfElse +private: + Block block_stmt; +}; + +class While : Statement { +public: + While(); + ~While(); + void set_condition(Expression c){condition = c;}; + Expression get_condition(){return condition;}; + Block get_block_stmt(){return block_stmt;}; + void set_block_stmt(Block stmt){block_stmt = stmt;}; + //attributes: condition, block +private: + Expression condition; + Block block_stmt; +}; + +class Variable : Expression { + Variable(); + ~Variable(); + void set_name(char n){name = n;}; + void set_type(var_type t){type = t;}; + string get_name(){return name;}; + var_type get_type(){ + if type == 0: + return "string"; + elif type == 1: + return "integer"; + elif type == 2: + return "character"; + elif type == 3: + return "floating_point"; + }; +private: + string name; + var_type type; +}; + +class UnOp : Expression { + UnOp(); + ~UnOp(); + void set_operation(un_op op){operation = op;}; + void set_expression(Expression e){expression = e;}; + un_op get_operation(){ + if operation == 0: + return "negation"; + elif operation == 1: + return "plusplus"; + }; + Expression get_expression(){return expression;}; +private: + un_op operation; + Expression expression; +}; + +class BinOp : Expression { + BinOp(); + ~BinOp(); + void set_operation(bin_op op){operation = op;}; + void set_left_expression(Expression l_e){left_exp = l_e;}; + void set_right_expression(Expression r_e){right_exp = r_e;}; + bin_op get_operation(){ + if operation == 0: + return "conjunction"; + elif operation == 1: + return "disjunction"; + elif operation == 2: + return "addition"; + elif operation == 3: + return "substraction"; + elif operation == 4: + return "multiplication"; + elif operation == 5: + return "division"; + elif operation == 6: + return "lthan"; + elif operation == 7: + return "mthan"; + elif operation == 8: + return "leq"; + elif operation == 9: + return "meq"; + elif operation == 10: + return "eq"; + elif operation == 11: + return "eqeq"; + }; + Expression get_left_expression(){return left_exp;}; + Expression get_right_expression(){return right_exp;}; +private: + bin_op operation; + Expression left_exp; + Expression right_exp; +}; + +class Boolean : Expression { + //not sure if this is necessary but putting + //it down for now + Boolean(); + ~Boolean(); + void set_value(bool v){value = v;}; + bool is_true(){return value;}; +private: + bool value; +}; + +>>>>>>> Stashed changes #endif // AST_H From a488cf43fa9bb86c64eb9a2bbb36d44a2a1a7064 Mon Sep 17 00:00:00 2001 From: milenanedeljkovic <80540793+milenanedeljkovic@users.noreply.github.com> Date: Tue, 16 Nov 2021 11:38:37 +0100 Subject: [PATCH 15/43] added references and corrected bugs - cases instead of ifs in get_type functions from dasha - all Expressions and Statements that are arguments in other classes are passed by reference --- Algorithm-visualizer/AST/ast.hpp | 260 ++++++++++++++++++++++++++++++- 1 file changed, 259 insertions(+), 1 deletion(-) diff --git a/Algorithm-visualizer/AST/ast.hpp b/Algorithm-visualizer/AST/ast.hpp index fbd6763..5ba01f2 100644 --- a/Algorithm-visualizer/AST/ast.hpp +++ b/Algorithm-visualizer/AST/ast.hpp @@ -1,8 +1,11 @@ #ifndef AST_H #define AST_H +#include +#include #include +/* class AST : public QAbstractItemModel { Q_OBJECT @@ -25,5 +28,260 @@ class AST : public QAbstractItemModel private: }; +*/ -#endif // AST_H +enum var_type { + unknown_var_type = 0, + string = 1, + integer = 2, + character = 3, + floating_point = 4 + +}; + +enum un_op { + unknown_un_op = 0, + negation = 1, + plusplus = 2 + //inverse = 2 (if we add this as a unary operation for number -> -number) +}; + +enum bin_op { + unknown_bin_op = 0, + conjunction = 1, + disjunction = 2, + addition = 3, + subtraction = 4, + multiplication = 5, + division = 6, + lthan = 7, + mthan = 8, + leq = 9, + meq = 10, + eq = 11, + eqeq = 12 +}; + +enum jump_type { + unknown_jump_type = 0, + br = 1, + cont = 2 +}; + +//AST CLASS + +class AST { +protected : AST(); +protected : ~AST(); +private: + std::map variables; +}; + +class Statement : AST { +protected : Statement(); +protected : ~Statement(); +}; + +enum expression_type { + unknown_expression_type = 0 +}; + +class Expression : AST { +protected : Expression(); +protected : Expression(expression_type t) { + type = t; + }; + ~Expression(); +private: + expression_type type = unknown_expression_type; +}; + +class Block : Statement { +protected : Block(); +protected : ~Block(); + //list of statements +}; + + +class Declaration : Statement { +public: + Declaration(); + ~Declaration(); + void set_var_type(var_type t){type = t;}; + std::string get_var_type(){ + switch(type) { + case 0: return "unknown variable type"; + case 1: return "string"; + case 2: return "integer"; + case 3: return "char"; + case 4: return "floating_point"; + } + } + char get_value(){return value;}; + void set_value(char v){value = v;}; + + +private: + var_type type = unknown_var_type; + char value; + //int x = 7, bool y = False + //attributes: + //name + value of the variable or Variable + sth +}; + +class Assignment : Statement { + public: + Assignment(); + ~Assignment(); + Expression* get_value(){return value;}; + void set_value(Expression* v){value= v;} + std::string get_name(){return name;}; + void set_name(std::string n){name= n;} + //x = 5; x = y +private: + std::string name; + Expression* value; +}; + +class Return : Statement { + Return(); + ~Return(); + void set_exp(Expression* e){exp = e;}; + Expression* get_exp(){return exp;}; +private: + Expression* exp; +}; + +class Print : Statement { + Print(); + ~Print(); + void set_exp(Expression* e){exp = e;}; + Expression* get_exp(){return exp;}; + //attribute: expression to be printed +private: + Expression* exp; +}; + +class Jump : Statement { + Jump(); + Jump(char value); + ~Jump(); + void set_value(jump_type v){value = v;}; + std::string get_value(){ + switch(value) { + case 0: return "unknown jump type"; + case 1: return "break"; + case 2: return "continue"; + } + }; +private: + jump_type value = unknown_jump_type; +}; + +class IfRest : Statement { +public: + IfRest(); + ~IfRest(); + Block* get_block_stmt(){return block_stmt;}; + void set_block_stmt(Block* stmt){block_stmt = stmt;}; + //atrributes: a block, or another IfElse +private: + Block* block_stmt; +}; + +class IfElse : Statement { + IfElse(); + ~IfElse(); + //attributes: condition(expression), IfRest + void set_condition(Expression* c){condition = c;}; + Expression* get_condition(){return condition;}; + void set_else_stmt(IfRest* stmt){else_stmt = stmt;}; + IfRest* get_else_stmt(){return else_stmt;}; +private: + Expression* condition; + IfRest* else_stmt; +}; + +class While : Statement { +public: + While(); + ~While(); + void set_condition(Expression* c){condition = c;}; + Expression* get_condition(){return condition;}; + Block* get_block_stmt(){return block_stmt;}; + void set_block_stmt(Block* stmt){block_stmt = stmt;}; + + //attributes: condition, block +private: + Expression* condition; + Block* block_stmt; +}; + +class Variable : Expression { + Variable(); + ~Variable(); + void set_name(char n){name = n;}; + void set_type(var_type t){type = t;}; + std::string get_name(){return name;}; + var_type get_type(){return type;}; + +private: + std::string name; + var_type type = unknown_var_type; +}; + +class UnOp : Expression { + UnOp(); + ~UnOp(); + void set_operation(un_op op){operation = op;}; + void set_expression(Expression* e){expression = e;}; + un_op get_operation(){return operation;}; + Expression* get_expression(){return expression;}; +private: + un_op operation = unknown_un_op; + Expression* expression; +}; + +class BinOp : Expression { + BinOp(); + ~BinOp(); + void set_operation(bin_op op){operation = op;}; + void set_left_expression(Expression* l_e){left_exp = l_e;}; + void set_right_expression(Expression* r_e){right_exp = r_e;}; + std::string get_operation(){ + switch(operation) { + case 0: return "unknown binary operation"; + case 1: return "conjunction"; + case 2: return "disjunction"; + case 3: return "addition"; + case 4: return "substraction"; + case 5: return "multiplication"; + case 6: return "division"; + case 7: return "lthan"; + case 8: return "mthan"; + case 9: return "leq"; + case 10: return "meq"; + case 11: return "eq"; + case 12: return "eqeq"; + } + } + Expression* get_left_expression(){return left_exp;}; + Expression* get_right_expression(){return right_exp;}; +private: + bin_op operation = unknown_bin_op; + Expression* left_exp; + Expression* right_exp; +}; + +class Boolean : Expression { + //not sure if this is necessary but putting + //it down for now + Boolean(); + ~Boolean(); + void set_value(bool v){value = v;}; + bool is_true(){return value;}; +private: + bool value; +}; + +#endif From b6a923cfb564818c69cb3c46b4e051b2f2bbfa4e Mon Sep 17 00:00:00 2001 From: elena-mrdja <91255937+elena-mrdja@users.noreply.github.com> Date: Wed, 17 Nov 2021 23:24:25 +0100 Subject: [PATCH 16/43] added shapes to the viewer --- Algorithm-visualizer/GUI/viewer.cpp | 138 +++++++++++++++++++++++++++- Algorithm-visualizer/GUI/viewer.h | 34 +++++++ Algorithm-visualizer/mainwindow.ui | 2 +- 3 files changed, 171 insertions(+), 3 deletions(-) diff --git a/Algorithm-visualizer/GUI/viewer.cpp b/Algorithm-visualizer/GUI/viewer.cpp index 773ff00..8e71339 100644 --- a/Algorithm-visualizer/GUI/viewer.cpp +++ b/Algorithm-visualizer/GUI/viewer.cpp @@ -1,6 +1,140 @@ -#include "viewer.h" +#include "viewer.h" +#include "math.h" +#include +#include -Viewer::Viewer(QWidget *parent) : QWidget(parent) +Viewer::Viewer(QWidget *parent) : QWidget(parent), mBackgroundColor(0,0,255),mShapeColor(255,255,255),mShape(Process) { + on_shape_changed(); +} + +QSize Viewer::minimumSizeHint() const +{ + return QSize(100,100); +} +QSize Viewer::sizeHint() const +{ + return QSize(400,200); +} + +void Viewer::on_shape_changed() +{ + switch (mShape) { + case Arrow: + mScale =50; + mIntervalLength = 1; + mStepCount = 128; + mBackgroundColor = Qt::blue; + break; + + case UnitLine: + mScale =50; + mIntervalLength = 1; + mStepCount = 128; + mBackgroundColor = Qt::blue; + break; + + case Process: + mScale =4; + mIntervalLength = 4*M_PI; + mStepCount = 256; + mBackgroundColor = Qt::blue; + break; + + case Decision: + mScale =40; + mIntervalLength = 2*M_PI; + mStepCount = 256; + mBackgroundColor = Qt::blue; + break; + default: + break; + } +} + +QPointF Viewer::compute(float t) +{ + switch (mShape) { + case Arrow: + return compute_arrow(t); + break; + + case UnitLine: + //mBackgroundColor = Qt::green; + return compute_unitline(t); + break; + + case Process: + //mBackgroundColor = Qt::blue; + return compute_process(t); + break; + + case Decision: + //mBackgroundColor = Qt::yellow; + return compute_decision(t); + break; + + default: + break; + } + return QPointF(0,0); +} + +QPointF Viewer::compute_arrow(float t) +{ + return QPointF(1-t,1-t); //X,Y } + +QPointF Viewer::compute_unitline(float t) +{ + return QPointF(1-t,1-t); //X,Y +} + +QPointF Viewer::compute_decision(float t) +{ + return QPointF( + (t-4), //X + (2*t*t*t - 24*t*t + 96*t - 128) //Y + ); +} + +QPointF Viewer::compute_process(float t) +{ + float cos_t = cos(t); + float sin_t = sin(t); + float x = 2*cos_t*cos_t*cos_t; + float y=2*sin_t*sin_t*sin_t; + return QPointF(x,y); +} + +void Viewer::paintEvent(QPaintEvent *event) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing,true); + + painter.setBrush(mBackgroundColor); + painter.setPen(mShapeColor); + painter.drawRect(this->rect()); + + QPoint center = this->rect().center(); + + QPointF prevPoint = compute(0); + QPoint prevPixel; + prevPixel.setX(prevPoint.x()*mScale + center.x()); + prevPixel.setY(prevPoint.y()*mScale + center.y()); + + float step = mIntervalLength/mStepCount; + for(float t=0; t< mIntervalLength; t+=step){ + QPointF point = compute(t); + + QPoint pixel; + pixel.setX(point.x()*mScale + center.x()); + pixel.setY(point.y()*mScale + center.y()); + + painter.drawLine(pixel,prevPixel); + prevPixel =pixel; + } +} + + diff --git a/Algorithm-visualizer/GUI/viewer.h b/Algorithm-visualizer/GUI/viewer.h index f953c2b..75f7e46 100644 --- a/Algorithm-visualizer/GUI/viewer.h +++ b/Algorithm-visualizer/GUI/viewer.h @@ -9,6 +9,40 @@ class Viewer : public QWidget public: explicit Viewer(QWidget *parent = nullptr); + QSize minimumSizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const Q_DECL_OVERRIDE; + + //declaring all the shapes we will use + enum ShapeType {Arrow, UnitLine, Decision, Process}; + + void setBackgroundColor(QColor color){mBackgroundColor=color;} //setter function + QColor backgroudColor() const {return mBackgroundColor; } //getter, const function so that it doesn't modify the class variables + + void setShape(ShapeType shape){mShape=shape; on_shape_changed();} //declare rhe setter and getter fcts for shapes + ShapeType shape() const {return mShape; } + + void setScale(float scale) {mScale=scale; repaint();} + float scale() const {return mScale;} + +protected: + void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; + +private: + QPointF compute_arrow(float t); + QPointF compute_unitline(float t); + QPointF compute_decision(float t); + QPointF compute_process(float t); + void on_shape_changed(); + QPointF compute(float t); //dispatch function based on mShape type +private: + QColor mBackgroundColor; + QColor mShapeColor; + ShapeType mShape; + + float mIntervalLength; + float mScale; + int mStepCount; + signals: }; diff --git a/Algorithm-visualizer/mainwindow.ui b/Algorithm-visualizer/mainwindow.ui index 6328253..1828a22 100644 --- a/Algorithm-visualizer/mainwindow.ui +++ b/Algorithm-visualizer/mainwindow.ui @@ -14,7 +14,7 @@ MainWindow - + 30 From da323762587232fe8777a8274a04b4481b2329d2 Mon Sep 17 00:00:00 2001 From: goranovic37 Date: Thu, 18 Nov 2021 00:51:55 +0100 Subject: [PATCH 17/43] varcell should be scrollable, but there is a bug to be fixed --- Algorithm-visualizer/GUI/varcell.cpp | 2 +- Algorithm-visualizer/GUI/varcell.h | 8 +++++--- Algorithm-visualizer/mainwindow.cpp | 2 +- Algorithm-visualizer/mainwindow.h | 4 ++++ Algorithm-visualizer/mainwindow.ui | 6 +++--- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Algorithm-visualizer/GUI/varcell.cpp b/Algorithm-visualizer/GUI/varcell.cpp index 4405212..a4c3209 100644 --- a/Algorithm-visualizer/GUI/varcell.cpp +++ b/Algorithm-visualizer/GUI/varcell.cpp @@ -1,6 +1,6 @@ #include "varcell.h" -VarCell::VarCell() +VarCell::VarCell(QWidget *parent) : QGraphicsView(parent) { } diff --git a/Algorithm-visualizer/GUI/varcell.h b/Algorithm-visualizer/GUI/varcell.h index 0b691ef..c625e26 100644 --- a/Algorithm-visualizer/GUI/varcell.h +++ b/Algorithm-visualizer/GUI/varcell.h @@ -1,11 +1,13 @@ #ifndef VARCELL_H #define VARCELL_H +#include +#include +#include -class VarCell +class VarCell : public QGraphicsView { -public: - VarCell(); + }; #endif // VARCELL_H diff --git a/Algorithm-visualizer/mainwindow.cpp b/Algorithm-visualizer/mainwindow.cpp index 41a26bd..edab823 100644 --- a/Algorithm-visualizer/mainwindow.cpp +++ b/Algorithm-visualizer/mainwindow.cpp @@ -5,7 +5,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { - ui->setupUi(this); + } MainWindow::~MainWindow() diff --git a/Algorithm-visualizer/mainwindow.h b/Algorithm-visualizer/mainwindow.h index 4643e32..7643a2a 100644 --- a/Algorithm-visualizer/mainwindow.h +++ b/Algorithm-visualizer/mainwindow.h @@ -2,6 +2,9 @@ #define MAINWINDOW_H #include +#include +#include +#include QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } @@ -17,5 +20,6 @@ class MainWindow : public QMainWindow private: Ui::MainWindow *ui; + }; #endif // MAINWINDOW_H diff --git a/Algorithm-visualizer/mainwindow.ui b/Algorithm-visualizer/mainwindow.ui index 6328253..ffe6676 100644 --- a/Algorithm-visualizer/mainwindow.ui +++ b/Algorithm-visualizer/mainwindow.ui @@ -14,7 +14,7 @@ MainWindow - + 30 @@ -52,7 +52,7 @@ 0 0 825 - 26 + 22 @@ -74,7 +74,7 @@ VarCell QWidget -
varcell.h
+
varcell.h
1
From 2f40448ee8406a447404aa7bc5d15c6b6c441a32 Mon Sep 17 00:00:00 2001 From: goranovic37 Date: Thu, 18 Nov 2021 10:27:06 +0100 Subject: [PATCH 18/43] line missing --- Algorithm-visualizer/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Algorithm-visualizer/mainwindow.cpp b/Algorithm-visualizer/mainwindow.cpp index edab823..41a26bd 100644 --- a/Algorithm-visualizer/mainwindow.cpp +++ b/Algorithm-visualizer/mainwindow.cpp @@ -5,7 +5,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { - + ui->setupUi(this); } MainWindow::~MainWindow() From c74361c2ea62c500db9e8805ff01e3fa5e931aba Mon Sep 17 00:00:00 2001 From: mattea777 Date: Thu, 18 Nov 2021 10:55:54 +0100 Subject: [PATCH 19/43] Deleted unnecessary code --- Algorithm-visualizer/AST/ast.hpp | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/Algorithm-visualizer/AST/ast.hpp b/Algorithm-visualizer/AST/ast.hpp index 7090b79..01adde7 100644 --- a/Algorithm-visualizer/AST/ast.hpp +++ b/Algorithm-visualizer/AST/ast.hpp @@ -5,29 +5,6 @@ #include -class AST : public QAbstractItemModel -{ - Q_OBJECT - -public: - explicit AST(QObject *parent = nullptr); - - // Header: - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; - - // Basic functionality: - QModelIndex index(int row, int column, - const QModelIndex &parent = QModelIndex()) const override; - QModelIndex parent(const QModelIndex &index) const override; - - int rowCount(const QModelIndex &parent = QModelIndex()) const override; - int columnCount(const QModelIndex &parent = QModelIndex()) const override; - - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - -private: -}; - enum var_type { string = 0, integer = 1, From e8e1eab3c55ac76085b9a71185642f7c46a8b3f3 Mon Sep 17 00:00:00 2001 From: milenanedeljkovic <80540793+milenanedeljkovic@users.noreply.github.com> Date: Thu, 18 Nov 2021 10:57:28 +0100 Subject: [PATCH 20/43] evdokia + milena + dasha changes --- Algorithm-visualizer/AST/ast.hpp | 399 ++++++++++++++----------------- 1 file changed, 173 insertions(+), 226 deletions(-) diff --git a/Algorithm-visualizer/AST/ast.hpp b/Algorithm-visualizer/AST/ast.hpp index b8fb0cf..a64c5a0 100644 --- a/Algorithm-visualizer/AST/ast.hpp +++ b/Algorithm-visualizer/AST/ast.hpp @@ -1,342 +1,289 @@ #ifndef AST_H #define AST_H +#include +#include #include +using namespace std; -class AST : public QAbstractItemModel -{ - Q_OBJECT - -public: - explicit AST(QObject *parent = nullptr); - - // Header: - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; - - // Basic functionality: - QModelIndex index(int row, int column, - const QModelIndex &parent = QModelIndex()) const override; - QModelIndex parent(const QModelIndex &index) const override; - - int rowCount(const QModelIndex &parent = QModelIndex()) const override; - int columnCount(const QModelIndex &parent = QModelIndex()) const override; - - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - -private: -}; - -<<<<<<< Updated upstream -======= enum var_type { - string = 0, - integer = 1, - character = 2, - floating_point = 3 + unknown_var_type = 0, + string = 1, + integer = 2, + character = 3, + floating_point = 4 + }; enum un_op { - negation = 0, - plusplus = 1 + unknown_un_op = 0, + negation = 1, + plusplus = 2 //inverse = 2 (if we add this as a unary operation for number -> -number) }; enum bin_op { - conjunction = 0, - disjunction = 1, - addition = 2, - subtraction = 3, - multiplication = 4, - division = 5, - lthan = 6, - mthan = 7, - leq = 8, - meq = 9, - eq = 10, - eqeq = 11 + unknown_bin_op = 0, + conjunction = 1, + disjunction = 2, + addition = 3, + subtraction = 4, + multiplication = 5, + division = 6, + lthan = 7, + mthan = 8, + leq = 9, + meq = 10, + eq = 11, + eqeq = 12 }; enum jump_type { - jump = 0, - continue = 1 + unknown_jump_type = 0, + br = 1, + cont = 2 }; //AST CLASS class AST { - AST(); - ~AST(); - -//this whole rest of the class will probably be deleted -/* void set_left_child(AST* lc){left_child = lc;}; - AST* get_left_child(){return left_child;}; - void set_right_child(AST* rc){right_child = rc;}; - AST* get_right_child(){return right_child;}; - void set_parent(AST* par){parent = par;}; - AST* get_parent(){return parent;}; -private: - AST* left_child; - AST* right_child; - AST* parent; */ -}; - -/* -class NodeBinOp(AST) { - NodeBinOp(); - ~NodeBinOp(); - void set_bin_op(bin_op op){operation = op}; - bin_op get_bin_op(){return operation;}; -private: - bin_op operation; -}; - -class NodeUnOp(AST) { - NodeUnOp(); - ~NodeUnOp(); - void set_un_op(un_op op){operation = op;}; - un_op get_un_op(){return operation;}; +protected : AST(); +protected : ~AST(); +virtual std::string get_type() = 0; // Statement or Expression (this is an abstract method which will be defined in subclasses Statement +//and Expression and inherited by every other subclass below) +virtual std::string get_subtype() = 0; // Block, Declaration, UnOp, BinOp, ... +//(this is an abstract method which will be defined in subclasses Block, Declaration, ...) private: - un_op operation; + std::map variables; }; -class NodeVar(AST) { - NodeVar(); - ~NodeVar(); - void set_var_type(var_type vt){type = vt;}; - var_type get_var_type(return type;); - void set_var_name(char vn){var_name = vn;}; - char get_var_name(){return var_name;}; -private: - var_type type; - char var_name; +class Statement : public AST { +protected : Statement(); +protected : ~Statement(); +std::string get_type(){return "Statement";}; }; - -class NodeIf(AST) { - NodeIf(); - ~NodeIf(); - void set_condition(AST a){condition = a;}; - AST get_condition(){return condition;}; -private: - AST condition; -}; */ -class Statement (AST) { - Statement(); - ~Statement(); +enum expression_type { + unknown_expression_type = 0 }; -class Expression (AST) { - Expression(); +class Expression : public AST { +protected : Expression(); +protected : Expression(expression_type t) { + type = t; + }; ~Expression(); +std::string get_type(){return "Expression";}; +private: + expression_type type = unknown_expression_type; }; -class Block : Statement { - Block(); - ~Block(); +class Block : public Statement { +protected : Block(); +protected : ~Block(); +std::string get_subtype(){return "Block";}; //list of statements }; -class Declaration : Statement { + +class Declaration : public Statement { public: Declaration(); ~Declaration(); void set_var_type(var_type t){type = t;}; - var_type get_var_type(){ - if type == 0: - return "string"; - elif type == 1: - return "integer"; - elif type == 2: - return "character"; - elif type == 3: - return "floating_point"; - }; + std::string get_var_type(){ + switch(type) { + case 0: return "unknown variable type"; + case 1: return "string"; + case 2: return "integer"; + case 3: return "char"; + case 4: return "floating_point"; + } + } char get_value(){return value;}; void set_value(char v){value = v;}; + std::string get_subtype(){return "Declaration";}; + + private: - var_type type; + var_type type = unknown_var_type; char value; //int x = 7, bool y = False //attributes: //name + value of the variable or Variable + sth }; -class Assignment : Statement { +class Assignment : public Statement { public: Assignment(); ~Assignment(); - Expression get_value(){return value;}; - void set_value(Expression v){value= v;} - string get_name(){return name;}; - void set_name(string n){name= n;} + Expression* get_value(){return value;}; + void set_value(Expression* v){value= v;} + std::string get_name(){return name;}; + void set_name(std::string n){name= n;} //x = 5; x = y + std::string get_subtype(){return "Assignment";}; private: - string name; - Expression value; + std::string name; + Expression* value; }; -class Return : Statement { +class Return : public Statement { Return(); ~Return(); - void set_exp(Expression e){exp = e;}; - Expression get_exp(){return exp;}; + void set_exp(Expression* e){exp = e;}; + Expression* get_exp(){return exp;}; + std::string get_subtype(){return "Return";}; private: - Expression exp; + Expression* exp; }; -class Print : Statement { +class Print : public Statement { Print(); ~Print(); - void set_exp(Expression e){exp = e;}; - Expression get_exp(){return exp;}; - //attribute: expression to be printed + void set_exp(Expression* e){exp = e;}; + Expression* get_exp(){return exp;}; + std::string get_subtype(){return "Print";}; private: - Expression exp; + Expression* exp; }; -class Jump : Statement { -public: +class Jump : public Statement { Jump(); Jump(char value); ~Jump(); - void set_value(char v){value = v;}; - jump_type get_value(){ - if value == 0: - return "jump"; - elif value == 1: - return "continue"; - }; + void set_value(jump_type v){value = v;}; + std::string get_value(){ + switch(value) { + case 0: return "unknown jump type"; + case 1: return "break"; + case 2: return "continue"; + } + }; + std::string get_subtype(){return "Jump";}; private: - jump_type value; // values are CONT or BREAK + jump_type value = unknown_jump_type; }; -class IfElse : Statement { - IfElse(); - ~IfElse(); - //attributes: condition(expression), IfRest - void set_condition(Expression c){condition = c;}; - Expression get_condition(){return condition;}; - void set_else_stmt(IfRest stmt){else_stmt = stmt;}; - IfRest get_else_stmt(){return else_stmt;}; +class Decision : public Statement { + Decision(); + ~Decision(); + void set_condition(Expression* c){condition = c;}; + std::string get_subtype(){return "Decision";}; private: - Expression condition; - IfRest else_stmt; + Expression* condition; }; -class IfRest : Statement { +class IfRest : public Statement { public: IfRest(); ~IfRest(); - Block get_block_stmt(){return block_stmt;}; - void set_block_stmt(Block stmt){block_stmt = stmt;}; - //atrributes: a block, or another IfElse + Block* get_block_stmt(){return block_stmt;}; + void set_block_stmt(Block* stmt){block_stmt = stmt;}; + std::string get_subtype(){return "IfRest";}; private: - Block block_stmt; + Block* block_stmt; }; -class While : Statement { +class IfElse : public Decision { + IfElse(); + ~IfElse(); + //attributes: condition(expression), IfRest + void set_condition(Expression* c){condition = c;}; + Expression* get_condition(){return condition;}; + void set_else_stmt(IfRest* stmt){else_stmt = stmt;}; + IfRest* get_else_stmt(){return else_stmt;}; + std::string get_subtype(){return "IfElse";}; +private: + Expression* condition; + IfRest* else_stmt; +}; + +class While : public Decision { public: While(); ~While(); - void set_condition(Expression c){condition = c;}; - Expression get_condition(){return condition;}; - Block get_block_stmt(){return block_stmt;}; - void set_block_stmt(Block stmt){block_stmt = stmt;}; + void set_condition(Expression* c){condition = c;}; + Expression* get_condition(){return condition;}; + Block* get_block_stmt(){return block_stmt;}; + void set_block_stmt(Block* stmt){block_stmt = stmt;}; + std::string get_subtype(){return "While";}; //attributes: condition, block private: - Expression condition; - Block block_stmt; + Expression* condition; + Block* block_stmt; }; -class Variable : Expression { +class Variable : public Expression { Variable(); ~Variable(); void set_name(char n){name = n;}; void set_type(var_type t){type = t;}; - string get_name(){return name;}; - var_type get_type(){ - if type == 0: - return "string"; - elif type == 1: - return "integer"; - elif type == 2: - return "character"; - elif type == 3: - return "floating_point"; - }; + std::string get_name(){return name;}; + var_type get_var_type(){return type;}; + std::string get_subtype(){return "Variable";}; + private: - string name; - var_type type; + std::string name; + var_type type = unknown_var_type; }; -class UnOp : Expression { +class UnOp : public Expression { UnOp(); ~UnOp(); void set_operation(un_op op){operation = op;}; - void set_expression(Expression e){expression = e;}; - un_op get_operation(){ - if operation == 0: - return "negation"; - elif operation == 1: - return "plusplus"; - }; - Expression get_expression(){return expression;}; + void set_expression(Expression* e){expression = e;}; + un_op get_operation(){return operation;}; + Expression* get_expression(){return expression;}; + std::string get_subtype(){return "UnOp";}; private: - un_op operation; - Expression expression; + un_op operation = unknown_un_op; + Expression* expression; }; -class BinOp : Expression { +class BinOp : public Expression { BinOp(); ~BinOp(); void set_operation(bin_op op){operation = op;}; - void set_left_expression(Expression l_e){left_exp = l_e;}; - void set_right_expression(Expression r_e){right_exp = r_e;}; - bin_op get_operation(){ - if operation == 0: - return "conjunction"; - elif operation == 1: - return "disjunction"; - elif operation == 2: - return "addition"; - elif operation == 3: - return "substraction"; - elif operation == 4: - return "multiplication"; - elif operation == 5: - return "division"; - elif operation == 6: - return "lthan"; - elif operation == 7: - return "mthan"; - elif operation == 8: - return "leq"; - elif operation == 9: - return "meq"; - elif operation == 10: - return "eq"; - elif operation == 11: - return "eqeq"; - }; - Expression get_left_expression(){return left_exp;}; - Expression get_right_expression(){return right_exp;}; + void set_left_expression(Expression* l_e){left_exp = l_e;}; + void set_right_expression(Expression* r_e){right_exp = r_e;}; + std::string get_operation(){ + switch(operation) { + case 0: return "unknown binary operation"; + case 1: return "conjunction"; + case 2: return "disjunction"; + case 3: return "addition"; + case 4: return "substraction"; + case 5: return "multiplication"; + case 6: return "division"; + case 7: return "lthan"; + case 8: return "mthan"; + case 9: return "leq"; + case 10: return "meq"; + case 11: return "eq"; + case 12: return "eqeq"; + } + } + Expression* get_left_expression(){return left_exp;}; + Expression* get_right_expression(){return right_exp;}; + std::string get_subtype(){return "BinOp";}; private: - bin_op operation; - Expression left_exp; - Expression right_exp; + bin_op operation = unknown_bin_op; + Expression* left_exp; + Expression* right_exp; }; -class Boolean : Expression { +class Boolean : public Expression { //not sure if this is necessary but putting //it down for now Boolean(); ~Boolean(); void set_value(bool v){value = v;}; bool is_true(){return value;}; + std::string get_subtype(){return "Bool";}; private: bool value; }; ->>>>>>> Stashed changes -#endif // AST_H +#endif From 10e3773341abc21bb21ecca0dd6206dae0381122 Mon Sep 17 00:00:00 2001 From: milenanedeljkovic <80540793+milenanedeljkovic@users.noreply.github.com> Date: Thu, 18 Nov 2021 10:58:08 +0100 Subject: [PATCH 21/43] dasha + milena + evdokia changes --- Algorithm-visualizer/AST/ast.hpp | 90 ++++++++++++++++---------------- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/Algorithm-visualizer/AST/ast.hpp b/Algorithm-visualizer/AST/ast.hpp index 5ba01f2..a64c5a0 100644 --- a/Algorithm-visualizer/AST/ast.hpp +++ b/Algorithm-visualizer/AST/ast.hpp @@ -4,31 +4,7 @@ #include #include #include - -/* -class AST : public QAbstractItemModel -{ - Q_OBJECT - -public: - explicit AST(QObject *parent = nullptr); - - // Header: - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; - - // Basic functionality: - QModelIndex index(int row, int column, - const QModelIndex &parent = QModelIndex()) const override; - QModelIndex parent(const QModelIndex &index) const override; - - int rowCount(const QModelIndex &parent = QModelIndex()) const override; - int columnCount(const QModelIndex &parent = QModelIndex()) const override; - - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - -private: -}; -*/ +using namespace std; enum var_type { unknown_var_type = 0, @@ -73,37 +49,45 @@ enum jump_type { class AST { protected : AST(); protected : ~AST(); +virtual std::string get_type() = 0; // Statement or Expression (this is an abstract method which will be defined in subclasses Statement +//and Expression and inherited by every other subclass below) +virtual std::string get_subtype() = 0; // Block, Declaration, UnOp, BinOp, ... +//(this is an abstract method which will be defined in subclasses Block, Declaration, ...) private: std::map variables; }; -class Statement : AST { +class Statement : public AST { protected : Statement(); protected : ~Statement(); +std::string get_type(){return "Statement";}; }; enum expression_type { unknown_expression_type = 0 }; -class Expression : AST { +class Expression : public AST { protected : Expression(); protected : Expression(expression_type t) { type = t; }; ~Expression(); +std::string get_type(){return "Expression";}; private: expression_type type = unknown_expression_type; }; -class Block : Statement { +class Block : public Statement { protected : Block(); protected : ~Block(); +std::string get_subtype(){return "Block";}; //list of statements }; -class Declaration : Statement { + +class Declaration : public Statement { public: Declaration(); ~Declaration(); @@ -119,6 +103,7 @@ class Declaration : Statement { } char get_value(){return value;}; void set_value(char v){value = v;}; + std::string get_subtype(){return "Declaration";}; private: @@ -129,7 +114,7 @@ class Declaration : Statement { //name + value of the variable or Variable + sth }; -class Assignment : Statement { +class Assignment : public Statement { public: Assignment(); ~Assignment(); @@ -138,31 +123,33 @@ class Assignment : Statement { std::string get_name(){return name;}; void set_name(std::string n){name= n;} //x = 5; x = y + std::string get_subtype(){return "Assignment";}; private: std::string name; Expression* value; }; -class Return : Statement { +class Return : public Statement { Return(); ~Return(); void set_exp(Expression* e){exp = e;}; Expression* get_exp(){return exp;}; + std::string get_subtype(){return "Return";}; private: Expression* exp; }; -class Print : Statement { +class Print : public Statement { Print(); ~Print(); void set_exp(Expression* e){exp = e;}; Expression* get_exp(){return exp;}; - //attribute: expression to be printed + std::string get_subtype(){return "Print";}; private: Expression* exp; }; -class Jump : Statement { +class Jump : public Statement { Jump(); Jump(char value); ~Jump(); @@ -174,22 +161,32 @@ class Jump : Statement { case 2: return "continue"; } }; + std::string get_subtype(){return "Jump";}; private: jump_type value = unknown_jump_type; }; -class IfRest : Statement { +class Decision : public Statement { + Decision(); + ~Decision(); + void set_condition(Expression* c){condition = c;}; + std::string get_subtype(){return "Decision";}; +private: + Expression* condition; +}; + +class IfRest : public Statement { public: IfRest(); ~IfRest(); Block* get_block_stmt(){return block_stmt;}; void set_block_stmt(Block* stmt){block_stmt = stmt;}; - //atrributes: a block, or another IfElse + std::string get_subtype(){return "IfRest";}; private: Block* block_stmt; }; -class IfElse : Statement { +class IfElse : public Decision { IfElse(); ~IfElse(); //attributes: condition(expression), IfRest @@ -197,12 +194,13 @@ class IfElse : Statement { Expression* get_condition(){return condition;}; void set_else_stmt(IfRest* stmt){else_stmt = stmt;}; IfRest* get_else_stmt(){return else_stmt;}; + std::string get_subtype(){return "IfElse";}; private: Expression* condition; IfRest* else_stmt; }; -class While : Statement { +class While : public Decision { public: While(); ~While(); @@ -210,39 +208,41 @@ class While : Statement { Expression* get_condition(){return condition;}; Block* get_block_stmt(){return block_stmt;}; void set_block_stmt(Block* stmt){block_stmt = stmt;}; - + std::string get_subtype(){return "While";}; //attributes: condition, block private: Expression* condition; Block* block_stmt; }; -class Variable : Expression { +class Variable : public Expression { Variable(); ~Variable(); void set_name(char n){name = n;}; void set_type(var_type t){type = t;}; std::string get_name(){return name;}; - var_type get_type(){return type;}; + var_type get_var_type(){return type;}; + std::string get_subtype(){return "Variable";}; private: std::string name; var_type type = unknown_var_type; }; -class UnOp : Expression { +class UnOp : public Expression { UnOp(); ~UnOp(); void set_operation(un_op op){operation = op;}; void set_expression(Expression* e){expression = e;}; un_op get_operation(){return operation;}; Expression* get_expression(){return expression;}; + std::string get_subtype(){return "UnOp";}; private: un_op operation = unknown_un_op; Expression* expression; }; -class BinOp : Expression { +class BinOp : public Expression { BinOp(); ~BinOp(); void set_operation(bin_op op){operation = op;}; @@ -267,19 +267,21 @@ class BinOp : Expression { } Expression* get_left_expression(){return left_exp;}; Expression* get_right_expression(){return right_exp;}; + std::string get_subtype(){return "BinOp";}; private: bin_op operation = unknown_bin_op; Expression* left_exp; Expression* right_exp; }; -class Boolean : Expression { +class Boolean : public Expression { //not sure if this is necessary but putting //it down for now Boolean(); ~Boolean(); void set_value(bool v){value = v;}; bool is_true(){return value;}; + std::string get_subtype(){return "Bool";}; private: bool value; }; From 37a3af047f93913e71e0ca0cb80eaee9f9d9db23 Mon Sep 17 00:00:00 2001 From: milenanedeljkovic <80540793+milenanedeljkovic@users.noreply.github.com> Date: Thu, 18 Nov 2021 10:59:42 +0100 Subject: [PATCH 22/43] dasha + milena + evdokia changes --- Algorithm-visualizer/AST/ast.hpp | 343 +++++++++++++++---------------- 1 file changed, 171 insertions(+), 172 deletions(-) diff --git a/Algorithm-visualizer/AST/ast.hpp b/Algorithm-visualizer/AST/ast.hpp index 01adde7..a64c5a0 100644 --- a/Algorithm-visualizer/AST/ast.hpp +++ b/Algorithm-visualizer/AST/ast.hpp @@ -1,290 +1,289 @@ -#include -#include #ifndef AST_H #define AST_H +#include +#include #include +using namespace std; enum var_type { - string = 0, - integer = 1, - character = 2, - floating_point = 3 + unknown_var_type = 0, + string = 1, + integer = 2, + character = 3, + floating_point = 4 }; enum un_op { - negation = 0, - plusplus = 1 + unknown_un_op = 0, + negation = 1, + plusplus = 2 //inverse = 2 (if we add this as a unary operation for number -> -number) }; enum bin_op { - conjunction = 0, - disjunction = 1, - addition = 2, - subtraction = 3, - multiplication = 4, - division = 5, - lthan = 6, - mthan = 7, - leq = 8, - meq = 9, - eq = 10, - eqeq = 11 + unknown_bin_op = 0, + conjunction = 1, + disjunction = 2, + addition = 3, + subtraction = 4, + multiplication = 5, + division = 6, + lthan = 7, + mthan = 8, + leq = 9, + meq = 10, + eq = 11, + eqeq = 12 }; enum jump_type { - jump = 0, - continue = 1 + unknown_jump_type = 0, + br = 1, + cont = 2 }; //AST CLASS class AST { -// mattea777: The AST class will contain a cache in the form of a dictionary that will keep track of all the changes to the -// variables during the various blocks. As each block may contain sub-blocks, but they still need information from the same dictionary, -// the cache will be passed by reference to sub-blocks. The cache will be passed by reference to every operation that involves -// changing the value of the variables, so Block, Declaration, Assignment, UnOp, and potentially expression. Constructors with a cache argument will -// be added to the classes by Milena. -public: - AST(); - AST() - ~AST(); -private: - std::map cache = {}; - -//this whole rest of the class will probably be deleted -/* void set_left_child(AST* lc){left_child = lc;}; - AST* get_left_child(){return left_child;}; - void set_right_child(AST* rc){right_child = rc;}; - AST* get_right_child(){return right_child;}; - void set_parent(AST* par){parent = par;}; - AST* get_parent(){return parent;}; +protected : AST(); +protected : ~AST(); +virtual std::string get_type() = 0; // Statement or Expression (this is an abstract method which will be defined in subclasses Statement +//and Expression and inherited by every other subclass below) +virtual std::string get_subtype() = 0; // Block, Declaration, UnOp, BinOp, ... +//(this is an abstract method which will be defined in subclasses Block, Declaration, ...) private: - AST* left_child; - AST* right_child; - AST* parent; */ + std::map variables; }; -/* -class NodeBinOp(AST) { - NodeBinOp(); - ~NodeBinOp(); - void set_bin_op(bin_op op){operation = op}; - bin_op get_bin_op(){return operation;}; -private: - bin_op operation; +class Statement : public AST { +protected : Statement(); +protected : ~Statement(); +std::string get_type(){return "Statement";}; }; -class NodeUnOp(AST) { - NodeUnOp(); - ~NodeUnOp(); - void set_un_op(un_op op){operation = op;}; - un_op get_un_op(){return operation;}; -private: - un_op operation; +enum expression_type { + unknown_expression_type = 0 }; -class NodeVar(AST) { - NodeVar(); - ~NodeVar(); - void set_var_type(var_type vt){type = vt;}; - var_type get_var_type(return type;); - void set_var_name(char vn){var_name = vn;}; - char get_var_name(){return var_name;}; -private: - var_type type; - char var_name; -}; - -class NodeIf(AST) { - NodeIf(); - ~NodeIf(); - void set_condition(AST a){condition = a;}; - AST get_condition(){return condition;}; -private: - AST condition; -}; */ - -class Statement (AST) { - Statement(); - ~Statement(); -}; - -class Expression (AST) { - Expression(); +class Expression : public AST { +protected : Expression(); +protected : Expression(expression_type t) { + type = t; + }; ~Expression(); +std::string get_type(){return "Expression";}; +private: + expression_type type = unknown_expression_type; }; -class Block : Statement { - -public: - Block(); - Block(std::map* c){cache = c;}; - ~Block(); +class Block : public Statement { +protected : Block(); +protected : ~Block(); +std::string get_subtype(){return "Block";}; //list of statements -private: -// dictionary var_name, values[] -// Based on Dasha's changes, I need to verify the type of the array of stored values - std::map cache = {}; - }; -class Declaration : Statement { -// Write method to add new varibale to cache of Block + +class Declaration : public Statement { public: Declaration(); ~Declaration(); void set_var_type(var_type t){type = t;}; - var_type get_var_type(){return type}; + std::string get_var_type(){ + switch(type) { + case 0: return "unknown variable type"; + case 1: return "string"; + case 2: return "integer"; + case 3: return "char"; + case 4: return "floating_point"; + } + } char get_value(){return value;}; void set_value(char v){value = v;}; + std::string get_subtype(){return "Declaration";}; private: - var_type type; + var_type type = unknown_var_type; char value; //int x = 7, bool y = False //attributes: //name + value of the variable or Variable + sth }; -class Assignment : Statement { -// Write method to add new varibale to cache of Block +class Assignment : public Statement { public: Assignment(); ~Assignment(); - Expression get_value(){return value;}; - void set_value(Expression v){value= v;} - string get_name(){return name;}; - void set_name(string n){name= n;} + Expression* get_value(){return value;}; + void set_value(Expression* v){value= v;} + std::string get_name(){return name;}; + void set_name(std::string n){name= n;} //x = 5; x = y + std::string get_subtype(){return "Assignment";}; private: - string name; - Expression value; + std::string name; + Expression* value; }; -class Return : Statement { +class Return : public Statement { Return(); ~Return(); - void set_exp(Expression e){exp = e;}; - Expression get_exp(){return exp;}; + void set_exp(Expression* e){exp = e;}; + Expression* get_exp(){return exp;}; + std::string get_subtype(){return "Return";}; private: - Expression exp; + Expression* exp; }; -class Print : Statement { +class Print : public Statement { Print(); ~Print(); - void set_exp(Expression e){exp = e;}; - Expression get_exp(){return exp;}; - //attribute: expression to be printed + void set_exp(Expression* e){exp = e;}; + Expression* get_exp(){return exp;}; + std::string get_subtype(){return "Print";}; private: - Expression exp; + Expression* exp; }; -class Jump : Statement { -public: - Jump(); - Jump(char value); - ~Jump(); - void set_value(char v){value = v;}; - jump_type get_value(){return value;}; +class Jump : public Statement { + Jump(); + Jump(char value); + ~Jump(); + void set_value(jump_type v){value = v;}; + std::string get_value(){ + switch(value) { + case 0: return "unknown jump type"; + case 1: return "break"; + case 2: return "continue"; + } + }; + std::string get_subtype(){return "Jump";}; private: - jump_type value; // values are CONT or BREAK + jump_type value = unknown_jump_type; }; -class IfElse : Statement { - IfElse(); - ~IfElse(); - //attributes: condition(expression), IfRest - void set_condition(Expression c){condition = c;}; - Expression get_condition(){return condition;}; - void set_else_stmt(IfRest stmt){else_stmt = stmt;}; - IfRest get_else_stmt(){return else_stmt;}; +class Decision : public Statement { + Decision(); + ~Decision(); + void set_condition(Expression* c){condition = c;}; + std::string get_subtype(){return "Decision";}; private: - Expression condition; - IfRest else_stmt; + Expression* condition; }; -class IfRest : Statement { +class IfRest : public Statement { public: IfRest(); ~IfRest(); - Block get_block_stmt(){return block_stmt;}; - void set_block_stmt(Block stmt){block_stmt = stmt;}; - //atrributes: a block, or another IfElse + Block* get_block_stmt(){return block_stmt;}; + void set_block_stmt(Block* stmt){block_stmt = stmt;}; + std::string get_subtype(){return "IfRest";}; private: - Block block_stmt; + Block* block_stmt; }; -class While : Statement { +class IfElse : public Decision { + IfElse(); + ~IfElse(); + //attributes: condition(expression), IfRest + void set_condition(Expression* c){condition = c;}; + Expression* get_condition(){return condition;}; + void set_else_stmt(IfRest* stmt){else_stmt = stmt;}; + IfRest* get_else_stmt(){return else_stmt;}; + std::string get_subtype(){return "IfElse";}; +private: + Expression* condition; + IfRest* else_stmt; +}; + +class While : public Decision { public: While(); ~While(); - void set_condition(Expression c){condition = c;}; - Expression get_condition(){return condition;}; - Block get_block_stmt(){return block_stmt;}; - void set_block_stmt(Block stmt){block_stmt = stmt;}; - + void set_condition(Expression* c){condition = c;}; + Expression* get_condition(){return condition;}; + Block* get_block_stmt(){return block_stmt;}; + void set_block_stmt(Block* stmt){block_stmt = stmt;}; + std::string get_subtype(){return "While";}; //attributes: condition, block private: - Expression condition; - Block block_stmt; + Expression* condition; + Block* block_stmt; }; -class Variable : Expression { +class Variable : public Expression { Variable(); ~Variable(); void set_name(char n){name = n;}; void set_type(var_type t){type = t;}; - string get_name(){return name;}; - var_type get_type(){return type;}; + std::string get_name(){return name;}; + var_type get_var_type(){return type;}; + std::string get_subtype(){return "Variable";}; private: - string name; - var_type type; + std::string name; + var_type type = unknown_var_type; }; -class UnOp : Expression { -// Write method to add new varibale to cache of Block +class UnOp : public Expression { UnOp(); ~UnOp(); void set_operation(un_op op){operation = op;}; - void set_expression(Expression e){expression = e;}; + void set_expression(Expression* e){expression = e;}; un_op get_operation(){return operation;}; - Expression get_expression(){return expression;}; + Expression* get_expression(){return expression;}; + std::string get_subtype(){return "UnOp";}; private: - un_op operation; - Expression expression; + un_op operation = unknown_un_op; + Expression* expression; }; -class BinOp : Expression { +class BinOp : public Expression { BinOp(); ~BinOp(); void set_operation(bin_op op){operation = op;}; - void set_left_expression(Expression l_e){left_exp = l_e;}; - void set_right_expression(Expression r_e){right_exp = r_e;}; - bin_op get_operation(){return operation;}; - Expression get_left_expression(){return left_exp;}; - Expression get_right_expression(){return right_exp;}; + void set_left_expression(Expression* l_e){left_exp = l_e;}; + void set_right_expression(Expression* r_e){right_exp = r_e;}; + std::string get_operation(){ + switch(operation) { + case 0: return "unknown binary operation"; + case 1: return "conjunction"; + case 2: return "disjunction"; + case 3: return "addition"; + case 4: return "substraction"; + case 5: return "multiplication"; + case 6: return "division"; + case 7: return "lthan"; + case 8: return "mthan"; + case 9: return "leq"; + case 10: return "meq"; + case 11: return "eq"; + case 12: return "eqeq"; + } + } + Expression* get_left_expression(){return left_exp;}; + Expression* get_right_expression(){return right_exp;}; + std::string get_subtype(){return "BinOp";}; private: - bin_op operation; - Expression left_exp; - Expression right_exp; + bin_op operation = unknown_bin_op; + Expression* left_exp; + Expression* right_exp; }; -class Boolean : Expression { +class Boolean : public Expression { //not sure if this is necessary but putting //it down for now Boolean(); ~Boolean(); void set_value(bool v){value = v;}; bool is_true(){return value;}; + std::string get_subtype(){return "Bool";}; private: bool value; }; -#endif // AST_H +#endif From 5d193852be78ecbe007e321106c9750fe1e71b43 Mon Sep 17 00:00:00 2001 From: elena-mrdja <91255937+elena-mrdja@users.noreply.github.com> Date: Thu, 18 Nov 2021 11:10:22 +0100 Subject: [PATCH 23/43] fixed qt mainwindow SetUp --- Algorithm-visualizer/mainwindow.cpp | 3 +-- Algorithm-visualizer/mainwindow.h | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Algorithm-visualizer/mainwindow.cpp b/Algorithm-visualizer/mainwindow.cpp index 41a26bd..8f6a553 100644 --- a/Algorithm-visualizer/mainwindow.cpp +++ b/Algorithm-visualizer/mainwindow.cpp @@ -2,8 +2,7 @@ #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) - , ui(new Ui::MainWindow) + : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } diff --git a/Algorithm-visualizer/mainwindow.h b/Algorithm-visualizer/mainwindow.h index 7643a2a..1b1a47b 100644 --- a/Algorithm-visualizer/mainwindow.h +++ b/Algorithm-visualizer/mainwindow.h @@ -5,6 +5,7 @@ #include #include #include +#include "ui_mainwindow.h" QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } @@ -19,7 +20,7 @@ class MainWindow : public QMainWindow ~MainWindow(); private: - Ui::MainWindow *ui; + Ui::MainWindow ui; }; #endif // MAINWINDOW_H From 8a1847bd5b5988240b99d0a0b26b8228c8a480f3 Mon Sep 17 00:00:00 2001 From: mattea777 Date: Thu, 18 Nov 2021 11:32:36 +0100 Subject: [PATCH 24/43] Added individual hpp/cpp files for every class I copied the already existing classes into separate cpp/hpp files in order to avoid git conflicts. --- Algorithm-visualizer/AST/assignment.cpp | 6 + Algorithm-visualizer/AST/assignment.hpp | 63 ++++++ Algorithm-visualizer/AST/ast.hpp | 214 +----------------- Algorithm-visualizer/AST/binop.cpp | 6 + Algorithm-visualizer/AST/binop.hpp | 81 +++++++ Algorithm-visualizer/AST/block.cpp | 6 + Algorithm-visualizer/AST/block.hpp | 55 +++++ Algorithm-visualizer/AST/boolean.cpp | 6 + Algorithm-visualizer/AST/boolean.hpp | 60 +++++ Algorithm-visualizer/AST/class.cpp | 6 + Algorithm-visualizer/AST/class.hpp | 60 +++++ Algorithm-visualizer/AST/decision.cpp | 6 + Algorithm-visualizer/AST/decision.hpp | 58 +++++ Algorithm-visualizer/AST/declaration.cpp | 6 + Algorithm-visualizer/AST/declaration.hpp | 76 +++++++ Algorithm-visualizer/AST/expression.cpp | 6 + Algorithm-visualizer/AST/expression.hpp | 58 +++++ Algorithm-visualizer/AST/ifelse.cpp | 6 + Algorithm-visualizer/AST/ifelse.hpp | 64 ++++++ Algorithm-visualizer/AST/ifrest.cpp | 6 + Algorithm-visualizer/AST/ifrest.hpp | 60 +++++ Algorithm-visualizer/AST/jump.cpp | 6 + Algorithm-visualizer/AST/jump.hpp | 66 ++++++ Algorithm-visualizer/AST/print.cpp | 6 + Algorithm-visualizer/AST/print.hpp | 59 +++++ Algorithm-visualizer/AST/statement.cpp | 6 + Algorithm-visualizer/AST/statement.hpp | 55 +++++ Algorithm-visualizer/AST/unop.cpp | 6 + Algorithm-visualizer/AST/unop.hpp | 59 +++++ Algorithm-visualizer/AST/variable.cpp | 6 + Algorithm-visualizer/AST/variable.hpp | 21 ++ Algorithm-visualizer/AST/while.cpp | 6 + Algorithm-visualizer/AST/while.hpp | 64 ++++++ Algorithm-visualizer/Algorithm-visualizer.pro | 32 +++ 34 files changed, 1094 insertions(+), 207 deletions(-) create mode 100644 Algorithm-visualizer/AST/assignment.cpp create mode 100644 Algorithm-visualizer/AST/assignment.hpp create mode 100644 Algorithm-visualizer/AST/binop.cpp create mode 100644 Algorithm-visualizer/AST/binop.hpp create mode 100644 Algorithm-visualizer/AST/block.cpp create mode 100644 Algorithm-visualizer/AST/block.hpp create mode 100644 Algorithm-visualizer/AST/boolean.cpp create mode 100644 Algorithm-visualizer/AST/boolean.hpp create mode 100644 Algorithm-visualizer/AST/class.cpp create mode 100644 Algorithm-visualizer/AST/class.hpp create mode 100644 Algorithm-visualizer/AST/decision.cpp create mode 100644 Algorithm-visualizer/AST/decision.hpp create mode 100644 Algorithm-visualizer/AST/declaration.cpp create mode 100644 Algorithm-visualizer/AST/declaration.hpp create mode 100644 Algorithm-visualizer/AST/expression.cpp create mode 100644 Algorithm-visualizer/AST/expression.hpp create mode 100644 Algorithm-visualizer/AST/ifelse.cpp create mode 100644 Algorithm-visualizer/AST/ifelse.hpp create mode 100644 Algorithm-visualizer/AST/ifrest.cpp create mode 100644 Algorithm-visualizer/AST/ifrest.hpp create mode 100644 Algorithm-visualizer/AST/jump.cpp create mode 100644 Algorithm-visualizer/AST/jump.hpp create mode 100644 Algorithm-visualizer/AST/print.cpp create mode 100644 Algorithm-visualizer/AST/print.hpp create mode 100644 Algorithm-visualizer/AST/statement.cpp create mode 100644 Algorithm-visualizer/AST/statement.hpp create mode 100644 Algorithm-visualizer/AST/unop.cpp create mode 100644 Algorithm-visualizer/AST/unop.hpp create mode 100644 Algorithm-visualizer/AST/variable.cpp create mode 100644 Algorithm-visualizer/AST/variable.hpp create mode 100644 Algorithm-visualizer/AST/while.cpp create mode 100644 Algorithm-visualizer/AST/while.hpp diff --git a/Algorithm-visualizer/AST/assignment.cpp b/Algorithm-visualizer/AST/assignment.cpp new file mode 100644 index 0000000..4e99a47 --- /dev/null +++ b/Algorithm-visualizer/AST/assignment.cpp @@ -0,0 +1,6 @@ +#include "assignment.hpp" + +Assignment::Assignment() +{ + +} diff --git a/Algorithm-visualizer/AST/assignment.hpp b/Algorithm-visualizer/AST/assignment.hpp new file mode 100644 index 0000000..c3d203a --- /dev/null +++ b/Algorithm-visualizer/AST/assignment.hpp @@ -0,0 +1,63 @@ +#include "ast.hpp" +#include "statement.hpp" +#include "expression.hpp" +#ifndef ASSIGNMENT_HPP +#define ASSIGNMENT_HPP + +//enum var_type { +// unknown_var_type = 0, +// string = 1, +// integer = 2, +// character = 3, +// floating_point = 4 + +//}; + +//enum un_op { +// unknown_un_op = 0, +// negation = 1, +// plusplus = 2 +// //inverse = 2 (if we add this as a unary operation for number -> -number) +//}; + +//enum bin_op { +// unknown_bin_op = 0, +// conjunction = 1, +// disjunction = 2, +// addition = 3, +// subtraction = 4, +// multiplication = 5, +// division = 6, +// lthan = 7, +// mthan = 8, +// leq = 9, +// meq = 10, +// eq = 11, +// eqeq = 12 +//}; + +//enum jump_type { +// unknown_jump_type = 0, +// br = 1, +// cont = 2 +//}; +//enum expression_type { +// unknown_expression_type = 0 +//}; + + +class Assignment : public Statement { + public: + Assignment(); + ~Assignment(); + Expression* get_value(){return value;}; + void set_value(Expression* v){value= v;} + std::string get_name(){return name;}; + void set_name(std::string n){name= n;} + //x = 5; x = y + std::string get_subtype(){return "Assignment";}; +private: + std::string name; + Expression* value; +}; +#endif // ASSIGNMENT_HPP diff --git a/Algorithm-visualizer/AST/ast.hpp b/Algorithm-visualizer/AST/ast.hpp index a64c5a0..ec8b8ec 100644 --- a/Algorithm-visualizer/AST/ast.hpp +++ b/Algorithm-visualizer/AST/ast.hpp @@ -4,6 +4,7 @@ #include #include #include + using namespace std; enum var_type { @@ -43,6 +44,9 @@ enum jump_type { br = 1, cont = 2 }; +enum expression_type { + unknown_expression_type = 0 +}; //AST CLASS @@ -57,233 +61,29 @@ virtual std::string get_subtype() = 0; // Block, Declaration, UnOp, BinOp, ... std::map variables; }; -class Statement : public AST { -protected : Statement(); -protected : ~Statement(); -std::string get_type(){return "Statement";}; -}; -enum expression_type { - unknown_expression_type = 0 -}; -class Expression : public AST { -protected : Expression(); -protected : Expression(expression_type t) { - type = t; - }; - ~Expression(); -std::string get_type(){return "Expression";}; -private: - expression_type type = unknown_expression_type; -}; -class Block : public Statement { -protected : Block(); -protected : ~Block(); -std::string get_subtype(){return "Block";}; - //list of statements -}; -class Declaration : public Statement { -public: - Declaration(); - ~Declaration(); - void set_var_type(var_type t){type = t;}; - std::string get_var_type(){ - switch(type) { - case 0: return "unknown variable type"; - case 1: return "string"; - case 2: return "integer"; - case 3: return "char"; - case 4: return "floating_point"; - } - } - char get_value(){return value;}; - void set_value(char v){value = v;}; - std::string get_subtype(){return "Declaration";}; -private: - var_type type = unknown_var_type; - char value; - //int x = 7, bool y = False - //attributes: - //name + value of the variable or Variable + sth -}; -class Assignment : public Statement { - public: - Assignment(); - ~Assignment(); - Expression* get_value(){return value;}; - void set_value(Expression* v){value= v;} - std::string get_name(){return name;}; - void set_name(std::string n){name= n;} - //x = 5; x = y - std::string get_subtype(){return "Assignment";}; -private: - std::string name; - Expression* value; -}; -class Return : public Statement { - Return(); - ~Return(); - void set_exp(Expression* e){exp = e;}; - Expression* get_exp(){return exp;}; - std::string get_subtype(){return "Return";}; -private: - Expression* exp; -}; -class Print : public Statement { - Print(); - ~Print(); - void set_exp(Expression* e){exp = e;}; - Expression* get_exp(){return exp;}; - std::string get_subtype(){return "Print";}; -private: - Expression* exp; -}; -class Jump : public Statement { - Jump(); - Jump(char value); - ~Jump(); - void set_value(jump_type v){value = v;}; - std::string get_value(){ - switch(value) { - case 0: return "unknown jump type"; - case 1: return "break"; - case 2: return "continue"; - } - }; - std::string get_subtype(){return "Jump";}; -private: - jump_type value = unknown_jump_type; -}; -class Decision : public Statement { - Decision(); - ~Decision(); - void set_condition(Expression* c){condition = c;}; - std::string get_subtype(){return "Decision";}; -private: - Expression* condition; -}; -class IfRest : public Statement { -public: - IfRest(); - ~IfRest(); - Block* get_block_stmt(){return block_stmt;}; - void set_block_stmt(Block* stmt){block_stmt = stmt;}; - std::string get_subtype(){return "IfRest";}; -private: - Block* block_stmt; -}; -class IfElse : public Decision { - IfElse(); - ~IfElse(); - //attributes: condition(expression), IfRest - void set_condition(Expression* c){condition = c;}; - Expression* get_condition(){return condition;}; - void set_else_stmt(IfRest* stmt){else_stmt = stmt;}; - IfRest* get_else_stmt(){return else_stmt;}; - std::string get_subtype(){return "IfElse";}; -private: - Expression* condition; - IfRest* else_stmt; -}; -class While : public Decision { -public: - While(); - ~While(); - void set_condition(Expression* c){condition = c;}; - Expression* get_condition(){return condition;}; - Block* get_block_stmt(){return block_stmt;}; - void set_block_stmt(Block* stmt){block_stmt = stmt;}; - std::string get_subtype(){return "While";}; - //attributes: condition, block -private: - Expression* condition; - Block* block_stmt; -}; -class Variable : public Expression { - Variable(); - ~Variable(); - void set_name(char n){name = n;}; - void set_type(var_type t){type = t;}; - std::string get_name(){return name;}; - var_type get_var_type(){return type;}; - std::string get_subtype(){return "Variable";}; -private: - std::string name; - var_type type = unknown_var_type; -}; -class UnOp : public Expression { - UnOp(); - ~UnOp(); - void set_operation(un_op op){operation = op;}; - void set_expression(Expression* e){expression = e;}; - un_op get_operation(){return operation;}; - Expression* get_expression(){return expression;}; - std::string get_subtype(){return "UnOp";}; -private: - un_op operation = unknown_un_op; - Expression* expression; -}; -class BinOp : public Expression { - BinOp(); - ~BinOp(); - void set_operation(bin_op op){operation = op;}; - void set_left_expression(Expression* l_e){left_exp = l_e;}; - void set_right_expression(Expression* r_e){right_exp = r_e;}; - std::string get_operation(){ - switch(operation) { - case 0: return "unknown binary operation"; - case 1: return "conjunction"; - case 2: return "disjunction"; - case 3: return "addition"; - case 4: return "substraction"; - case 5: return "multiplication"; - case 6: return "division"; - case 7: return "lthan"; - case 8: return "mthan"; - case 9: return "leq"; - case 10: return "meq"; - case 11: return "eq"; - case 12: return "eqeq"; - } - } - Expression* get_left_expression(){return left_exp;}; - Expression* get_right_expression(){return right_exp;}; - std::string get_subtype(){return "BinOp";}; -private: - bin_op operation = unknown_bin_op; - Expression* left_exp; - Expression* right_exp; -}; -class Boolean : public Expression { - //not sure if this is necessary but putting - //it down for now - Boolean(); - ~Boolean(); - void set_value(bool v){value = v;}; - bool is_true(){return value;}; - std::string get_subtype(){return "Bool";}; -private: - bool value; -}; + + + #endif diff --git a/Algorithm-visualizer/AST/binop.cpp b/Algorithm-visualizer/AST/binop.cpp new file mode 100644 index 0000000..111d0ff --- /dev/null +++ b/Algorithm-visualizer/AST/binop.cpp @@ -0,0 +1,6 @@ +#include "binop.hpp" + +BinOp::BinOp() +{ + +} diff --git a/Algorithm-visualizer/AST/binop.hpp b/Algorithm-visualizer/AST/binop.hpp new file mode 100644 index 0000000..bd9faaa --- /dev/null +++ b/Algorithm-visualizer/AST/binop.hpp @@ -0,0 +1,81 @@ + +#include "expression.hpp" +#include "ast.hpp" +#ifndef BINOP_HPP +#define BINOP_HPP + +//enum var_type { +// unknown_var_type = 0, +// string = 1, +// integer = 2, +// character = 3, +// floating_point = 4 + +//}; + +//enum un_op { +// unknown_un_op = 0, +// negation = 1, +// plusplus = 2 +// //inverse = 2 (if we add this as a unary operation for number -> -number) +//}; + +//enum bin_op { +// unknown_bin_op = 0, +// conjunction = 1, +// disjunction = 2, +// addition = 3, +// subtraction = 4, +// multiplication = 5, +// division = 6, +// lthan = 7, +// mthan = 8, +// leq = 9, +// meq = 10, +// eq = 11, +// eqeq = 12 +//}; + +//enum jump_type { +// unknown_jump_type = 0, +// br = 1, +// cont = 2 +//}; +//enum expression_type { +// unknown_expression_type = 0 +//}; + + +class BinOp : public Expression { + BinOp(); + ~BinOp(); + void set_operation(bin_op op){operation = op;}; + void set_left_expression(Expression* l_e){left_exp = l_e;}; + void set_right_expression(Expression* r_e){right_exp = r_e;}; + std::string get_operation(){ + switch(operation) { + case 0: return "unknown binary operation"; + case 1: return "conjunction"; + case 2: return "disjunction"; + case 3: return "addition"; + case 4: return "substraction"; + case 5: return "multiplication"; + case 6: return "division"; + case 7: return "lthan"; + case 8: return "mthan"; + case 9: return "leq"; + case 10: return "meq"; + case 11: return "eq"; + case 12: return "eqeq"; + } + } + Expression* get_left_expression(){return left_exp;}; + Expression* get_right_expression(){return right_exp;}; + std::string get_subtype(){return "BinOp";}; +private: + bin_op operation = unknown_bin_op; + Expression* left_exp; + Expression* right_exp; +}; + +#endif // BINOP_HPP diff --git a/Algorithm-visualizer/AST/block.cpp b/Algorithm-visualizer/AST/block.cpp new file mode 100644 index 0000000..0943fbe --- /dev/null +++ b/Algorithm-visualizer/AST/block.cpp @@ -0,0 +1,6 @@ +#include "block.hpp" + +Block::Block() +{ + +} diff --git a/Algorithm-visualizer/AST/block.hpp b/Algorithm-visualizer/AST/block.hpp new file mode 100644 index 0000000..2b99f99 --- /dev/null +++ b/Algorithm-visualizer/AST/block.hpp @@ -0,0 +1,55 @@ +#include "ast.hpp" +#include "statement.hpp" +#ifndef BLOCK_HPP +#define BLOCK_HPP + +//enum var_type { +// unknown_var_type = 0, +// string = 1, +// integer = 2, +// character = 3, +// floating_point = 4 + +//}; + +//enum un_op { +// unknown_un_op = 0, +// negation = 1, +// plusplus = 2 +// //inverse = 2 (if we add this as a unary operation for number -> -number) +//}; + +//enum bin_op { +// unknown_bin_op = 0, +// conjunction = 1, +// disjunction = 2, +// addition = 3, +// subtraction = 4, +// multiplication = 5, +// division = 6, +// lthan = 7, +// mthan = 8, +// leq = 9, +// meq = 10, +// eq = 11, +// eqeq = 12 +//}; + +//enum jump_type { +// unknown_jump_type = 0, +// br = 1, +// cont = 2 +//}; +//enum expression_type { +// unknown_expression_type = 0 +//}; + + +class Block : public Statement { +protected : Block(); +protected : ~Block(); +std::string get_subtype(){return "Block";}; + //list of statements +}; + +#endif // BLOCK_HPP diff --git a/Algorithm-visualizer/AST/boolean.cpp b/Algorithm-visualizer/AST/boolean.cpp new file mode 100644 index 0000000..aaf4e98 --- /dev/null +++ b/Algorithm-visualizer/AST/boolean.cpp @@ -0,0 +1,6 @@ +#include "boolean.hpp" + +Boolean::Boolean() +{ + +} diff --git a/Algorithm-visualizer/AST/boolean.hpp b/Algorithm-visualizer/AST/boolean.hpp new file mode 100644 index 0000000..89706a0 --- /dev/null +++ b/Algorithm-visualizer/AST/boolean.hpp @@ -0,0 +1,60 @@ + +#include "expression.hpp" +#include "ast.hpp" +#ifndef BOOLEAN_HPP +#define BOOLEAN_HPP + +//enum var_type { +// unknown_var_type = 0, +// string = 1, +// integer = 2, +// character = 3, +// floating_point = 4 + +//}; + +//enum un_op { +// unknown_un_op = 0, +// negation = 1, +// plusplus = 2 +// //inverse = 2 (if we add this as a unary operation for number -> -number) +//}; + +//enum bin_op { +// unknown_bin_op = 0, +// conjunction = 1, +// disjunction = 2, +// addition = 3, +// subtraction = 4, +// multiplication = 5, +// division = 6, +// lthan = 7, +// mthan = 8, +// leq = 9, +// meq = 10, +// eq = 11, +// eqeq = 12 +//}; + +//enum jump_type { +// unknown_jump_type = 0, +// br = 1, +// cont = 2 +//}; +//enum expression_type { +// unknown_expression_type = 0 +//}; + + +class Boolean : public Expression { + //not sure if this is necessary but putting + //it down for now + Boolean(); + ~Boolean(); + void set_value(bool v){value = v;}; + bool is_true(){return value;}; + std::string get_subtype(){return "Bool";}; +private: + bool value; +}; +#endif // BOOLEAN_HPP diff --git a/Algorithm-visualizer/AST/class.cpp b/Algorithm-visualizer/AST/class.cpp new file mode 100644 index 0000000..ba28d06 --- /dev/null +++ b/Algorithm-visualizer/AST/class.cpp @@ -0,0 +1,6 @@ +#include "class.hpp" + +Class::Class() +{ + +} diff --git a/Algorithm-visualizer/AST/class.hpp b/Algorithm-visualizer/AST/class.hpp new file mode 100644 index 0000000..698b843 --- /dev/null +++ b/Algorithm-visualizer/AST/class.hpp @@ -0,0 +1,60 @@ + +#include "expression.hpp" +#include "statement.hpp" +#include "ast.hpp" +#ifndef CLASS_HPP +#define CLASS_HPP + +//enum var_type { +// unknown_var_type = 0, +// string = 1, +// integer = 2, +// character = 3, +// floating_point = 4 + +//}; + +//enum un_op { +// unknown_un_op = 0, +// negation = 1, +// plusplus = 2 +// //inverse = 2 (if we add this as a unary operation for number -> -number) +//}; + +//enum bin_op { +// unknown_bin_op = 0, +// conjunction = 1, +// disjunction = 2, +// addition = 3, +// subtraction = 4, +// multiplication = 5, +// division = 6, +// lthan = 7, +// mthan = 8, +// leq = 9, +// meq = 10, +// eq = 11, +// eqeq = 12 +//}; + +//enum jump_type { +// unknown_jump_type = 0, +// br = 1, +// cont = 2 +//}; +//enum expression_type { +// unknown_expression_type = 0 +//}; + + +class Return : public Statement { + Return(); + ~Return(); + void set_exp(Expression* e){exp = e;}; + Expression* get_exp(){return exp;}; + std::string get_subtype(){return "Return";}; +private: + Expression* exp; +}; + +#endif // CLASS_HPP diff --git a/Algorithm-visualizer/AST/decision.cpp b/Algorithm-visualizer/AST/decision.cpp new file mode 100644 index 0000000..b8979e2 --- /dev/null +++ b/Algorithm-visualizer/AST/decision.cpp @@ -0,0 +1,6 @@ +#include "decision.hpp" + +Decision::Decision() +{ + +} diff --git a/Algorithm-visualizer/AST/decision.hpp b/Algorithm-visualizer/AST/decision.hpp new file mode 100644 index 0000000..601cd7e --- /dev/null +++ b/Algorithm-visualizer/AST/decision.hpp @@ -0,0 +1,58 @@ + +#include "expression.hpp" +#include "statement.hpp" +#include "ast.hpp" +#ifndef DECISION_HPP +#define DECISION_HPP + +//enum var_type { +// unknown_var_type = 0, +// string = 1, +// integer = 2, +// character = 3, +// floating_point = 4 + +//}; + +//enum un_op { +// unknown_un_op = 0, +// negation = 1, +// plusplus = 2 +// //inverse = 2 (if we add this as a unary operation for number -> -number) +//}; + +//enum bin_op { +// unknown_bin_op = 0, +// conjunction = 1, +// disjunction = 2, +// addition = 3, +// subtraction = 4, +// multiplication = 5, +// division = 6, +// lthan = 7, +// mthan = 8, +// leq = 9, +// meq = 10, +// eq = 11, +// eqeq = 12 +//}; + +//enum jump_type { +// unknown_jump_type = 0, +// br = 1, +// cont = 2 +//}; +//enum expression_type { +// unknown_expression_type = 0 +//}; + + +class Decision : public Statement { + Decision(); + ~Decision(); + void set_condition(Expression* c){condition = c;}; + std::string get_subtype(){return "Decision";}; +private: + Expression* condition; +}; +#endif // DECISION_HPP diff --git a/Algorithm-visualizer/AST/declaration.cpp b/Algorithm-visualizer/AST/declaration.cpp new file mode 100644 index 0000000..6d58d50 --- /dev/null +++ b/Algorithm-visualizer/AST/declaration.cpp @@ -0,0 +1,6 @@ +#include "declaration.hpp" + +Declaration::Declaration() +{ + +} diff --git a/Algorithm-visualizer/AST/declaration.hpp b/Algorithm-visualizer/AST/declaration.hpp new file mode 100644 index 0000000..e817410 --- /dev/null +++ b/Algorithm-visualizer/AST/declaration.hpp @@ -0,0 +1,76 @@ +#include "ast.hpp" +#include "statement.hpp" +#ifndef DECLARATION_HPP +#define DECLARATION_HPP + + +//enum var_type { +// unknown_var_type = 0, +// string = 1, +// integer = 2, +// character = 3, +// floating_point = 4 + +//}; + +//enum un_op { +// unknown_un_op = 0, +// negation = 1, +// plusplus = 2 +// //inverse = 2 (if we add this as a unary operation for number -> -number) +//}; + +//enum bin_op { +// unknown_bin_op = 0, +// conjunction = 1, +// disjunction = 2, +// addition = 3, +// subtraction = 4, +// multiplication = 5, +// division = 6, +// lthan = 7, +// mthan = 8, +// leq = 9, +// meq = 10, +// eq = 11, +// eqeq = 12 +//}; + +//enum jump_type { +// unknown_jump_type = 0, +// br = 1, +// cont = 2 +//}; +//enum expression_type { +// unknown_expression_type = 0 +//}; + + +class Declaration : public Statement { +public: + Declaration(); + ~Declaration(); + void set_var_type(var_type t){type = t;}; + std::string get_var_type(){ + switch(type) { + case 0: return "unknown variable type"; + case 1: return "string"; + case 2: return "integer"; + case 3: return "char"; + case 4: return "floating_point"; + } + } + char get_value(){return value;}; + void set_value(char v){value = v;}; + std::string get_subtype(){return "Declaration";}; + + +private: + var_type type = unknown_var_type; + char value; + //int x = 7, bool y = False + //attributes: + //name + value of the variable or Variable + sth +}; + +#endif // DECLARATION_HPP diff --git a/Algorithm-visualizer/AST/expression.cpp b/Algorithm-visualizer/AST/expression.cpp new file mode 100644 index 0000000..06f2b21 --- /dev/null +++ b/Algorithm-visualizer/AST/expression.cpp @@ -0,0 +1,6 @@ +#include "expression.hpp" + +Expression::Expression() +{ + +} diff --git a/Algorithm-visualizer/AST/expression.hpp b/Algorithm-visualizer/AST/expression.hpp new file mode 100644 index 0000000..a412131 --- /dev/null +++ b/Algorithm-visualizer/AST/expression.hpp @@ -0,0 +1,58 @@ +#include "ast.hpp" +#ifndef EXPRESSION_HPP +#define EXPRESSION_HPP + +//enum var_type { +// unknown_var_type = 0, +// string = 1, +// integer = 2, +// character = 3, +// floating_point = 4 + +//}; + +//enum un_op { +// unknown_un_op = 0, +// negation = 1, +// plusplus = 2 +// //inverse = 2 (if we add this as a unary operation for number -> -number) +//}; + +//enum bin_op { +// unknown_bin_op = 0, +// conjunction = 1, +// disjunction = 2, +// addition = 3, +// subtraction = 4, +// multiplication = 5, +// division = 6, +// lthan = 7, +// mthan = 8, +// leq = 9, +// meq = 10, +// eq = 11, +// eqeq = 12 +//}; + +//enum jump_type { +// unknown_jump_type = 0, +// br = 1, +// cont = 2 +//}; +//enum expression_type { +// unknown_expression_type = 0 +//}; + + +class Expression : public AST { +protected : Expression(); +protected : Expression(expression_type t) { + type = t; + }; + ~Expression(); +std::string get_type(){return "Expression";}; +private: + expression_type type = unknown_expression_type; +}; + +#endif // EXPRESSION_HPP diff --git a/Algorithm-visualizer/AST/ifelse.cpp b/Algorithm-visualizer/AST/ifelse.cpp new file mode 100644 index 0000000..af071aa --- /dev/null +++ b/Algorithm-visualizer/AST/ifelse.cpp @@ -0,0 +1,6 @@ +#include "ifelse.hpp" + +IfElse::IfElse() +{ + +} diff --git a/Algorithm-visualizer/AST/ifelse.hpp b/Algorithm-visualizer/AST/ifelse.hpp new file mode 100644 index 0000000..3395c9c --- /dev/null +++ b/Algorithm-visualizer/AST/ifelse.hpp @@ -0,0 +1,64 @@ +#include "assignment.hpp" +#include "decision.hpp" +#include "ifrest.hpp" +#include "ast.hpp" +#ifndef IFELSE_HPP +#define IFELSE_HPP + +//enum var_type { +// unknown_var_type = 0, +// string = 1, +// integer = 2, +// character = 3, +// floating_point = 4 + +//}; + +//enum un_op { +// unknown_un_op = 0, +// negation = 1, +// plusplus = 2 +// //inverse = 2 (if we add this as a unary operation for number -> -number) +//}; + +//enum bin_op { +// unknown_bin_op = 0, +// conjunction = 1, +// disjunction = 2, +// addition = 3, +// subtraction = 4, +// multiplication = 5, +// division = 6, +// lthan = 7, +// mthan = 8, +// leq = 9, +// meq = 10, +// eq = 11, +// eqeq = 12 +//}; + +//enum jump_type { +// unknown_jump_type = 0, +// br = 1, +// cont = 2 +//}; +//enum expression_type { +// unknown_expression_type = 0 +//}; + + +class IfElse : public Decision { + IfElse(); + ~IfElse(); + //attributes: condition(expression), IfRest + void set_condition(Expression* c){condition = c;}; + Expression* get_condition(){return condition;}; + void set_else_stmt(IfRest* stmt){else_stmt = stmt;}; + IfRest* get_else_stmt(){return else_stmt;}; + std::string get_subtype(){return "IfElse";}; +private: + Expression* condition; + IfRest* else_stmt; +}; + +#endif // IFELSE_HPP diff --git a/Algorithm-visualizer/AST/ifrest.cpp b/Algorithm-visualizer/AST/ifrest.cpp new file mode 100644 index 0000000..73b1ea0 --- /dev/null +++ b/Algorithm-visualizer/AST/ifrest.cpp @@ -0,0 +1,6 @@ +#include "ifrest.h" + +IfRest::IfRest() +{ + +} diff --git a/Algorithm-visualizer/AST/ifrest.hpp b/Algorithm-visualizer/AST/ifrest.hpp new file mode 100644 index 0000000..1ff4455 --- /dev/null +++ b/Algorithm-visualizer/AST/ifrest.hpp @@ -0,0 +1,60 @@ +#include "block.hpp" +#include "ast.hpp" +#ifndef IFREST_H +#define IFREST_H + +//enum var_type { +// unknown_var_type = 0, +// string = 1, +// integer = 2, +// character = 3, +// floating_point = 4 + +//}; + +//enum un_op { +// unknown_un_op = 0, +// negation = 1, +// plusplus = 2 +// //inverse = 2 (if we add this as a unary operation for number -> -number) +//}; + +//enum bin_op { +// unknown_bin_op = 0, +// conjunction = 1, +// disjunction = 2, +// addition = 3, +// subtraction = 4, +// multiplication = 5, +// division = 6, +// lthan = 7, +// mthan = 8, +// leq = 9, +// meq = 10, +// eq = 11, +// eqeq = 12 +//}; + +//enum jump_type { +// unknown_jump_type = 0, +// br = 1, +// cont = 2 +//}; +//enum expression_type { +// unknown_expression_type = 0 +//}; + + + +class IfRest : public Statement { +public: + IfRest(); + ~IfRest(); + Block* get_block_stmt(){return block_stmt;}; + void set_block_stmt(Block* stmt){block_stmt = stmt;}; + std::string get_subtype(){return "IfRest";}; +private: + Block* block_stmt; +}; + +#endif // IFREST_H diff --git a/Algorithm-visualizer/AST/jump.cpp b/Algorithm-visualizer/AST/jump.cpp new file mode 100644 index 0000000..2b8cbcb --- /dev/null +++ b/Algorithm-visualizer/AST/jump.cpp @@ -0,0 +1,6 @@ +#include "jump.hpp" + +Jump::Jump() +{ + +} diff --git a/Algorithm-visualizer/AST/jump.hpp b/Algorithm-visualizer/AST/jump.hpp new file mode 100644 index 0000000..ae08b24 --- /dev/null +++ b/Algorithm-visualizer/AST/jump.hpp @@ -0,0 +1,66 @@ +#include "statement.hpp" +#include "ast.hpp" +#ifndef JUMP_HPP +#define JUMP_HPP + +//enum var_type { +// unknown_var_type = 0, +// string = 1, +// integer = 2, +// character = 3, +// floating_point = 4 + +//}; + +//enum un_op { +// unknown_un_op = 0, +// negation = 1, +// plusplus = 2 +// //inverse = 2 (if we add this as a unary operation for number -> -number) +//}; + +//enum bin_op { +// unknown_bin_op = 0, +// conjunction = 1, +// disjunction = 2, +// addition = 3, +// subtraction = 4, +// multiplication = 5, +// division = 6, +// lthan = 7, +// mthan = 8, +// leq = 9, +// meq = 10, +// eq = 11, +// eqeq = 12 +//}; + +//enum jump_type { +// unknown_jump_type = 0, +// br = 1, +// cont = 2 +//}; +//enum expression_type { +// unknown_expression_type = 0 +//}; + + +class Jump : public Statement { + Jump(); + Jump(char value); + ~Jump(); + void set_value(jump_type v){value = v;}; + std::string get_value(){ + switch(value) { + case 0: return "unknown jump type"; + case 1: return "break"; + case 2: return "continue"; + } + }; + std::string get_subtype(){return "Jump";}; +private: + jump_type value = unknown_jump_type; +}; + + +#endif // JUMP_HPP diff --git a/Algorithm-visualizer/AST/print.cpp b/Algorithm-visualizer/AST/print.cpp new file mode 100644 index 0000000..b654672 --- /dev/null +++ b/Algorithm-visualizer/AST/print.cpp @@ -0,0 +1,6 @@ +#include "print.hpp" + +Print::Print() +{ + +} diff --git a/Algorithm-visualizer/AST/print.hpp b/Algorithm-visualizer/AST/print.hpp new file mode 100644 index 0000000..f6cd901 --- /dev/null +++ b/Algorithm-visualizer/AST/print.hpp @@ -0,0 +1,59 @@ +#include "statement.hpp" +#include "expression.hpp" +#include "ast.hpp" +#ifndef PRINT_HPP +#define PRINT_HPP + +//enum var_type { +// unknown_var_type = 0, +// string = 1, +// integer = 2, +// character = 3, +// floating_point = 4 + +//}; + +//enum un_op { +// unknown_un_op = 0, +// negation = 1, +// plusplus = 2 +// //inverse = 2 (if we add this as a unary operation for number -> -number) +//}; + +//enum bin_op { +// unknown_bin_op = 0, +// conjunction = 1, +// disjunction = 2, +// addition = 3, +// subtraction = 4, +// multiplication = 5, +// division = 6, +// lthan = 7, +// mthan = 8, +// leq = 9, +// meq = 10, +// eq = 11, +// eqeq = 12 +//}; + +//enum jump_type { +// unknown_jump_type = 0, +// br = 1, +// cont = 2 +//}; +//enum expression_type { +// unknown_expression_type = 0 +//}; + + +class Print : public Statement { + Print(); + ~Print(); + void set_exp(Expression* e){exp = e;}; + Expression* get_exp(){return exp;}; + std::string get_subtype(){return "Print";}; +private: + Expression* exp; +}; + +#endif // PRINT_HPP diff --git a/Algorithm-visualizer/AST/statement.cpp b/Algorithm-visualizer/AST/statement.cpp new file mode 100644 index 0000000..8b60f6f --- /dev/null +++ b/Algorithm-visualizer/AST/statement.cpp @@ -0,0 +1,6 @@ +#include "statement.hpp" + +Statement::Statement() +{ + +} diff --git a/Algorithm-visualizer/AST/statement.hpp b/Algorithm-visualizer/AST/statement.hpp new file mode 100644 index 0000000..40e47bd --- /dev/null +++ b/Algorithm-visualizer/AST/statement.hpp @@ -0,0 +1,55 @@ +#include "ast.hpp" +#ifndef STATEMENT_HPP +#define STATEMENT_HPP + + +//enum var_type { +// unknown_var_type = 0, +// string = 1, +// integer = 2, +// character = 3, +// floating_point = 4 + +//}; + +//enum un_op { +// unknown_un_op = 0, +// negation = 1, +// plusplus = 2 +// //inverse = 2 (if we add this as a unary operation for number -> -number) +//}; + +//enum bin_op { +// unknown_bin_op = 0, +// conjunction = 1, +// disjunction = 2, +// addition = 3, +// subtraction = 4, +// multiplication = 5, +// division = 6, +// lthan = 7, +// mthan = 8, +// leq = 9, +// meq = 10, +// eq = 11, +// eqeq = 12 +//}; + +//enum jump_type { +// unknown_jump_type = 0, +// br = 1, +// cont = 2 +//}; +//enum expression_type { +// unknown_expression_type = 0 +//}; + +class Statement : public AST { +protected : Statement(); +protected : ~Statement(); +std::string get_type(){return "Statement";}; +}; + + + +#endif // STATEMENT_HPP diff --git a/Algorithm-visualizer/AST/unop.cpp b/Algorithm-visualizer/AST/unop.cpp new file mode 100644 index 0000000..2eaf41f --- /dev/null +++ b/Algorithm-visualizer/AST/unop.cpp @@ -0,0 +1,6 @@ +#include "unop.hpp" + +UnOp::UnOp() +{ + +} diff --git a/Algorithm-visualizer/AST/unop.hpp b/Algorithm-visualizer/AST/unop.hpp new file mode 100644 index 0000000..b0bf19c --- /dev/null +++ b/Algorithm-visualizer/AST/unop.hpp @@ -0,0 +1,59 @@ +#include "expression.hpp" +#include "ast.hpp" +#ifndef UNOP_HPP +#define UNOP_HPP + +//enum var_type { +// unknown_var_type = 0, +// string = 1, +// integer = 2, +// character = 3, +// floating_point = 4 + +//}; + +//enum un_op { +// unknown_un_op = 0, +// negation = 1, +// plusplus = 2 +// //inverse = 2 (if we add this as a unary operation for number -> -number) +//}; + +//enum bin_op { +// unknown_bin_op = 0, +// conjunction = 1, +// disjunction = 2, +// addition = 3, +// subtraction = 4, +// multiplication = 5, +// division = 6, +// lthan = 7, +// mthan = 8, +// leq = 9, +// meq = 10, +// eq = 11, +// eqeq = 12 +//}; + +//enum jump_type { +// unknown_jump_type = 0, +// br = 1, +// cont = 2 +//}; +//enum expression_type { +// unknown_expression_type = 0 +//}; + +class UnOp : public Expression { + UnOp(); + ~UnOp(); + void set_operation(un_op op){operation = op;}; + void set_expression(Expression* e){expression = e;}; + un_op get_operation(){return operation;}; + Expression* get_expression(){return expression;}; + std::string get_subtype(){return "UnOp";}; +private: + un_op operation = unknown_un_op; + Expression* expression; +}; +#endif // UNOP_HPP diff --git a/Algorithm-visualizer/AST/variable.cpp b/Algorithm-visualizer/AST/variable.cpp new file mode 100644 index 0000000..d874ee2 --- /dev/null +++ b/Algorithm-visualizer/AST/variable.cpp @@ -0,0 +1,6 @@ +#include "variable.hpp" + +Variable::Variable() +{ + +} diff --git a/Algorithm-visualizer/AST/variable.hpp b/Algorithm-visualizer/AST/variable.hpp new file mode 100644 index 0000000..0e69133 --- /dev/null +++ b/Algorithm-visualizer/AST/variable.hpp @@ -0,0 +1,21 @@ +#include "expression.hpp" +#include "ast.hpp" +#ifndef VARIABLE_HPP +#define VARIABLE_HPP + + +class Variable : public Expression { + Variable(); + ~Variable(); + void set_name(char n){name = n;}; + void set_type(var_type t){type = t;}; + std::string get_name(){return name;}; + var_type get_var_type(){return type;}; + std::string get_subtype(){return "Variable";}; + +private: + std::string name; + var_type type = unknown_var_type; +}; + +#endif // VARIABLE_HPP diff --git a/Algorithm-visualizer/AST/while.cpp b/Algorithm-visualizer/AST/while.cpp new file mode 100644 index 0000000..1f64951 --- /dev/null +++ b/Algorithm-visualizer/AST/while.cpp @@ -0,0 +1,6 @@ +#include "while.hpp" + +While::While() +{ + +} diff --git a/Algorithm-visualizer/AST/while.hpp b/Algorithm-visualizer/AST/while.hpp new file mode 100644 index 0000000..9b23a86 --- /dev/null +++ b/Algorithm-visualizer/AST/while.hpp @@ -0,0 +1,64 @@ +#include "decision.hpp" +#include "block.hpp" +#include "ast.hpp" +#ifndef WHILE_HPP +#define WHILE_HPP + +//enum var_type { +// unknown_var_type = 0, +// string = 1, +// integer = 2, +// character = 3, +// floating_point = 4 + +//}; + +//enum un_op { +// unknown_un_op = 0, +// negation = 1, +// plusplus = 2 +// //inverse = 2 (if we add this as a unary operation for number -> -number) +//}; + +//enum bin_op { +// unknown_bin_op = 0, +// conjunction = 1, +// disjunction = 2, +// addition = 3, +// subtraction = 4, +// multiplication = 5, +// division = 6, +// lthan = 7, +// mthan = 8, +// leq = 9, +// meq = 10, +// eq = 11, +// eqeq = 12 +//}; + +//enum jump_type { +// unknown_jump_type = 0, +// br = 1, +// cont = 2 +//}; +//enum expression_type { +// unknown_expression_type = 0 +//}; + + +class While : public Decision { +public: + While(); + ~While(); + void set_condition(Expression* c){condition = c;}; + Expression* get_condition(){return condition;}; + Block* get_block_stmt(){return block_stmt;}; + void set_block_stmt(Block* stmt){block_stmt = stmt;}; + std::string get_subtype(){return "While";}; + //attributes: condition, block +private: + Expression* condition; + Block* block_stmt; +}; + +#endif // WHILE_HPP diff --git a/Algorithm-visualizer/Algorithm-visualizer.pro b/Algorithm-visualizer/Algorithm-visualizer.pro index 46d4090..01e9d92 100644 --- a/Algorithm-visualizer/Algorithm-visualizer.pro +++ b/Algorithm-visualizer/Algorithm-visualizer.pro @@ -9,7 +9,23 @@ CONFIG += c++11 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ + AST/assignment.cpp \ AST/ast.cpp \ + AST/binop.cpp \ + AST/block.cpp \ + AST/boolean.cpp \ + AST/class.cpp \ + AST/decision.cpp \ + AST/declaration.cpp \ + AST/expression.cpp \ + AST/ifelse.cpp \ + AST/ifrest.cpp \ + AST/jump.cpp \ + AST/print.cpp \ + AST/statement.cpp \ + AST/unop.cpp \ + AST/variable.cpp \ + AST/while.cpp \ GUI/codecell.cpp \ GUI/gui.cpp \ GUI/varcell.cpp \ @@ -19,7 +35,23 @@ SOURCES += \ mainwindow.cpp HEADERS += \ + AST/assignment.hpp \ AST/ast.hpp \ + AST/binop.hpp \ + AST/block.hpp \ + AST/boolean.hpp \ + AST/class.hpp \ + AST/decision.hpp \ + AST/declaration.hpp \ + AST/expression.hpp \ + AST/ifelse.hpp \ + AST/ifrest.hpp \ + AST/jump.hpp \ + AST/print.hpp \ + AST/statement.hpp \ + AST/unop.hpp \ + AST/variable.hpp \ + AST/while.hpp \ GUI/codecell.h \ GUI/gui.hpp \ GUI/varcell.h \ From 84aa5f4b26e5ead080ecb7ea1a3ba393a6740742 Mon Sep 17 00:00:00 2001 From: milenanedeljkovic <80540793+milenanedeljkovic@users.noreply.github.com> Date: Sun, 21 Nov 2021 14:10:06 +0100 Subject: [PATCH 25/43] Create week 3 - personal report for elena to put into the group week 3 report --- Reports/week 3 - personal report | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Reports/week 3 - personal report diff --git a/Reports/week 3 - personal report b/Reports/week 3 - personal report new file mode 100644 index 0000000..0a2aa20 --- /dev/null +++ b/Reports/week 3 - personal report @@ -0,0 +1,4 @@ +This week wes dedicated to finalizing the AST classes so that they are ready to be used. OUr work had to be manually merged which me and Matea finished at the TD. +We now have a good basis to conitnue working on the interpreter. I communicated with the GUI team about creating test ASTs. +Writing the interpreter and the tests are the main goals for my team for the next week. +Creating the AST from the parsing tree wes handed over to Team 1 and I have their group leader the explanation of our classes. From 6c8c3bc85a7cf6dcf690538a08eceb64bac86cb9 Mon Sep 17 00:00:00 2001 From: evdokia0 <83377179+evdokia0@users.noreply.github.com> Date: Sun, 21 Nov 2021 19:11:24 +0100 Subject: [PATCH 26/43] Update ast.hpp --- Algorithm-visualizer/AST/ast.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Algorithm-visualizer/AST/ast.hpp b/Algorithm-visualizer/AST/ast.hpp index 7e1958d..d063c86 100644 --- a/Algorithm-visualizer/AST/ast.hpp +++ b/Algorithm-visualizer/AST/ast.hpp @@ -6,8 +6,6 @@ #include using namespace std; -using namespace std; - enum var_type { unknown_var_type = 0, string = 1, From 3b7aa5e87a432c7b0b6032a1da237b0e8bf241f1 Mon Sep 17 00:00:00 2001 From: goranovic37 <91254922+goranovic37@users.noreply.github.com> Date: Mon, 22 Nov 2021 10:09:33 +0100 Subject: [PATCH 27/43] Update project_design.md --- doc/project_design.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/project_design.md b/doc/project_design.md index 26d2c56..9ea41ac 100644 --- a/doc/project_design.md +++ b/doc/project_design.md @@ -16,7 +16,7 @@ Algorithm Visualizer will be a tool where user will be able to input C++ code in - How are you sub-dividing your project? Which modules are you implementing? -We will have one team working on making the parser. Basically, this team will, in the first stage of the project define initial tokens and “grammar” we will use. With help of the library, they will allow the lexical analysis of the code typed by the user (that will have restrictions we will talk later about). After making the parser, this team will work on advanced functionalities and potentially help GUI team. +We will have one team working on making the parser and the AST. Basically, this team will, in the first stage of the project define initial tokens and “grammar” we will use. With help of the library ANTLR4, they will allow the lexical analysis and parsing of the code typed by the user (that will have restrictions we will talk later about). After making the parser, this team will create from the parse tree the AST. The other team will, in the first time, be working on creating the signatures of the classes inheritance for grammar we use and writing methods that wil be used for merging backend with GUI. In the second time, this team will be wokring on the interpreter that will work with AST and allow our varCell to interpret state of variables. Last but not the least, the GUI team will firstly learn basics of QtGraphics and then create simple version of the mainwindow. In the second part of the project, GUI team will work on merging graphics with the backend. - What is the interface of each module? @@ -24,7 +24,7 @@ We will have one team working on making the parser. Basically, this team will, i - What external dependencies do you have? Why? -We will use a library during the lexing process and for now that seems to be the only external dependency we have. +We will use a library during the lexing process and parsing. The library we use is ANTLR4. ## Initial grammar we defined: @@ -43,3 +43,4 @@ We will use a library during the lexing process and for now that seems to be the + From fef315997e217a8242eae2129137ea92fdfc6493 Mon Sep 17 00:00:00 2001 From: goranovic37 <91254922+goranovic37@users.noreply.github.com> Date: Mon, 22 Nov 2021 10:12:42 +0100 Subject: [PATCH 28/43] Update reports.md Workspace up to date w reports --- Reports/Week2/reports.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Reports/Week2/reports.md b/Reports/Week2/reports.md index a178980..e1d5129 100644 --- a/Reports/Week2/reports.md +++ b/Reports/Week2/reports.md @@ -1,17 +1,9 @@ # Week 2 - Reports #### Elena Mrdja -This week I worked on grasping all the necessary knowledge in Qt graphics we will need. As planned, I finished the Qt Graphics course we found, and I implemented the gathered skills through making a trial project where I created a main window with different shapes and their class methods, which will be of great help as I progress with coding the project. - -After everyone in GUI team was done with the course, I set up a meeting to decide on all the custom classes and the shape types we want to have in our project. When this was decided, I started coding the main window of our project's GUI, adding the classes and creating a simple structure we plan to build upon next week. Next week our goal is to finish the text editor cell and implement all the shapes we decided to use. - +This week I worked on grasping all the necessary knowledge in Qt graphics we will need. As planned, I finished the Qt Graphics course we found, and I implemented the gathered skills through making a trial project where I created a main window with different shapes and their class methods, which will be of great help as I progress with coding the project. +After everyone in GUI team was done with the course, I set up a meeting to decide on all the custom classes and the shape types we want to have in our project. When this was decided, I started coding the main window of our project's GUI, adding the classes and creating a simple structure we plan to build upon next week. Next week our goal is to finish the text editor cell and implement all the shapes we decided to use. As the git leader, I created a tutorial document with all of the important git hub commands, so that everyone was sure on how to use it, and was there to help my teammates out with any git hub problems. -This week I worked on grasping all the necessary knowledge in Qt graphics I will need to continue with the graphics part of the project. As planned, I finished the Qt Graphics course we found, and implemented the gathered skills through making a trial project where I created a main window with different shapes and their class methods, which will be of great help as I progress with coding the project. -After everyone in GUI team was done with the course, I set up a meeting to decide on all the custom classes and the shape types we want to have in our project. When this was decided, I started coding the main window of our project's GUI, adding the classes and creating a simple structure we plan to build upon next week. Next week our goal is to finish the text editor cell and implement all the shapes we decided to use. - -As the git leader, I created a common branch for all of us to collaborate, and made sure everyone has their own branch if they need it. I also created a tutorial document with all of the important git hub commands, so that everyone was sure on how to use it, and was there to help my teammates out with any git hub problems. - - #### Matea Gjika @@ -43,17 +35,25 @@ and we all need to give input into which attributes we need) #### Darya Todoskova During the second week, I did a more profound research on ANTLR, in order to know what output we will be receiving from Team 1. I also met a couple of times with my team to discuss our progress and to define specific tasks for each one of us to do. Indeed, I defined all the AST-inherited getters and setters in the ast.hpp file. Finally, I am currently trying to set up ANTLR on mac0S just like team 1, who has been trying to set it up on Windows. For the following week, I plan on refining our ast.hpp file and working on the exact output we are going to give to the GUI team, in order to make the transition smoother. - -#### John Levy - #### Evdokia Gneusheva This week Team 1 came up with the idea to use ANTLR library for parsing so as a member of Team 2 my job was to get familier with this library in order to be able to convert parser trees created by Team 1 into AST. Precisely, to convert a parser tree into AST we need to use ANTLR4 visitor. Thus, I accomplished an online tutorial on how to use visitor class. But also, the most importantly, Team 2 started defining AST by creating multiple classes in ast.hpp file (on Workspace branch), where I coded set() and get() methods for all classes inherited from Expression class. Next week I will continue working on AST classes and start the conversion of parser tree created by Team 1 into AST, as well as working on the output of our AST which we will pass to the Team 3. #### Stefan Vayl +Throughout the whole week I have been working on installation of ANTRL library. I have managed to install it on my computer even though there were many difficulties that I had to face. I managed to test this library on small grammar files that I found online. From those grammar files it created Lexer and Parser files. Although, there is still work to be done next week especially I am planning to find out how can I be using those automatically generated files in order to create parsing tree. #### Ekaterina Borisova +This week I have been working on installing ANTRLv.4 library. There were many ideas on how we should be implementing our backend but in the end we came to an understanding that ANTRL library should work well for our project. I have managed to install it on my computer and try to run it on different libraries including a C++ library. I have found some grammar files that I can use for testing and from which I managed to create tokens using the library. Next week I am planning to get better understanding on how to use this library in order to create parsing tree because right now I am struggling to get it. + #### Mina Goranovic +This week I found us resources and tutorial for antlr library the parsing team will use. I downloaded all of the needed setup for the library, but it is still not working. What I need to do next week is to learn how to get the graph output of the parse tree instead of the graphical representation. +Next, I finished the course on the Qt graphics and decided with the GUI team on how we want our main window to look like. +I made us a grammar file for parsing. +For next week I need to find out how exactly we will make an interpreter from AST that we will connect to flowchart elements. + +#### John Levy +This week, I completed my learning of the Qt Graphics and Qt Designer libraries. The whole GUI Team then met to decide the general aspect of our main window, we quickly identified some challenges that we would have to work on. We decided on the main classes we will use for the display of our visualization tree. +Next week, I plan on working a lot on the Text Editor part of our UI in order to display the algorithms as in a code developement environement, and decide on the final shapes we will use for the visualization cell in order to start their implementation. From 1d06ee2f5f2720051225ac5e03b4fee304225559 Mon Sep 17 00:00:00 2001 From: goranovic37 Date: Mon, 22 Nov 2021 11:07:45 +0100 Subject: [PATCH 29/43] setting up varcell --- Algorithm-visualizer/GUI/varcell.cpp | 19 ++++++++++++++++++- Algorithm-visualizer/GUI/varcell.h | 4 ++++ Algorithm-visualizer/mainwindow.cpp | 6 ++++++ Algorithm-visualizer/mainwindow.h | 15 ++++++++++++--- Algorithm-visualizer/mainwindow.ui | 18 +++++++++++++++++- 5 files changed, 57 insertions(+), 5 deletions(-) diff --git a/Algorithm-visualizer/GUI/varcell.cpp b/Algorithm-visualizer/GUI/varcell.cpp index a4c3209..81a04f2 100644 --- a/Algorithm-visualizer/GUI/varcell.cpp +++ b/Algorithm-visualizer/GUI/varcell.cpp @@ -1,6 +1,23 @@ -#include "varcell.h" + #include "varcell.h" VarCell::VarCell(QWidget *parent) : QGraphicsView(parent) { } + +void VarCell::wheelEvent(QWheelEvent *event) +{ + setTransformationAnchor(QGraphicsView::AnchorUnderMouse); + double scaleFactor = 1.15; + + if (event->delta() > 0) { + + scale(scaleFactor,scaleFactor); + } + + else { + + scale(1/scaleFactor,1/scaleFactor); + } + +} diff --git a/Algorithm-visualizer/GUI/varcell.h b/Algorithm-visualizer/GUI/varcell.h index c625e26..fa384ae 100644 --- a/Algorithm-visualizer/GUI/varcell.h +++ b/Algorithm-visualizer/GUI/varcell.h @@ -7,7 +7,11 @@ class VarCell : public QGraphicsView { +public: + VarCell(QWidget* parent = 0); +protected: + virtual void wheelEvent(QWheelEvent *event); }; #endif // VARCELL_H diff --git a/Algorithm-visualizer/mainwindow.cpp b/Algorithm-visualizer/mainwindow.cpp index 8f6a553..0c5b216 100644 --- a/Algorithm-visualizer/mainwindow.cpp +++ b/Algorithm-visualizer/mainwindow.cpp @@ -10,5 +10,11 @@ MainWindow::MainWindow(QWidget *parent) MainWindow::~MainWindow() { delete ui; + + //the following comm is if u want picture in the scrollable widget + //QImage image("path to the pciture"); + //item = new QGraphicsPixmapItem (QPixmap::fromImage(image)); + //scene = new QGraphicsScene(this); //it does make a problem with QgraphicsScene that is "not defined"? + } diff --git a/Algorithm-visualizer/mainwindow.h b/Algorithm-visualizer/mainwindow.h index c6efccc..0cc17f8 100644 --- a/Algorithm-visualizer/mainwindow.h +++ b/Algorithm-visualizer/mainwindow.h @@ -2,9 +2,9 @@ #define MAINWINDOW_H #include -#include -#include -#include +#include //for scrollable widgets +#include //for scrollable widgets +#include //for scrollable widgets #include "ui_mainwindow.h" QT_BEGIN_NAMESPACE @@ -22,6 +22,15 @@ class MainWindow : public QMainWindow private: Ui::MainWindow ui; + + //this can be added for including a photo in varcell scrollable + //QGraphicsItem *item; + //QGraphicsScene *scene; + //ui->graphicsView->setScene(scene); + //scene->addItem(item); + + + }; class Program { diff --git a/Algorithm-visualizer/mainwindow.ui b/Algorithm-visualizer/mainwindow.ui index ffe6676..6d7610c 100644 --- a/Algorithm-visualizer/mainwindow.ui +++ b/Algorithm-visualizer/mainwindow.ui @@ -25,7 +25,18 @@ - + + + + + 5 + 0 + 371 + 231 + + + + @@ -77,6 +88,11 @@
varcell.h
1 + + varcell + QGraphicsView +
varcell.h
+
From a128c6d052d8a4851af5d15e731110ae3f64989f Mon Sep 17 00:00:00 2001 From: milenanedeljkovic Date: Mon, 22 Nov 2021 13:29:24 +0100 Subject: [PATCH 30/43] edited comments, added number.hpp --- Algorithm-visualizer/AST/binop.hpp | 26 ----------- Algorithm-visualizer/AST/block.hpp | 42 ------------------ Algorithm-visualizer/AST/boolean.hpp | 42 ------------------ Algorithm-visualizer/AST/decision.hpp | 43 ------------------- Algorithm-visualizer/AST/declaration.hpp | 33 -------------- Algorithm-visualizer/AST/expression.hpp | 37 ---------------- Algorithm-visualizer/AST/ifelse.hpp | 42 ------------------ Algorithm-visualizer/AST/ifrest.hpp | 43 ------------------- Algorithm-visualizer/AST/number.hpp | 4 ++ Algorithm-visualizer/AST/print.hpp | 42 ------------------ Algorithm-visualizer/AST/statement.hpp | 42 ------------------ Algorithm-visualizer/AST/unop.hpp | 34 --------------- Algorithm-visualizer/AST/variable.hpp | 8 ++++ Algorithm-visualizer/AST/while.hpp | 42 ------------------ Algorithm-visualizer/Algorithm-visualizer.pro | 1 + 15 files changed, 13 insertions(+), 468 deletions(-) create mode 100644 Algorithm-visualizer/AST/number.hpp diff --git a/Algorithm-visualizer/AST/binop.hpp b/Algorithm-visualizer/AST/binop.hpp index bd9faaa..d39f0a9 100644 --- a/Algorithm-visualizer/AST/binop.hpp +++ b/Algorithm-visualizer/AST/binop.hpp @@ -4,22 +4,6 @@ #ifndef BINOP_HPP #define BINOP_HPP -//enum var_type { -// unknown_var_type = 0, -// string = 1, -// integer = 2, -// character = 3, -// floating_point = 4 - -//}; - -//enum un_op { -// unknown_un_op = 0, -// negation = 1, -// plusplus = 2 -// //inverse = 2 (if we add this as a unary operation for number -> -number) -//}; - //enum bin_op { // unknown_bin_op = 0, // conjunction = 1, @@ -36,16 +20,6 @@ // eqeq = 12 //}; -//enum jump_type { -// unknown_jump_type = 0, -// br = 1, -// cont = 2 -//}; -//enum expression_type { -// unknown_expression_type = 0 -//}; - - class BinOp : public Expression { BinOp(); ~BinOp(); diff --git a/Algorithm-visualizer/AST/block.hpp b/Algorithm-visualizer/AST/block.hpp index 2b99f99..bba2ff6 100644 --- a/Algorithm-visualizer/AST/block.hpp +++ b/Algorithm-visualizer/AST/block.hpp @@ -3,48 +3,6 @@ #ifndef BLOCK_HPP #define BLOCK_HPP -//enum var_type { -// unknown_var_type = 0, -// string = 1, -// integer = 2, -// character = 3, -// floating_point = 4 - -//}; - -//enum un_op { -// unknown_un_op = 0, -// negation = 1, -// plusplus = 2 -// //inverse = 2 (if we add this as a unary operation for number -> -number) -//}; - -//enum bin_op { -// unknown_bin_op = 0, -// conjunction = 1, -// disjunction = 2, -// addition = 3, -// subtraction = 4, -// multiplication = 5, -// division = 6, -// lthan = 7, -// mthan = 8, -// leq = 9, -// meq = 10, -// eq = 11, -// eqeq = 12 -//}; - -//enum jump_type { -// unknown_jump_type = 0, -// br = 1, -// cont = 2 -//}; -//enum expression_type { -// unknown_expression_type = 0 -//}; - - class Block : public Statement { protected : Block(); protected : ~Block(); diff --git a/Algorithm-visualizer/AST/boolean.hpp b/Algorithm-visualizer/AST/boolean.hpp index 89706a0..45efe98 100644 --- a/Algorithm-visualizer/AST/boolean.hpp +++ b/Algorithm-visualizer/AST/boolean.hpp @@ -4,48 +4,6 @@ #ifndef BOOLEAN_HPP #define BOOLEAN_HPP -//enum var_type { -// unknown_var_type = 0, -// string = 1, -// integer = 2, -// character = 3, -// floating_point = 4 - -//}; - -//enum un_op { -// unknown_un_op = 0, -// negation = 1, -// plusplus = 2 -// //inverse = 2 (if we add this as a unary operation for number -> -number) -//}; - -//enum bin_op { -// unknown_bin_op = 0, -// conjunction = 1, -// disjunction = 2, -// addition = 3, -// subtraction = 4, -// multiplication = 5, -// division = 6, -// lthan = 7, -// mthan = 8, -// leq = 9, -// meq = 10, -// eq = 11, -// eqeq = 12 -//}; - -//enum jump_type { -// unknown_jump_type = 0, -// br = 1, -// cont = 2 -//}; -//enum expression_type { -// unknown_expression_type = 0 -//}; - - class Boolean : public Expression { //not sure if this is necessary but putting //it down for now diff --git a/Algorithm-visualizer/AST/decision.hpp b/Algorithm-visualizer/AST/decision.hpp index 601cd7e..0bc6b93 100644 --- a/Algorithm-visualizer/AST/decision.hpp +++ b/Algorithm-visualizer/AST/decision.hpp @@ -1,52 +1,9 @@ - #include "expression.hpp" #include "statement.hpp" #include "ast.hpp" #ifndef DECISION_HPP #define DECISION_HPP -//enum var_type { -// unknown_var_type = 0, -// string = 1, -// integer = 2, -// character = 3, -// floating_point = 4 - -//}; - -//enum un_op { -// unknown_un_op = 0, -// negation = 1, -// plusplus = 2 -// //inverse = 2 (if we add this as a unary operation for number -> -number) -//}; - -//enum bin_op { -// unknown_bin_op = 0, -// conjunction = 1, -// disjunction = 2, -// addition = 3, -// subtraction = 4, -// multiplication = 5, -// division = 6, -// lthan = 7, -// mthan = 8, -// leq = 9, -// meq = 10, -// eq = 11, -// eqeq = 12 -//}; - -//enum jump_type { -// unknown_jump_type = 0, -// br = 1, -// cont = 2 -//}; -//enum expression_type { -// unknown_expression_type = 0 -//}; - - class Decision : public Statement { Decision(); ~Decision(); diff --git a/Algorithm-visualizer/AST/declaration.hpp b/Algorithm-visualizer/AST/declaration.hpp index e817410..7250107 100644 --- a/Algorithm-visualizer/AST/declaration.hpp +++ b/Algorithm-visualizer/AST/declaration.hpp @@ -13,39 +13,6 @@ //}; -//enum un_op { -// unknown_un_op = 0, -// negation = 1, -// plusplus = 2 -// //inverse = 2 (if we add this as a unary operation for number -> -number) -//}; - -//enum bin_op { -// unknown_bin_op = 0, -// conjunction = 1, -// disjunction = 2, -// addition = 3, -// subtraction = 4, -// multiplication = 5, -// division = 6, -// lthan = 7, -// mthan = 8, -// leq = 9, -// meq = 10, -// eq = 11, -// eqeq = 12 -//}; - -//enum jump_type { -// unknown_jump_type = 0, -// br = 1, -// cont = 2 -//}; -//enum expression_type { -// unknown_expression_type = 0 -//}; - - class Declaration : public Statement { public: Declaration(); diff --git a/Algorithm-visualizer/AST/expression.hpp b/Algorithm-visualizer/AST/expression.hpp index a412131..68d3d37 100644 --- a/Algorithm-visualizer/AST/expression.hpp +++ b/Algorithm-visualizer/AST/expression.hpp @@ -2,43 +2,6 @@ #ifndef EXPRESSION_HPP #define EXPRESSION_HPP -//enum var_type { -// unknown_var_type = 0, -// string = 1, -// integer = 2, -// character = 3, -// floating_point = 4 - -//}; - -//enum un_op { -// unknown_un_op = 0, -// negation = 1, -// plusplus = 2 -// //inverse = 2 (if we add this as a unary operation for number -> -number) -//}; - -//enum bin_op { -// unknown_bin_op = 0, -// conjunction = 1, -// disjunction = 2, -// addition = 3, -// subtraction = 4, -// multiplication = 5, -// division = 6, -// lthan = 7, -// mthan = 8, -// leq = 9, -// meq = 10, -// eq = 11, -// eqeq = 12 -//}; - -//enum jump_type { -// unknown_jump_type = 0, -// br = 1, -// cont = 2 -//}; //enum expression_type { // unknown_expression_type = 0 //}; diff --git a/Algorithm-visualizer/AST/ifelse.hpp b/Algorithm-visualizer/AST/ifelse.hpp index 3395c9c..b8ce871 100644 --- a/Algorithm-visualizer/AST/ifelse.hpp +++ b/Algorithm-visualizer/AST/ifelse.hpp @@ -5,48 +5,6 @@ #ifndef IFELSE_HPP #define IFELSE_HPP -//enum var_type { -// unknown_var_type = 0, -// string = 1, -// integer = 2, -// character = 3, -// floating_point = 4 - -//}; - -//enum un_op { -// unknown_un_op = 0, -// negation = 1, -// plusplus = 2 -// //inverse = 2 (if we add this as a unary operation for number -> -number) -//}; - -//enum bin_op { -// unknown_bin_op = 0, -// conjunction = 1, -// disjunction = 2, -// addition = 3, -// subtraction = 4, -// multiplication = 5, -// division = 6, -// lthan = 7, -// mthan = 8, -// leq = 9, -// meq = 10, -// eq = 11, -// eqeq = 12 -//}; - -//enum jump_type { -// unknown_jump_type = 0, -// br = 1, -// cont = 2 -//}; -//enum expression_type { -// unknown_expression_type = 0 -//}; - - class IfElse : public Decision { IfElse(); ~IfElse(); diff --git a/Algorithm-visualizer/AST/ifrest.hpp b/Algorithm-visualizer/AST/ifrest.hpp index 1ff4455..c428b2c 100644 --- a/Algorithm-visualizer/AST/ifrest.hpp +++ b/Algorithm-visualizer/AST/ifrest.hpp @@ -3,49 +3,6 @@ #ifndef IFREST_H #define IFREST_H -//enum var_type { -// unknown_var_type = 0, -// string = 1, -// integer = 2, -// character = 3, -// floating_point = 4 - -//}; - -//enum un_op { -// unknown_un_op = 0, -// negation = 1, -// plusplus = 2 -// //inverse = 2 (if we add this as a unary operation for number -> -number) -//}; - -//enum bin_op { -// unknown_bin_op = 0, -// conjunction = 1, -// disjunction = 2, -// addition = 3, -// subtraction = 4, -// multiplication = 5, -// division = 6, -// lthan = 7, -// mthan = 8, -// leq = 9, -// meq = 10, -// eq = 11, -// eqeq = 12 -//}; - -//enum jump_type { -// unknown_jump_type = 0, -// br = 1, -// cont = 2 -//}; -//enum expression_type { -// unknown_expression_type = 0 -//}; - - - class IfRest : public Statement { public: IfRest(); diff --git a/Algorithm-visualizer/AST/number.hpp b/Algorithm-visualizer/AST/number.hpp new file mode 100644 index 0000000..c1c3c6b --- /dev/null +++ b/Algorithm-visualizer/AST/number.hpp @@ -0,0 +1,4 @@ +#ifndef NUMBER_HPP +#define NUMBER_HPP + +#endif // NUMBER_HPP diff --git a/Algorithm-visualizer/AST/print.hpp b/Algorithm-visualizer/AST/print.hpp index f6cd901..a9c4276 100644 --- a/Algorithm-visualizer/AST/print.hpp +++ b/Algorithm-visualizer/AST/print.hpp @@ -4,48 +4,6 @@ #ifndef PRINT_HPP #define PRINT_HPP -//enum var_type { -// unknown_var_type = 0, -// string = 1, -// integer = 2, -// character = 3, -// floating_point = 4 - -//}; - -//enum un_op { -// unknown_un_op = 0, -// negation = 1, -// plusplus = 2 -// //inverse = 2 (if we add this as a unary operation for number -> -number) -//}; - -//enum bin_op { -// unknown_bin_op = 0, -// conjunction = 1, -// disjunction = 2, -// addition = 3, -// subtraction = 4, -// multiplication = 5, -// division = 6, -// lthan = 7, -// mthan = 8, -// leq = 9, -// meq = 10, -// eq = 11, -// eqeq = 12 -//}; - -//enum jump_type { -// unknown_jump_type = 0, -// br = 1, -// cont = 2 -//}; -//enum expression_type { -// unknown_expression_type = 0 -//}; - - class Print : public Statement { Print(); ~Print(); diff --git a/Algorithm-visualizer/AST/statement.hpp b/Algorithm-visualizer/AST/statement.hpp index 40e47bd..8cbb95e 100644 --- a/Algorithm-visualizer/AST/statement.hpp +++ b/Algorithm-visualizer/AST/statement.hpp @@ -2,48 +2,6 @@ #ifndef STATEMENT_HPP #define STATEMENT_HPP - -//enum var_type { -// unknown_var_type = 0, -// string = 1, -// integer = 2, -// character = 3, -// floating_point = 4 - -//}; - -//enum un_op { -// unknown_un_op = 0, -// negation = 1, -// plusplus = 2 -// //inverse = 2 (if we add this as a unary operation for number -> -number) -//}; - -//enum bin_op { -// unknown_bin_op = 0, -// conjunction = 1, -// disjunction = 2, -// addition = 3, -// subtraction = 4, -// multiplication = 5, -// division = 6, -// lthan = 7, -// mthan = 8, -// leq = 9, -// meq = 10, -// eq = 11, -// eqeq = 12 -//}; - -//enum jump_type { -// unknown_jump_type = 0, -// br = 1, -// cont = 2 -//}; -//enum expression_type { -// unknown_expression_type = 0 -//}; - class Statement : public AST { protected : Statement(); protected : ~Statement(); diff --git a/Algorithm-visualizer/AST/unop.hpp b/Algorithm-visualizer/AST/unop.hpp index b0bf19c..7ab920e 100644 --- a/Algorithm-visualizer/AST/unop.hpp +++ b/Algorithm-visualizer/AST/unop.hpp @@ -3,15 +3,6 @@ #ifndef UNOP_HPP #define UNOP_HPP -//enum var_type { -// unknown_var_type = 0, -// string = 1, -// integer = 2, -// character = 3, -// floating_point = 4 - -//}; - //enum un_op { // unknown_un_op = 0, // negation = 1, @@ -19,31 +10,6 @@ // //inverse = 2 (if we add this as a unary operation for number -> -number) //}; -//enum bin_op { -// unknown_bin_op = 0, -// conjunction = 1, -// disjunction = 2, -// addition = 3, -// subtraction = 4, -// multiplication = 5, -// division = 6, -// lthan = 7, -// mthan = 8, -// leq = 9, -// meq = 10, -// eq = 11, -// eqeq = 12 -//}; - -//enum jump_type { -// unknown_jump_type = 0, -// br = 1, -// cont = 2 -//}; -//enum expression_type { -// unknown_expression_type = 0 -//}; - class UnOp : public Expression { UnOp(); ~UnOp(); diff --git a/Algorithm-visualizer/AST/variable.hpp b/Algorithm-visualizer/AST/variable.hpp index 0e69133..75b5edd 100644 --- a/Algorithm-visualizer/AST/variable.hpp +++ b/Algorithm-visualizer/AST/variable.hpp @@ -3,6 +3,14 @@ #ifndef VARIABLE_HPP #define VARIABLE_HPP +/* enum var_type { + unknown_var_type = 0, + string = 1, + integer = 2, + character = 3, + floating_point = 4 + +}; */ class Variable : public Expression { Variable(); diff --git a/Algorithm-visualizer/AST/while.hpp b/Algorithm-visualizer/AST/while.hpp index 9b23a86..b5721b1 100644 --- a/Algorithm-visualizer/AST/while.hpp +++ b/Algorithm-visualizer/AST/while.hpp @@ -4,48 +4,6 @@ #ifndef WHILE_HPP #define WHILE_HPP -//enum var_type { -// unknown_var_type = 0, -// string = 1, -// integer = 2, -// character = 3, -// floating_point = 4 - -//}; - -//enum un_op { -// unknown_un_op = 0, -// negation = 1, -// plusplus = 2 -// //inverse = 2 (if we add this as a unary operation for number -> -number) -//}; - -//enum bin_op { -// unknown_bin_op = 0, -// conjunction = 1, -// disjunction = 2, -// addition = 3, -// subtraction = 4, -// multiplication = 5, -// division = 6, -// lthan = 7, -// mthan = 8, -// leq = 9, -// meq = 10, -// eq = 11, -// eqeq = 12 -//}; - -//enum jump_type { -// unknown_jump_type = 0, -// br = 1, -// cont = 2 -//}; -//enum expression_type { -// unknown_expression_type = 0 -//}; - - class While : public Decision { public: While(); diff --git a/Algorithm-visualizer/Algorithm-visualizer.pro b/Algorithm-visualizer/Algorithm-visualizer.pro index 01e9d92..726dab1 100644 --- a/Algorithm-visualizer/Algorithm-visualizer.pro +++ b/Algorithm-visualizer/Algorithm-visualizer.pro @@ -47,6 +47,7 @@ HEADERS += \ AST/ifelse.hpp \ AST/ifrest.hpp \ AST/jump.hpp \ + AST/number.hpp \ AST/print.hpp \ AST/statement.hpp \ AST/unop.hpp \ From 2d22ce8e00090b8a823be5a9db2d3ea2f1ceb59f Mon Sep 17 00:00:00 2001 From: milenanedeljkovic Date: Mon, 22 Nov 2021 13:36:31 +0100 Subject: [PATCH 31/43] number + comment changes --- Algorithm-visualizer/AST/class.hpp | 42 ----------------------------- Algorithm-visualizer/AST/jump.hpp | 32 ---------------------- Algorithm-visualizer/AST/number.hpp | 19 +++++++++++++ 3 files changed, 19 insertions(+), 74 deletions(-) diff --git a/Algorithm-visualizer/AST/class.hpp b/Algorithm-visualizer/AST/class.hpp index 698b843..9438d2b 100644 --- a/Algorithm-visualizer/AST/class.hpp +++ b/Algorithm-visualizer/AST/class.hpp @@ -5,48 +5,6 @@ #ifndef CLASS_HPP #define CLASS_HPP -//enum var_type { -// unknown_var_type = 0, -// string = 1, -// integer = 2, -// character = 3, -// floating_point = 4 - -//}; - -//enum un_op { -// unknown_un_op = 0, -// negation = 1, -// plusplus = 2 -// //inverse = 2 (if we add this as a unary operation for number -> -number) -//}; - -//enum bin_op { -// unknown_bin_op = 0, -// conjunction = 1, -// disjunction = 2, -// addition = 3, -// subtraction = 4, -// multiplication = 5, -// division = 6, -// lthan = 7, -// mthan = 8, -// leq = 9, -// meq = 10, -// eq = 11, -// eqeq = 12 -//}; - -//enum jump_type { -// unknown_jump_type = 0, -// br = 1, -// cont = 2 -//}; -//enum expression_type { -// unknown_expression_type = 0 -//}; - - class Return : public Statement { Return(); ~Return(); diff --git a/Algorithm-visualizer/AST/jump.hpp b/Algorithm-visualizer/AST/jump.hpp index ae08b24..3e2aa2e 100644 --- a/Algorithm-visualizer/AST/jump.hpp +++ b/Algorithm-visualizer/AST/jump.hpp @@ -3,38 +3,6 @@ #ifndef JUMP_HPP #define JUMP_HPP -//enum var_type { -// unknown_var_type = 0, -// string = 1, -// integer = 2, -// character = 3, -// floating_point = 4 - -//}; - -//enum un_op { -// unknown_un_op = 0, -// negation = 1, -// plusplus = 2 -// //inverse = 2 (if we add this as a unary operation for number -> -number) -//}; - -//enum bin_op { -// unknown_bin_op = 0, -// conjunction = 1, -// disjunction = 2, -// addition = 3, -// subtraction = 4, -// multiplication = 5, -// division = 6, -// lthan = 7, -// mthan = 8, -// leq = 9, -// meq = 10, -// eq = 11, -// eqeq = 12 -//}; - //enum jump_type { // unknown_jump_type = 0, // br = 1, diff --git a/Algorithm-visualizer/AST/number.hpp b/Algorithm-visualizer/AST/number.hpp index c1c3c6b..4f0bafe 100644 --- a/Algorithm-visualizer/AST/number.hpp +++ b/Algorithm-visualizer/AST/number.hpp @@ -1,4 +1,23 @@ #ifndef NUMBER_HPP #define NUMBER_HPP +#include "expression.hpp" +#include "ast.hpp" + +//enum var_type { +// unknown_var_type = 0, +// string = 1, +// integer = 2, +// character = 3, +// floating_point = 4 + +//}; + +class Number : Expression { + Number(); + ~Number(); +private: + var_type type; + std::string value; +}; #endif // NUMBER_HPP From 8bbfe3f442fc2ae644f932a725311afae34fa0c0 Mon Sep 17 00:00:00 2001 From: milenanedeljkovic Date: Mon, 22 Nov 2021 14:19:55 +0100 Subject: [PATCH 32/43] changed variable and declaration. only shifted attributes around but go over it again because it will be important for variable tracking --- Algorithm-visualizer/AST/ast.hpp | 2 -- Algorithm-visualizer/AST/block.hpp | 9 ++++++--- Algorithm-visualizer/AST/declaration.hpp | 20 ++++---------------- Algorithm-visualizer/AST/statement.hpp | 5 +++-- Algorithm-visualizer/AST/variable.hpp | 16 +++++++++++++++- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/Algorithm-visualizer/AST/ast.hpp b/Algorithm-visualizer/AST/ast.hpp index d063c86..8a7308c 100644 --- a/Algorithm-visualizer/AST/ast.hpp +++ b/Algorithm-visualizer/AST/ast.hpp @@ -59,8 +59,6 @@ virtual std::string get_type() = 0; // Statement or Expression (this is an abs //and Expression and inherited by every other subclass below) virtual std::string get_subtype() = 0; // Block, Declaration, UnOp, BinOp, ... //(this is an abstract method which will be defined in subclasses Block, Declaration, ...) -private: - std::map variables; }; diff --git a/Algorithm-visualizer/AST/block.hpp b/Algorithm-visualizer/AST/block.hpp index bba2ff6..33f07d5 100644 --- a/Algorithm-visualizer/AST/block.hpp +++ b/Algorithm-visualizer/AST/block.hpp @@ -3,11 +3,14 @@ #ifndef BLOCK_HPP #define BLOCK_HPP -class Block : public Statement { +class Block : public AST{ protected : Block(); protected : ~Block(); -std::string get_subtype(){return "Block";}; - //list of statements +std::string get_type(){return "Block";}; +public: +list statements; // list of statements in the block +std::map variables; +Block* parent_block; //nullptr if it is the program block }; #endif // BLOCK_HPP diff --git a/Algorithm-visualizer/AST/declaration.hpp b/Algorithm-visualizer/AST/declaration.hpp index 7250107..1e2a5a1 100644 --- a/Algorithm-visualizer/AST/declaration.hpp +++ b/Algorithm-visualizer/AST/declaration.hpp @@ -1,5 +1,6 @@ #include "ast.hpp" #include "statement.hpp" +#include "variable.hpp" #ifndef DECLARATION_HPP #define DECLARATION_HPP @@ -17,27 +18,14 @@ class Declaration : public Statement { public: Declaration(); ~Declaration(); - void set_var_type(var_type t){type = t;}; - std::string get_var_type(){ - switch(type) { - case 0: return "unknown variable type"; - case 1: return "string"; - case 2: return "integer"; - case 3: return "char"; - case 4: return "floating_point"; - } - } + void set_variable(Variable var){variable = var;}; char get_value(){return value;}; void set_value(char v){value = v;}; + Variable get_variable(){return variable;}; std::string get_subtype(){return "Declaration";}; - - private: - var_type type = unknown_var_type; + Variable variable; char value; - //int x = 7, bool y = False - //attributes: - //name + value of the variable or Variable + sth }; #endif // DECLARATION_HPP diff --git a/Algorithm-visualizer/AST/statement.hpp b/Algorithm-visualizer/AST/statement.hpp index 8cbb95e..9c13288 100644 --- a/Algorithm-visualizer/AST/statement.hpp +++ b/Algorithm-visualizer/AST/statement.hpp @@ -1,13 +1,14 @@ #include "ast.hpp" +#include "block.hpp" #ifndef STATEMENT_HPP #define STATEMENT_HPP class Statement : public AST { protected : Statement(); protected : ~Statement(); -std::string get_type(){return "Statement";}; + std::string get_type(){return "Statement";}; +Block* block; //reference to the block the statement is in: we want to be able to access the variables }; - #endif // STATEMENT_HPP diff --git a/Algorithm-visualizer/AST/variable.hpp b/Algorithm-visualizer/AST/variable.hpp index 75b5edd..4f18aef 100644 --- a/Algorithm-visualizer/AST/variable.hpp +++ b/Algorithm-visualizer/AST/variable.hpp @@ -18,7 +18,15 @@ class Variable : public Expression { void set_name(char n){name = n;}; void set_type(var_type t){type = t;}; std::string get_name(){return name;}; - var_type get_var_type(){return type;}; + std::string get_var_type(){ + switch(type) { + case 0: return "unknown variable type"; + case 1: return "string"; + case 2: return "integer"; + case 3: return "char"; + case 4: return "floating_point"; + } + } std::string get_subtype(){return "Variable";}; private: @@ -27,3 +35,9 @@ class Variable : public Expression { }; #endif // VARIABLE_HPP + + + +Variable x_var; +x_var.set_name('x') +x_var.set_type(integer) From 3592f4395692332eb3ba64137a226c93cf219a3d Mon Sep 17 00:00:00 2001 From: Evdokia Gneusheva Date: Mon, 22 Nov 2021 16:10:04 +0100 Subject: [PATCH 33/43] I added method which insert variable to a list of variables --- Algorithm-visualizer/AST/declaration.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Algorithm-visualizer/AST/declaration.hpp b/Algorithm-visualizer/AST/declaration.hpp index 1e2a5a1..5d7e919 100644 --- a/Algorithm-visualizer/AST/declaration.hpp +++ b/Algorithm-visualizer/AST/declaration.hpp @@ -1,6 +1,7 @@ #include "ast.hpp" #include "statement.hpp" #include "variable.hpp" +#include "block.hpp" #ifndef DECLARATION_HPP #define DECLARATION_HPP @@ -23,6 +24,7 @@ class Declaration : public Statement { void set_value(char v){value = v;}; Variable get_variable(){return variable;}; std::string get_subtype(){return "Declaration";}; + //void add_variable_to_list(){Block variables; variables.insert({variable, value});}; private: Variable variable; char value; From e9e12e7dda7277990270792ca6c292a6b157d9a4 Mon Sep 17 00:00:00 2001 From: milenanedeljkovic <80540793+milenanedeljkovic@users.noreply.github.com> Date: Thu, 25 Nov 2021 10:47:55 +0100 Subject: [PATCH 34/43] virtual methods (still empty) for Dasha --- Algorithm-visualizer/AST/expression.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Algorithm-visualizer/AST/expression.hpp b/Algorithm-visualizer/AST/expression.hpp index 68d3d37..646e311 100644 --- a/Algorithm-visualizer/AST/expression.hpp +++ b/Algorithm-visualizer/AST/expression.hpp @@ -14,6 +14,8 @@ protected : Expression(expression_type t) { }; ~Expression(); std::string get_type(){return "Expression";}; +virtual bool get_bool_value(); //expressions value is either numerical, true or false +virtual char get_num_value(); private: expression_type type = unknown_expression_type; }; From b34c19da26b47af75dfab696b61b657b1553f4d3 Mon Sep 17 00:00:00 2001 From: milenanedeljkovic Date: Thu, 25 Nov 2021 11:14:09 +0100 Subject: [PATCH 35/43] get_num_value in number.hpp and virtual classes in expression.hpp --- Algorithm-visualizer/AST/binop.hpp | 14 +++++++------- Algorithm-visualizer/AST/expression.hpp | 2 ++ Algorithm-visualizer/AST/number.hpp | 4 ++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Algorithm-visualizer/AST/binop.hpp b/Algorithm-visualizer/AST/binop.hpp index d39f0a9..16de815 100644 --- a/Algorithm-visualizer/AST/binop.hpp +++ b/Algorithm-visualizer/AST/binop.hpp @@ -6,18 +6,18 @@ //enum bin_op { // unknown_bin_op = 0, -// conjunction = 1, -// disjunction = 2, +// conjunction = 1, E +// disjunction = 2, E // addition = 3, // subtraction = 4, // multiplication = 5, // division = 6, -// lthan = 7, -// mthan = 8, -// leq = 9, -// meq = 10, +// lthan = 7, E +// mthan = 8, E +// leq = 9, E +// meq = 10, E // eq = 11, -// eqeq = 12 +// eqeq = 12 E //}; class BinOp : public Expression { diff --git a/Algorithm-visualizer/AST/expression.hpp b/Algorithm-visualizer/AST/expression.hpp index 68d3d37..646e311 100644 --- a/Algorithm-visualizer/AST/expression.hpp +++ b/Algorithm-visualizer/AST/expression.hpp @@ -14,6 +14,8 @@ protected : Expression(expression_type t) { }; ~Expression(); std::string get_type(){return "Expression";}; +virtual bool get_bool_value(); //expressions value is either numerical, true or false +virtual char get_num_value(); private: expression_type type = unknown_expression_type; }; diff --git a/Algorithm-visualizer/AST/number.hpp b/Algorithm-visualizer/AST/number.hpp index 4f0bafe..f5a6d8f 100644 --- a/Algorithm-visualizer/AST/number.hpp +++ b/Algorithm-visualizer/AST/number.hpp @@ -15,6 +15,10 @@ class Number : Expression { Number(); ~Number(); + std::string get_subtype(){return "Number";}; + double get_value(){return std::stod(value);}; //returns the double of the value + //we keep all the values as doubles for simplicity because we don't want + //some random internal clash of types to happen private: var_type type; std::string value; From ecce1e9ca7d1547981c79aa4a8d8cf095f2a4e8a Mon Sep 17 00:00:00 2001 From: darya-todoskova Date: Thu, 25 Nov 2021 13:25:15 +0100 Subject: [PATCH 36/43] Create .DS_Store --- .DS_Store | Bin 0 -> 6148 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c29797c862171fd67c3ba2b88b77c99c89ccadcf GIT binary patch literal 6148 zcmeHK%}yIJ5FUpBPAWtWNa@iRZb1rZ)QSVrHlzn`NQ=sWRVIy`jCdx>?VwLh&g}4n>fny zX7f>$Hp-h@+fr6#b*K8%AL^-}2l+Vb1nDK!&VqaxI{RGf_}LD^?@@nxRogq!NghN= zKQ+lwua6-=E~2ETryV^`dYS3Rw+&KOWaX+>pUqnBRzrPh&l_rX)M_?V`_t$7ydvxS zhsUSaquaaLulfChC0*eEX=K;o0)C_M&-0)7X%g#XfH{l)7X2_X1Iz$3@SYfOdzk$2 zo<5qtl^I|L*1`bo4+@pgb68k3TL%_&eWdm>Aqm>_mLOCPJ%@!wY(Wt=715>&_rwr3 z9sSD1c@7JUHXVc+8T)Y~3->}1W_0u`6Ar?&$R#tt3@kISVXHMd|G&Nd{$Ebw8Z*EQ z{8tQ!a@X&6a7ylMU6~x6wF>nbm4xC7i_a-&n4=hD=_vk)Y6Sg?3`EaiVG%tjd=W4- KaKQ|$m4PP)ja#e$ literal 0 HcmV?d00001 From 953fb8b477d2e2fa22cdd7b6c774e0e09b424501 Mon Sep 17 00:00:00 2001 From: milenanedeljkovic Date: Sat, 27 Nov 2021 20:23:37 +0100 Subject: [PATCH 37/43] new files: tried creating templates for Expression and Variable; renamed class.hpp to return.hpp --- Algorithm-visualizer/AST/ast.hpp | 9 --- Algorithm-visualizer/AST/binop_template.hpp | 56 +++++++++++++++++++ Algorithm-visualizer/AST/class.cpp | 6 -- Algorithm-visualizer/AST/decision.hpp | 1 + Algorithm-visualizer/AST/declaration.hpp | 10 ---- .../AST/declaration_template.hpp | 31 ++++++++++ Algorithm-visualizer/AST/expression.hpp | 2 +- .../AST/expression_template.cpp | 0 .../AST/expression_template.hpp | 12 ++++ Algorithm-visualizer/AST/return.cpp | 6 ++ .../AST/{class.hpp => return.hpp} | 6 +- Algorithm-visualizer/AST/unop.hpp | 2 +- Algorithm-visualizer/AST/variable.hpp | 24 +++----- .../AST/variable_template.cpp | 21 +++++++ .../AST/variable_template.hpp | 19 +++++++ Algorithm-visualizer/Algorithm-visualizer.pro | 11 +++- 16 files changed, 168 insertions(+), 48 deletions(-) create mode 100644 Algorithm-visualizer/AST/binop_template.hpp delete mode 100644 Algorithm-visualizer/AST/class.cpp create mode 100644 Algorithm-visualizer/AST/declaration_template.hpp create mode 100644 Algorithm-visualizer/AST/expression_template.cpp create mode 100644 Algorithm-visualizer/AST/expression_template.hpp create mode 100644 Algorithm-visualizer/AST/return.cpp rename Algorithm-visualizer/AST/{class.hpp => return.hpp} (84%) create mode 100644 Algorithm-visualizer/AST/variable_template.cpp create mode 100644 Algorithm-visualizer/AST/variable_template.hpp diff --git a/Algorithm-visualizer/AST/ast.hpp b/Algorithm-visualizer/AST/ast.hpp index 8a7308c..a953118 100644 --- a/Algorithm-visualizer/AST/ast.hpp +++ b/Algorithm-visualizer/AST/ast.hpp @@ -6,15 +6,6 @@ #include using namespace std; -enum var_type { - unknown_var_type = 0, - string = 1, - integer = 2, - character = 3, - floating_point = 4 - -}; - enum un_op { unknown_un_op = 0, negation = 1, diff --git a/Algorithm-visualizer/AST/binop_template.hpp b/Algorithm-visualizer/AST/binop_template.hpp new file mode 100644 index 0000000..0303fed --- /dev/null +++ b/Algorithm-visualizer/AST/binop_template.hpp @@ -0,0 +1,56 @@ + +#include "expression_template.hpp" +#include "ast.hpp" +#ifndef BINOP_HPP +#define BINOP_HPP + +//enum bin_op { +// unknown_bin_op = 0, +// conjunction = 1, E +// disjunction = 2, E +// addition = 3, +// subtraction = 4, +// multiplication = 5, +// division = 6, +// lthan = 7, E +// mthan = 8, E +// leq = 9, E +// meq = 10, E +// eq = 11, +// eqeq = 12 E +//}; + +template class BinOp : public Expression { + BinOp(); + ~BinOp(); + void set_operation(bin_op op){operation = op;}; + void set_left_expression(Expression* l_e){left_exp = l_e;}; + void set_right_expression(Expression* r_e){right_exp = r_e;}; + std::string get_operation(){ + switch(operation) { + case 0: return "unknown binary operation"; + case 1: return "conjunction"; + case 2: return "disjunction"; + case 3: return "addition"; + case 4: return "substraction"; + case 5: return "multiplication"; + case 6: return "division"; + case 7: return "lthan"; + case 8: return "mthan"; + case 9: return "leq"; + case 10: return "meq"; + case 11: return "eq"; + case 12: return "eqeq"; + } + } + Expression* get_left_expression(){return left_exp;}; + Expression* get_right_expression(){return right_exp;}; + std::string get_subtype(){return "BinOp";}; + T get_value(); +private: + bin_op operation = unknown_bin_op; + Expression* left_exp; + Expression* right_exp; +}; + +#endif // BINOP_HPP diff --git a/Algorithm-visualizer/AST/class.cpp b/Algorithm-visualizer/AST/class.cpp deleted file mode 100644 index ba28d06..0000000 --- a/Algorithm-visualizer/AST/class.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "class.hpp" - -Class::Class() -{ - -} diff --git a/Algorithm-visualizer/AST/decision.hpp b/Algorithm-visualizer/AST/decision.hpp index 0bc6b93..dc9383c 100644 --- a/Algorithm-visualizer/AST/decision.hpp +++ b/Algorithm-visualizer/AST/decision.hpp @@ -9,6 +9,7 @@ class Decision : public Statement { ~Decision(); void set_condition(Expression* c){condition = c;}; std::string get_subtype(){return "Decision";}; + bool is_true(); private: Expression* condition; }; diff --git a/Algorithm-visualizer/AST/declaration.hpp b/Algorithm-visualizer/AST/declaration.hpp index 1e2a5a1..1d2712f 100644 --- a/Algorithm-visualizer/AST/declaration.hpp +++ b/Algorithm-visualizer/AST/declaration.hpp @@ -4,16 +4,6 @@ #ifndef DECLARATION_HPP #define DECLARATION_HPP - -//enum var_type { -// unknown_var_type = 0, -// string = 1, -// integer = 2, -// character = 3, -// floating_point = 4 - -//}; - class Declaration : public Statement { public: Declaration(); diff --git a/Algorithm-visualizer/AST/declaration_template.hpp b/Algorithm-visualizer/AST/declaration_template.hpp new file mode 100644 index 0000000..1e2a5a1 --- /dev/null +++ b/Algorithm-visualizer/AST/declaration_template.hpp @@ -0,0 +1,31 @@ +#include "ast.hpp" +#include "statement.hpp" +#include "variable.hpp" +#ifndef DECLARATION_HPP +#define DECLARATION_HPP + + +//enum var_type { +// unknown_var_type = 0, +// string = 1, +// integer = 2, +// character = 3, +// floating_point = 4 + +//}; + +class Declaration : public Statement { +public: + Declaration(); + ~Declaration(); + void set_variable(Variable var){variable = var;}; + char get_value(){return value;}; + void set_value(char v){value = v;}; + Variable get_variable(){return variable;}; + std::string get_subtype(){return "Declaration";}; +private: + Variable variable; + char value; +}; + +#endif // DECLARATION_HPP diff --git a/Algorithm-visualizer/AST/expression.hpp b/Algorithm-visualizer/AST/expression.hpp index 646e311..4590700 100644 --- a/Algorithm-visualizer/AST/expression.hpp +++ b/Algorithm-visualizer/AST/expression.hpp @@ -15,7 +15,7 @@ protected : Expression(expression_type t) { ~Expression(); std::string get_type(){return "Expression";}; virtual bool get_bool_value(); //expressions value is either numerical, true or false -virtual char get_num_value(); +virtual double get_num_value(); private: expression_type type = unknown_expression_type; }; diff --git a/Algorithm-visualizer/AST/expression_template.cpp b/Algorithm-visualizer/AST/expression_template.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Algorithm-visualizer/AST/expression_template.hpp b/Algorithm-visualizer/AST/expression_template.hpp new file mode 100644 index 0000000..c8e5cbe --- /dev/null +++ b/Algorithm-visualizer/AST/expression_template.hpp @@ -0,0 +1,12 @@ +#ifndef EXPRESSION_TEMPLATE_H +#define EXPRESSION_TEMPLATE_H +#include "ast.hpp" + +template class Expression : AST{ +protected : Expression(); + ~Expression(); +std::string get_type(){return "Expression";}; +T get_value() = 0; +}; + +#endif // EXPRESSION_TEMPLATE_H diff --git a/Algorithm-visualizer/AST/return.cpp b/Algorithm-visualizer/AST/return.cpp new file mode 100644 index 0000000..121d8de --- /dev/null +++ b/Algorithm-visualizer/AST/return.cpp @@ -0,0 +1,6 @@ +#include "return.hpp" + +Class::Class() +{ + +} diff --git a/Algorithm-visualizer/AST/class.hpp b/Algorithm-visualizer/AST/return.hpp similarity index 84% rename from Algorithm-visualizer/AST/class.hpp rename to Algorithm-visualizer/AST/return.hpp index 9438d2b..41d9607 100644 --- a/Algorithm-visualizer/AST/class.hpp +++ b/Algorithm-visualizer/AST/return.hpp @@ -2,8 +2,8 @@ #include "expression.hpp" #include "statement.hpp" #include "ast.hpp" -#ifndef CLASS_HPP -#define CLASS_HPP +#ifndef RETURN_H +#define RETURN_H class Return : public Statement { Return(); @@ -15,4 +15,4 @@ class Return : public Statement { Expression* exp; }; -#endif // CLASS_HPP +#endif // RETURN_H diff --git a/Algorithm-visualizer/AST/unop.hpp b/Algorithm-visualizer/AST/unop.hpp index 7ab920e..eab621c 100644 --- a/Algorithm-visualizer/AST/unop.hpp +++ b/Algorithm-visualizer/AST/unop.hpp @@ -7,7 +7,7 @@ // unknown_un_op = 0, // negation = 1, // plusplus = 2 -// //inverse = 2 (if we add this as a unary operation for number -> -number) +// //inverse = 3 (if we add this as a unary operation for number -> -number) //}; class UnOp : public Expression { diff --git a/Algorithm-visualizer/AST/variable.hpp b/Algorithm-visualizer/AST/variable.hpp index 4f18aef..10d18d0 100644 --- a/Algorithm-visualizer/AST/variable.hpp +++ b/Algorithm-visualizer/AST/variable.hpp @@ -1,17 +1,9 @@ #include "expression.hpp" #include "ast.hpp" +#include "expression.hpp" #ifndef VARIABLE_HPP #define VARIABLE_HPP -/* enum var_type { - unknown_var_type = 0, - string = 1, - integer = 2, - character = 3, - floating_point = 4 - -}; */ - class Variable : public Expression { Variable(); ~Variable(); @@ -28,16 +20,18 @@ class Variable : public Expression { } } std::string get_subtype(){return "Variable";}; + double get_num_value(){ + assert (type ==2 or type == 4); + return std::stod(current_value); + }; + bool get_bool_value(){ + + }; private: std::string name; var_type type = unknown_var_type; + std::string current_value; }; #endif // VARIABLE_HPP - - - -Variable x_var; -x_var.set_name('x') -x_var.set_type(integer) diff --git a/Algorithm-visualizer/AST/variable_template.cpp b/Algorithm-visualizer/AST/variable_template.cpp new file mode 100644 index 0000000..dfa54d7 --- /dev/null +++ b/Algorithm-visualizer/AST/variable_template.cpp @@ -0,0 +1,21 @@ +#include "variable_template.hpp" + +template<> std::string Variable::type() { + return "Bool"; +}; + +template<> std::string Variable::type() { + return "Integer"; +}; + +template<> std::string Variable::type() { + return "Float"; +}; + +template<> std::string Variable::type() { + return "Double"; +}; + +template<> std::string Variable::type() { + return "String"; +}; diff --git a/Algorithm-visualizer/AST/variable_template.hpp b/Algorithm-visualizer/AST/variable_template.hpp new file mode 100644 index 0000000..6a51854 --- /dev/null +++ b/Algorithm-visualizer/AST/variable_template.hpp @@ -0,0 +1,19 @@ +#ifndef VARIABLE_TEMPLATE_H +#define VARIABLE_TEMPLATE_H + +#include "expression_template.hpp" + +template class Variable : Expression { + Variable(); + ~Variable(); + void set_name(char n){name = n;}; + std::string get_name(){return name;}; + std::string get_subtype(){return "Variable";}; + T get_value(){return value;}; + std::string type(); +private: + std::string name; + T value; +}; + +#endif // VARIABLE_TEMPLATE_H diff --git a/Algorithm-visualizer/Algorithm-visualizer.pro b/Algorithm-visualizer/Algorithm-visualizer.pro index 726dab1..0e564c9 100644 --- a/Algorithm-visualizer/Algorithm-visualizer.pro +++ b/Algorithm-visualizer/Algorithm-visualizer.pro @@ -14,17 +14,19 @@ SOURCES += \ AST/binop.cpp \ AST/block.cpp \ AST/boolean.cpp \ - AST/class.cpp \ AST/decision.cpp \ AST/declaration.cpp \ AST/expression.cpp \ + AST/expression_template.cpp \ AST/ifelse.cpp \ AST/ifrest.cpp \ AST/jump.cpp \ AST/print.cpp \ + AST/return.cpp \ AST/statement.cpp \ AST/unop.cpp \ AST/variable.cpp \ + AST/variable_template.cpp \ AST/while.cpp \ GUI/codecell.cpp \ GUI/gui.cpp \ @@ -38,20 +40,23 @@ HEADERS += \ AST/assignment.hpp \ AST/ast.hpp \ AST/binop.hpp \ + AST/binop_template.hpp \ AST/block.hpp \ AST/boolean.hpp \ - AST/class.hpp \ AST/decision.hpp \ AST/declaration.hpp \ + AST/declaration_template.hpp \ AST/expression.hpp \ + AST/expression_template.hpp \ AST/ifelse.hpp \ AST/ifrest.hpp \ AST/jump.hpp \ - AST/number.hpp \ AST/print.hpp \ + AST/return.hpp \ AST/statement.hpp \ AST/unop.hpp \ AST/variable.hpp \ + AST/variable_template.hpp \ AST/while.hpp \ GUI/codecell.h \ GUI/gui.hpp \ From a4bf24fe326246f02e43bb966da5ec5ac53d819b Mon Sep 17 00:00:00 2001 From: milenanedeljkovic Date: Sun, 28 Nov 2021 10:14:40 +0100 Subject: [PATCH 38/43] just some part of updated BinOp but I am struggling with it --- Algorithm-visualizer/AST/binop_template.cpp | 6 ++ Algorithm-visualizer/AST/binop_template.hpp | 74 +++++++------------ .../AST/expression_template.hpp | 2 +- Algorithm-visualizer/Algorithm-visualizer.pro | 1 + 4 files changed, 35 insertions(+), 48 deletions(-) create mode 100644 Algorithm-visualizer/AST/binop_template.cpp diff --git a/Algorithm-visualizer/AST/binop_template.cpp b/Algorithm-visualizer/AST/binop_template.cpp new file mode 100644 index 0000000..5025fe4 --- /dev/null +++ b/Algorithm-visualizer/AST/binop_template.cpp @@ -0,0 +1,6 @@ +#include "binop_template.hpp" + +binop_template::binop_template() +{ + +} diff --git a/Algorithm-visualizer/AST/binop_template.hpp b/Algorithm-visualizer/AST/binop_template.hpp index 0303fed..86b03b7 100644 --- a/Algorithm-visualizer/AST/binop_template.hpp +++ b/Algorithm-visualizer/AST/binop_template.hpp @@ -1,56 +1,36 @@ +#ifndef BINOP_TEMPLATE_HPP +#define BINOP_TEMPLATE_HPP #include "expression_template.hpp" -#include "ast.hpp" -#ifndef BINOP_HPP -#define BINOP_HPP -//enum bin_op { -// unknown_bin_op = 0, -// conjunction = 1, E -// disjunction = 2, E -// addition = 3, -// subtraction = 4, -// multiplication = 5, -// division = 6, -// lthan = 7, E -// mthan = 8, E -// leq = 9, E -// meq = 10, E -// eq = 11, -// eqeq = 12 E -//}; +template void set_expression(Expression* expression, Expression* e){ + e = expression; +}; + +class BoolBinOp : public Expression { + BoolBinOp(); + ~BoolBinOp(); + void set_operation(bin_op op){operation = op;}; + void set_left_expression(Expression* l_e){left_exp = l_e;}; + void set_right_expression(Expression* r_e){right_exp = r_e;}; +private: + bin_op operation = unknown_bin_op; + Expression* left_exp; + Expression* right_exp; +}; -template class BinOp : public Expression { - BinOp(); - ~BinOp(); +/* +class NumBinOp : public Expression, public Expression, public Expression { + NumBinOp(); + ~NumBinOp(); void set_operation(bin_op op){operation = op;}; - void set_left_expression(Expression* l_e){left_exp = l_e;}; - void set_right_expression(Expression* r_e){right_exp = r_e;}; - std::string get_operation(){ - switch(operation) { - case 0: return "unknown binary operation"; - case 1: return "conjunction"; - case 2: return "disjunction"; - case 3: return "addition"; - case 4: return "substraction"; - case 5: return "multiplication"; - case 6: return "division"; - case 7: return "lthan"; - case 8: return "mthan"; - case 9: return "leq"; - case 10: return "meq"; - case 11: return "eq"; - case 12: return "eqeq"; - } - } - Expression* get_left_expression(){return left_exp;}; - Expression* get_right_expression(){return right_exp;}; - std::string get_subtype(){return "BinOp";}; - T get_value(); + void set_left_expression(Expression* l_e){left_exp = l_e;}; + void set_right_expression(Expression* r_e){right_exp = r_e;}; private: bin_op operation = unknown_bin_op; - Expression* left_exp; - Expression* right_exp; + Expression* left_exp; + Expression* right_exp; }; +*/ -#endif // BINOP_HPP +#endif // BINOP_TEMPLATE_HPP diff --git a/Algorithm-visualizer/AST/expression_template.hpp b/Algorithm-visualizer/AST/expression_template.hpp index c8e5cbe..6ced2d4 100644 --- a/Algorithm-visualizer/AST/expression_template.hpp +++ b/Algorithm-visualizer/AST/expression_template.hpp @@ -2,7 +2,7 @@ #define EXPRESSION_TEMPLATE_H #include "ast.hpp" -template class Expression : AST{ +template class Expression : public AST{ protected : Expression(); ~Expression(); std::string get_type(){return "Expression";}; diff --git a/Algorithm-visualizer/Algorithm-visualizer.pro b/Algorithm-visualizer/Algorithm-visualizer.pro index 0e564c9..d8eb6a2 100644 --- a/Algorithm-visualizer/Algorithm-visualizer.pro +++ b/Algorithm-visualizer/Algorithm-visualizer.pro @@ -12,6 +12,7 @@ SOURCES += \ AST/assignment.cpp \ AST/ast.cpp \ AST/binop.cpp \ + AST/binop_template.cpp \ AST/block.cpp \ AST/boolean.cpp \ AST/decision.cpp \ From 7bcbd5bd228f672e740ae294a9cfc7019a23f202 Mon Sep 17 00:00:00 2001 From: milenanedeljkovic <80540793+milenanedeljkovic@users.noreply.github.com> Date: Sun, 5 Dec 2021 19:45:42 +0100 Subject: [PATCH 39/43] separating each operation; in progress --- Algorithm-visualizer/AST/binop.hpp | 178 +++++++++++++++++++++-------- 1 file changed, 133 insertions(+), 45 deletions(-) diff --git a/Algorithm-visualizer/AST/binop.hpp b/Algorithm-visualizer/AST/binop.hpp index 16de815..90daf89 100644 --- a/Algorithm-visualizer/AST/binop.hpp +++ b/Algorithm-visualizer/AST/binop.hpp @@ -1,55 +1,143 @@ - #include "expression.hpp" #include "ast.hpp" #ifndef BINOP_HPP #define BINOP_HPP -//enum bin_op { -// unknown_bin_op = 0, -// conjunction = 1, E -// disjunction = 2, E -// addition = 3, -// subtraction = 4, -// multiplication = 5, -// division = 6, -// lthan = 7, E -// mthan = 8, E -// leq = 9, E -// meq = 10, E -// eq = 11, -// eqeq = 12 E -//}; - -class BinOp : public Expression { - BinOp(); - ~BinOp(); - void set_operation(bin_op op){operation = op;}; - void set_left_expression(Expression* l_e){left_exp = l_e;}; - void set_right_expression(Expression* r_e){right_exp = r_e;}; - std::string get_operation(){ - switch(operation) { - case 0: return "unknown binary operation"; - case 1: return "conjunction"; - case 2: return "disjunction"; - case 3: return "addition"; - case 4: return "substraction"; - case 5: return "multiplication"; - case 6: return "division"; - case 7: return "lthan"; - case 8: return "mthan"; - case 9: return "leq"; - case 10: return "meq"; - case 11: return "eq"; - case 12: return "eqeq"; - } - } - Expression* get_left_expression(){return left_exp;}; - Expression* get_right_expression(){return right_exp;}; - std::string get_subtype(){return "BinOp";}; -private: - bin_op operation = unknown_bin_op; +class Addition : public Expression { +public : Addition(); +public : ~Addition(); +public : double get_value(){ + if (left_exp->get_exp_type() == "bool" or right_exp->get_exp_type() == "bool") {return 0;}; + return left_exp->get_value() + right_exp->get_value(); + }; +private : + Expression* left_exp; + Expression* right_exp; +}; + +class Subtraction : public Expression { +public : Subtraction(); +public : ~Subtraction(); +public : double get_value(){ + if (left_exp->get_exp_type() == "bool" or right_exp->get_exp_type() == "bool") {return 0;}; + return left_exp->get_value() - right_exp->get_value(); + }; +private : + Expression* left_exp; + Expression* right_exp; +}; + +class Multiplication : public Expression { +public : Multiplication(); +public : ~Multiplication(); +public : double get_value(){ + if (left_exp->get_exp_type() == "bool" or right_exp->get_exp_type() == "bool") {return 0;}; + return left_exp->get_value() * right_exp->get_value(); + }; +private : + Expression* left_exp; + Expression* right_exp; +}; + +class Division : public Expression { +public : Division(); +public : ~Division(); +public : double get_value(){ + if (left_exp->get_exp_type() == "bool" or right_exp->get_exp_type() == "bool" or right_exp->get_value() == 0) return 0; + return left_exp->get_value() / right_exp->get_value(); + }; +private : + Expression* left_exp; + Expression* right_exp; +}; + +class Mthan : public Expression { +public : Mthan(); +public : ~Mthan(); +public : double get_value(){ + if (left_exp->get_exp_type() == "bool" or right_exp->get_exp_type() == "bool") return 0; + if (left_exp->get_value() > right_exp->get_value()) return 1; + return 0; + }; +private : + Expression* left_exp; + Expression* right_exp; +}; + +class Lthan : public Expression { +public : Lthan(); +public : ~Lthan(); +public : double get_value(){ + if (left_exp->get_exp_type() == "bool" or right_exp->get_exp_type() == "bool") return 0; + if (left_exp->get_value() < right_exp->get_value()) return 1; + return 0; + }; +private : Expression* left_exp; Expression* right_exp; }; +class Leq : public Expression { +public : Leq(); +public : ~Leq(); +public : double get_value(){ + if (left_exp->get_exp_type() == "bool" or right_exp->get_exp_type() == "bool") return 0; + if (left_exp->get_value() <= right_exp->get_value()) return 1; + return 0; + }; +private : + Expression* left_exp; + Expression* right_exp; +}; + +class Meq : public Expression { +public : Meq(); +public : ~Meq(); +public : double get_value(){ + if (left_exp->get_exp_type() == "bool" or right_exp->get_exp_type() == "bool") return 0; + if (left_exp->get_value() >= right_exp->get_value()) return 1; + return 0; + }; +private : + Expression* left_exp; + Expression* right_exp; +}; + +class Eqeq : public Expression { +public : Eqeq(); +public : ~Eqeq(); +public : double get_value(){ + if (left_exp->get_value() == right_exp->get_value()) return 1; + return 0; + }; +private : + Expression* left_exp; + Expression* right_exp; +}; + +class AndOp : public Expression { +public : AndOp(); +public : ~AndOp(); +public : double get_value(){ + if (left_exp->get_value() && right_exp->get_value()) return 1; + return 0; + }; +private : + Expression* left_exp; + Expression* right_exp; +}; + +class OrOp : public Expression { +public : OrOp(); +public : ~OrOp(); +public : double get_value(){ + if (left_exp->get_value() || right_exp->get_value()) return 1; + return 0; + }; +private : + Expression* left_exp; + Expression* right_exp; +}; + + #endif // BINOP_HPP From a083c5020b42ba945d4037288278a37afe12c0d4 Mon Sep 17 00:00:00 2001 From: milenanedeljkovic <80540793+milenanedeljkovic@users.noreply.github.com> Date: Sun, 5 Dec 2021 19:47:02 +0100 Subject: [PATCH 40/43] final(ish) version of Variable --- Algorithm-visualizer/AST/variable.hpp | 43 +++++++++++---------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/Algorithm-visualizer/AST/variable.hpp b/Algorithm-visualizer/AST/variable.hpp index 10d18d0..0137aeb 100644 --- a/Algorithm-visualizer/AST/variable.hpp +++ b/Algorithm-visualizer/AST/variable.hpp @@ -1,37 +1,28 @@ -#include "expression.hpp" -#include "ast.hpp" -#include "expression.hpp" #ifndef VARIABLE_HPP #define VARIABLE_HPP +#include "expression.hpp" class Variable : public Expression { - Variable(); - ~Variable(); - void set_name(char n){name = n;}; - void set_type(var_type t){type = t;}; - std::string get_name(){return name;}; - std::string get_var_type(){ - switch(type) { - case 0: return "unknown variable type"; - case 1: return "string"; - case 2: return "integer"; - case 3: return "char"; - case 4: return "floating_point"; - } - } - std::string get_subtype(){return "Variable";}; - double get_num_value(){ - assert (type ==2 or type == 4); - return std::stod(current_value); +public : Variable(); +public : ~Variable(); +public : void set_name(std::string n){name = n;}; +public : void set_value(bool val){ + if (val) value = 1; + else value = 0; + type = "bool"; }; - bool get_bool_value(){ - +public : void set_value(double val){ + value = val; + type = "double"; }; - +public : std::string get_name(){return name;}; +public : double get_value(){return value;}; +public : std::string get_exp_type(){return type;}; +public : string get_type(){return "Variable";}; private: std::string name; - var_type type = unknown_var_type; - std::string current_value; + double value = 0; + std::string type; }; #endif // VARIABLE_HPP From 872f7c50282a149d50424482a1179da0908b92f0 Mon Sep 17 00:00:00 2001 From: milenanedeljkovic <80540793+milenanedeljkovic@users.noreply.github.com> Date: Sun, 5 Dec 2021 19:51:47 +0100 Subject: [PATCH 41/43] changes for the last commits of Variable and BinOp --- Algorithm-visualizer/AST/expression.hpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/Algorithm-visualizer/AST/expression.hpp b/Algorithm-visualizer/AST/expression.hpp index 4590700..554ba8c 100644 --- a/Algorithm-visualizer/AST/expression.hpp +++ b/Algorithm-visualizer/AST/expression.hpp @@ -1,21 +1,12 @@ -#include "ast.hpp" -#ifndef EXPRESSION_HPP -#define EXPRESSION_HPP - -//enum expression_type { -// unknown_expression_type = 0 -//}; - - class Expression : public AST { -protected : Expression(); -protected : Expression(expression_type t) { +public : Expression(); +public : Expression(expression_type t) { type = t; }; - ~Expression(); +public : ~Expression(); std::string get_type(){return "Expression";}; -virtual bool get_bool_value(); //expressions value is either numerical, true or false -virtual double get_num_value(); +virtual double get_value() = 0; +virtual std::string get_exp_type() = 0; private: expression_type type = unknown_expression_type; }; From 6ef42b134a6a5968ebaf56221ba958b0d5b9165f Mon Sep 17 00:00:00 2001 From: milenanedeljkovic <80540793+milenanedeljkovic@users.noreply.github.com> Date: Sun, 5 Dec 2021 19:53:09 +0100 Subject: [PATCH 42/43] oops --- Algorithm-visualizer/AST/expression.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Algorithm-visualizer/AST/expression.hpp b/Algorithm-visualizer/AST/expression.hpp index 554ba8c..b719bc8 100644 --- a/Algorithm-visualizer/AST/expression.hpp +++ b/Algorithm-visualizer/AST/expression.hpp @@ -1,3 +1,7 @@ +#include "ast.hpp" +#ifndef EXPRESSION_HPP +#define EXPRESSION_HPP + class Expression : public AST { public : Expression(); public : Expression(expression_type t) { From ca6af18f45aae7df91fc2f46f4edb571d4bd7ba7 Mon Sep 17 00:00:00 2001 From: milenanedeljkovic <80540793+milenanedeljkovic@users.noreply.github.com> Date: Sun, 5 Dec 2021 20:23:18 +0100 Subject: [PATCH 43/43] checking whether the condition is true --- Algorithm-visualizer/AST/decision.hpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Algorithm-visualizer/AST/decision.hpp b/Algorithm-visualizer/AST/decision.hpp index dc9383c..dd88f0e 100644 --- a/Algorithm-visualizer/AST/decision.hpp +++ b/Algorithm-visualizer/AST/decision.hpp @@ -1,16 +1,20 @@ #include "expression.hpp" #include "statement.hpp" -#include "ast.hpp" -#ifndef DECISION_HPP -#define DECISION_HPP +#ifndef DECISION_H +#define DECISION_H -class Decision : public Statement { - Decision(); - ~Decision(); - void set_condition(Expression* c){condition = c;}; - std::string get_subtype(){return "Decision";}; - bool is_true(); + +class Decision { +public : Decision(); +public : ~Decision(); +public : void set_condition(Expression* c){condition = c;}; +public : string get_subtype(){return "Decision";}; +public : double get_value(){ + if (condition->get_value()) return 1; + return 0; + }; private: Expression* condition; }; -#endif // DECISION_HPP + +#endif // DECISION_H