|
@@ -1,26 +1,81 @@
|
|
|
-import { Types } from './types';
|
|
|
-import WatchJS from 'melanke-watchjs';
|
|
|
-import * as AlgorithmManagement from './algorithm';
|
|
|
-
|
|
|
-export const COMMAND_TYPES = Object.freeze({function:"function", comment:"comment", reader:"reader", writer:"writer", attribution:"attribution", iftrue:"iftrue",
|
|
|
- repeatNtimes:"repeatNtimes", whiletrue:"whiletrue", dowhiletrue:"dowhiletrue", switch:"switch", switchcase:"switchcase", functioncall:"functioncall", break:"break",
|
|
|
- return:"return"});
|
|
|
-
|
|
|
-export const ARITHMETIC_TYPES = Object.freeze({plus:"plus", minus:"minus", multiplication:"multiplication", division:"division", module:"module", none:"none"});
|
|
|
-
|
|
|
-export const EXPRESSION_ELEMENTS = Object.freeze({exp_op_exp:"exp_op_exp", op_exp:"op_exp", par_exp_par:"par_exp_par", start_point:"start_point"});
|
|
|
-
|
|
|
-export const EXPRESSION_TYPES = Object.freeze({exp_conditional:"exp_conditional", exp_logic:"exp_logic", exp_arithmetic:"exp_arithmetic"});
|
|
|
-
|
|
|
-export const ARITHMETIC_COMPARISON = Object.freeze({greater_than:"greater_than", less_than:"less_than", equals_to:"equals_to", not_equals_to:"not_equals_to", greater_than_or_equals_to:"greater_than_or_equals_to", less_than_or_equals_to:"less_than_or_equals_to"});
|
|
|
-
|
|
|
-export const LOGIC_COMPARISON = Object.freeze({equals_to:"equals_to", not_equals_to:"not_equals_to", and:"and", or:"or", not:"not"});
|
|
|
-
|
|
|
-export const SYSTEM_FUNCTIONS_CATEGORIES = Object.freeze({math:'$mathLib', text:'$strLib', arrangement:'$arrayLib', conversion:'$langLib'});
|
|
|
+import { Types } from "./types";
|
|
|
+import WatchJS from "melanke-watchjs";
|
|
|
+import * as AlgorithmManagement from "./algorithm";
|
|
|
+
|
|
|
+export const COMMAND_TYPES = Object.freeze({
|
|
|
+ function: "function",
|
|
|
+ comment: "comment",
|
|
|
+ reader: "reader",
|
|
|
+ writer: "writer",
|
|
|
+ attribution: "attribution",
|
|
|
+ iftrue: "iftrue",
|
|
|
+ repeatNtimes: "repeatNtimes",
|
|
|
+ whiletrue: "whiletrue",
|
|
|
+ dowhiletrue: "dowhiletrue",
|
|
|
+ switch: "switch",
|
|
|
+ switchcase: "switchcase",
|
|
|
+ functioncall: "functioncall",
|
|
|
+ break: "break",
|
|
|
+ return: "return",
|
|
|
+});
|
|
|
+
|
|
|
+export const ARITHMETIC_TYPES = Object.freeze({
|
|
|
+ plus: "plus",
|
|
|
+ minus: "minus",
|
|
|
+ multiplication: "multiplication",
|
|
|
+ division: "division",
|
|
|
+ module: "module",
|
|
|
+ none: "none",
|
|
|
+});
|
|
|
+
|
|
|
+export const EXPRESSION_ELEMENTS = Object.freeze({
|
|
|
+ exp_op_exp: "exp_op_exp",
|
|
|
+ op_exp: "op_exp",
|
|
|
+ par_exp_par: "par_exp_par",
|
|
|
+ start_point: "start_point",
|
|
|
+});
|
|
|
+
|
|
|
+export const EXPRESSION_TYPES = Object.freeze({
|
|
|
+ exp_conditional: "exp_conditional",
|
|
|
+ exp_logic: "exp_logic",
|
|
|
+ exp_arithmetic: "exp_arithmetic",
|
|
|
+ write_sep: "write_separator",
|
|
|
+});
|
|
|
+
|
|
|
+export const ARITHMETIC_COMPARISON = Object.freeze({
|
|
|
+ greater_than: "greater_than",
|
|
|
+ less_than: "less_than",
|
|
|
+ equals_to: "equals_to",
|
|
|
+ not_equals_to: "not_equals_to",
|
|
|
+ greater_than_or_equals_to: "greater_than_or_equals_to",
|
|
|
+ less_than_or_equals_to: "less_than_or_equals_to",
|
|
|
+});
|
|
|
+
|
|
|
+export const LOGIC_COMPARISON = Object.freeze({
|
|
|
+ equals_to: "equals_to",
|
|
|
+ not_equals_to: "not_equals_to",
|
|
|
+ and: "and",
|
|
|
+ or: "or",
|
|
|
+ not: "not",
|
|
|
+});
|
|
|
+
|
|
|
+export const SYSTEM_FUNCTIONS_CATEGORIES = Object.freeze({
|
|
|
+ math: "$mathLib",
|
|
|
+ text: "$strLib",
|
|
|
+ arrangement: "$arrayLib",
|
|
|
+ conversion: "$langLib",
|
|
|
+});
|
|
|
|
|
|
export class Variable {
|
|
|
-
|
|
|
- constructor (type, name, value, dimensions = 0, is_constant = false, rows = 0, columns = 0) {
|
|
|
+ constructor (
|
|
|
+ type,
|
|
|
+ name,
|
|
|
+ value,
|
|
|
+ dimensions = 0,
|
|
|
+ is_constant = false,
|
|
|
+ rows = 0,
|
|
|
+ columns = 0
|
|
|
+ ) {
|
|
|
this.type = type;
|
|
|
this.name = name;
|
|
|
this.value = value;
|
|
@@ -32,8 +87,17 @@ export class Variable {
|
|
|
}
|
|
|
|
|
|
export class Function {
|
|
|
-
|
|
|
- constructor (name, return_type = Types.VOID, return_dimensions = 0, parameters_list = [], is_main = false, is_hidden = false, variables_list = [], function_comment = null, commands = []) {
|
|
|
+ constructor (
|
|
|
+ name,
|
|
|
+ return_type = Types.VOID,
|
|
|
+ return_dimensions = 0,
|
|
|
+ parameters_list = [],
|
|
|
+ is_main = false,
|
|
|
+ is_hidden = false,
|
|
|
+ variables_list = [],
|
|
|
+ function_comment = null,
|
|
|
+ commands = []
|
|
|
+ ) {
|
|
|
this.type = COMMAND_TYPES.function;
|
|
|
this.name = name;
|
|
|
this.return_type = return_type;
|
|
@@ -48,8 +112,14 @@ export class Function {
|
|
|
}
|
|
|
|
|
|
export class SystemFunction {
|
|
|
-
|
|
|
- constructor (identifier, return_type, return_dimensions, parameters_list, function_comment = null, category) {
|
|
|
+ constructor (
|
|
|
+ identifier,
|
|
|
+ return_type,
|
|
|
+ return_dimensions,
|
|
|
+ parameters_list,
|
|
|
+ function_comment = null,
|
|
|
+ category
|
|
|
+ ) {
|
|
|
this.type = COMMAND_TYPES.function;
|
|
|
this.identifier = identifier;
|
|
|
this.return_type = return_type;
|
|
@@ -61,7 +131,6 @@ export class SystemFunction {
|
|
|
}
|
|
|
|
|
|
export class Comment {
|
|
|
-
|
|
|
constructor (comment_text) {
|
|
|
this.type = COMMAND_TYPES.comment;
|
|
|
this.comment_text = comment_text;
|
|
@@ -69,14 +138,12 @@ export class Comment {
|
|
|
}
|
|
|
|
|
|
export class Break {
|
|
|
-
|
|
|
constructor () {
|
|
|
this.type = COMMAND_TYPES.break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export class Reader {
|
|
|
-
|
|
|
constructor (variable_value_menu = new VariableValueMenu()) {
|
|
|
this.type = COMMAND_TYPES.reader;
|
|
|
this.variable_value_menu = variable_value_menu;
|
|
@@ -84,15 +151,14 @@ export class Reader {
|
|
|
}
|
|
|
|
|
|
export class Writer {
|
|
|
-
|
|
|
- constructor (content) {
|
|
|
+ constructor (content, newline = true) {
|
|
|
this.type = COMMAND_TYPES.writer;
|
|
|
this.content = content;
|
|
|
+ this.newline = newline;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export class Attribution {
|
|
|
-
|
|
|
constructor (variable, expression = []) {
|
|
|
this.type = COMMAND_TYPES.attribution;
|
|
|
this.variable = variable;
|
|
@@ -101,7 +167,6 @@ export class Attribution {
|
|
|
}
|
|
|
|
|
|
export class ExpressionOperator {
|
|
|
-
|
|
|
constructor (type_op, item) {
|
|
|
this.type_op = type_op;
|
|
|
this.item = item;
|
|
@@ -109,7 +174,6 @@ export class ExpressionOperator {
|
|
|
}
|
|
|
|
|
|
export class ExpressionElement {
|
|
|
-
|
|
|
constructor (type_exp, itens = []) {
|
|
|
this.type_exp = type_exp;
|
|
|
this.itens = itens;
|
|
@@ -117,7 +181,6 @@ export class ExpressionElement {
|
|
|
}
|
|
|
|
|
|
export class ConditionalExpression {
|
|
|
-
|
|
|
constructor (expression) {
|
|
|
this.type = EXPRESSION_TYPES.exp_conditional;
|
|
|
this.expression = expression;
|
|
@@ -125,7 +188,6 @@ export class ConditionalExpression {
|
|
|
}
|
|
|
|
|
|
export class LogicExpression {
|
|
|
-
|
|
|
constructor (has_neg, first_operand, second_operand, operator) {
|
|
|
this.type = EXPRESSION_TYPES.exp_logic;
|
|
|
this.has_neg = has_neg;
|
|
@@ -136,7 +198,6 @@ export class LogicExpression {
|
|
|
}
|
|
|
|
|
|
export class ArithmeticExpression {
|
|
|
-
|
|
|
constructor (first_operand, second_operand, operator) {
|
|
|
this.type = EXPRESSION_TYPES.exp_arithmetic;
|
|
|
this.first_operand = first_operand;
|
|
@@ -146,7 +207,6 @@ export class ArithmeticExpression {
|
|
|
}
|
|
|
|
|
|
export class IfTrue {
|
|
|
-
|
|
|
constructor (expression, commands_block, commands_else) {
|
|
|
this.type = COMMAND_TYPES.iftrue;
|
|
|
this.expression = expression;
|
|
@@ -156,8 +216,14 @@ export class IfTrue {
|
|
|
}
|
|
|
|
|
|
export class RepeatNTimes {
|
|
|
-
|
|
|
- constructor (var_attribution, var_incrementation, expression1, expression2, expression3, commands_block) {
|
|
|
+ constructor (
|
|
|
+ var_attribution,
|
|
|
+ var_incrementation,
|
|
|
+ expression1,
|
|
|
+ expression2,
|
|
|
+ expression3,
|
|
|
+ commands_block
|
|
|
+ ) {
|
|
|
this.type = COMMAND_TYPES.repeatNtimes;
|
|
|
this.var_attribution = var_attribution;
|
|
|
this.var_incrementation = var_incrementation;
|
|
@@ -169,7 +235,6 @@ export class RepeatNTimes {
|
|
|
}
|
|
|
|
|
|
export class WhileTrue {
|
|
|
-
|
|
|
constructor (expression, commands_block) {
|
|
|
this.type = COMMAND_TYPES.whiletrue;
|
|
|
this.expression = expression;
|
|
@@ -178,7 +243,6 @@ export class WhileTrue {
|
|
|
}
|
|
|
|
|
|
export class DoWhileTrue {
|
|
|
-
|
|
|
constructor (expression, commands_block) {
|
|
|
this.type = COMMAND_TYPES.dowhiletrue;
|
|
|
this.expression = expression;
|
|
@@ -187,7 +251,6 @@ export class DoWhileTrue {
|
|
|
}
|
|
|
|
|
|
export class Switch {
|
|
|
-
|
|
|
constructor (variable, cases = []) {
|
|
|
this.type = COMMAND_TYPES.switch;
|
|
|
this.variable = variable;
|
|
@@ -196,24 +259,21 @@ export class Switch {
|
|
|
}
|
|
|
|
|
|
export class Return {
|
|
|
-
|
|
|
- constructor (variable_value_menu) {
|
|
|
+ constructor (variable_value_menu) {
|
|
|
this.type = COMMAND_TYPES.return;
|
|
|
this.variable_value_menu = variable_value_menu;
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export class SwitchCase {
|
|
|
-
|
|
|
- constructor (variable_value_menu, commands_block = []) {
|
|
|
+ constructor (variable_value_menu, commands_block = []) {
|
|
|
this.type = COMMAND_TYPES.switchcase;
|
|
|
this.variable_value_menu = variable_value_menu;
|
|
|
this.commands_block = commands_block;
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export class FunctionCall {
|
|
|
-
|
|
|
constructor (function_called, parameters_list) {
|
|
|
this.type = COMMAND_TYPES.functioncall;
|
|
|
this.function_called = function_called;
|
|
@@ -222,8 +282,14 @@ export class FunctionCall {
|
|
|
}
|
|
|
|
|
|
export class VariableValueMenu {
|
|
|
-
|
|
|
- constructor (variable_and_value = 7, content = null, row = null, column = null, include_constant = true, dimensions = 0) {
|
|
|
+ constructor (
|
|
|
+ variable_and_value = 7,
|
|
|
+ content = null,
|
|
|
+ row = null,
|
|
|
+ column = null,
|
|
|
+ include_constant = true,
|
|
|
+ dimensions = 0
|
|
|
+ ) {
|
|
|
this.type = "var_value";
|
|
|
this.variable_and_value = variable_and_value;
|
|
|
this.content = content;
|
|
@@ -235,7 +301,6 @@ export class VariableValueMenu {
|
|
|
}
|
|
|
|
|
|
export class FunctionCallMenu {
|
|
|
-
|
|
|
constructor (function_called = null, parameters_list = []) {
|
|
|
this.type = "function_call";
|
|
|
this.function_called = function_called;
|
|
@@ -244,31 +309,41 @@ export class FunctionCallMenu {
|
|
|
}
|
|
|
|
|
|
export class Program {
|
|
|
-
|
|
|
constructor () {
|
|
|
this.functions = [];
|
|
|
this.globals = [];
|
|
|
}
|
|
|
|
|
|
addFunction (function_to_add) {
|
|
|
-
|
|
|
- WatchJS.watch(function_to_add.parameters_list, function(){
|
|
|
- if (window.insertContext) {
|
|
|
- setTimeout(function(){ AlgorithmManagement.renderAlgorithm(); }, 300);
|
|
|
- window.insertContext = false;
|
|
|
- } else {
|
|
|
- AlgorithmManagement.renderAlgorithm();
|
|
|
- }
|
|
|
- }, 1);
|
|
|
-
|
|
|
- WatchJS.watch(function_to_add.variables_list, function(){
|
|
|
- if (window.insertContext) {
|
|
|
- setTimeout(function(){ AlgorithmManagement.renderAlgorithm(); }, 300);
|
|
|
- window.insertContext = false;
|
|
|
- } else {
|
|
|
- AlgorithmManagement.renderAlgorithm();
|
|
|
- }
|
|
|
- }, 1);
|
|
|
+ WatchJS.watch(
|
|
|
+ function_to_add.parameters_list,
|
|
|
+ function () {
|
|
|
+ if (window.insertContext) {
|
|
|
+ setTimeout(function () {
|
|
|
+ AlgorithmManagement.renderAlgorithm();
|
|
|
+ }, 300);
|
|
|
+ window.insertContext = false;
|
|
|
+ } else {
|
|
|
+ AlgorithmManagement.renderAlgorithm();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ 1
|
|
|
+ );
|
|
|
+
|
|
|
+ WatchJS.watch(
|
|
|
+ function_to_add.variables_list,
|
|
|
+ function () {
|
|
|
+ if (window.insertContext) {
|
|
|
+ setTimeout(function () {
|
|
|
+ AlgorithmManagement.renderAlgorithm();
|
|
|
+ }, 300);
|
|
|
+ window.insertContext = false;
|
|
|
+ } else {
|
|
|
+ AlgorithmManagement.renderAlgorithm();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ 1
|
|
|
+ );
|
|
|
|
|
|
this.functions.push(function_to_add);
|
|
|
}
|