123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- import * as VariableValueMenuManagement from './commands/variable_value_menu';
- 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"});
- export class Variable {
- constructor (type, name, value, dimensions = 0, is_constant = false, rows = 0, columns = 0) {
- this.type = type;
- this.name = name;
- this.value = value;
- this.dimensions = dimensions;
- this.is_constant = is_constant;
- this.rows = rows;
- this.columns = columns;
- }
- }
- 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 = []) {
- this.type = COMMAND_TYPES.function;
- this.name = name;
- this.return_type = return_type;
- this.return_dimensions = return_dimensions;
- this.parameters_list = parameters_list;
- this.is_main = is_main;
- this.is_hidden = is_hidden;
- this.variables_list = variables_list;
- this.function_comment = function_comment;
- this.commands = commands;
- }
- }
- export class Comment {
-
- constructor (comment_text) {
- this.type = COMMAND_TYPES.comment;
- this.comment_text = comment_text;
- }
- }
- 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;
- }
- }
- export class Writer {
- constructor (content) {
- this.type = COMMAND_TYPES.writer;
- this.content = content;
- }
- }
- export class Attribution {
- constructor (variable, expression = []) {
- this.type = COMMAND_TYPES.attribution;
- this.variable = variable;
- this.expression = expression;
- }
- }
- export class ExpressionElement {
- constructor (type_exp, itens = []) {
- this.type_exp = type_exp;
- this.itens = itens;
- }
- }
- export class ConditionalExpression {
- constructor (expression) {
- this.type = EXPRESSION_TYPES.exp_conditional;
- this.expression = expression;
- }
- }
- export class LogicExpression {
- constructor (has_neg, first_operand, second_operand, operator) {
- this.type = EXPRESSION_TYPES.exp_logic;
- this.has_neg = has_neg;
- this.first_operand = first_operand;
- this.second_operand = second_operand;
- this.operator = operator;
- }
- }
- export class ArithmeticExpression {
- constructor (first_operand, second_operand, operator) {
- this.type = EXPRESSION_TYPES.exp_arithmetic;
- this.first_operand = first_operand;
- this.second_operand = second_operand;
- this.operator = operator;
- }
- }
- export class IfTrue {
- constructor (expression, commands_block, commands_else) {
- this.type = COMMAND_TYPES.iftrue;
- this.expression = expression;
- this.commands_block = commands_block;
- this.commands_else = commands_else;
- }
- }
- export class RepeatNTimes {
- 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;
- this.expression1 = expression1;
- this.expression2 = expression2;
- this.expression3 = expression3;
- this.commands_block = commands_block;
- }
- }
- export class WhileTrue {
- constructor (expression, commands_block) {
- this.type = COMMAND_TYPES.whiletrue;
- this.expression = expression;
- this.commands_block = commands_block;
- }
- }
- export class DoWhileTrue {
- constructor (expression, commands_block) {
- this.type = COMMAND_TYPES.dowhiletrue;
- this.expression = expression;
- this.commands_block = commands_block;
- }
- }
- export class Switch {
- constructor (variable, cases = []) {
- this.type = COMMAND_TYPES.switch;
- this.variable = variable;
- this.cases = cases;
- }
- }
- export class Return {
- 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 = []) {
- 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;
- this.parameters_list = parameters_list;
- }
- }
- export class VariableValueMenu {
-
- constructor (variable_and_value = 7, content = null, row = null, column = null, include_constant = true) {
- this.type = "var_value";
- this.variable_and_value = variable_and_value;
- this.content = content;
- this.row = row;
- this.column = column;
- this.include_constant = include_constant;
- }
- }
- export class FunctionCallMenu {
-
- constructor (function_called = null, parameters_list = []) {
- this.type = "function_call";
- this.function_called = function_called;
- this.parameters_list = parameters_list;
- }
- }
- export class Program {
- constructor () {
- this.functions = [];
- this.globals = [];
- }
- addFunction (function_to_add) {
- WatchJS.watch(function_to_add.parameters_list, function(){
- console.log("os parametros da função abaixo foram alterados:");
- console.log(function_to_add);
- }, 1);
- WatchJS.watch(function_to_add.variables_list, function(){
- console.log("as variáveis da função abaixo foram alteradas: ");
- console.log(function_to_add);
- AlgorithmManagement.renderAlgorithm();
- }, 1);
- this.functions.push(function_to_add);
- }
- addVariable (function_to_receive, variable) {
- if (this.functions[function_to_receive].variable === null) {
- this.functions[function_to_receive].variables_list = [];
- }
- this.functions[function_to_receive].variables_list.push(variable);
- }
- addGlobal (variable) {
- this.globals.push(variable);
- }
- }
|