123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- import { Types } from './../ast/types';
- 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", functioncall:"functioncall"});
- 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 = null, is_main = false, is_hidden = false, variables_list = [], function_comment = null) {
- 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 = [];
- }
- }
- export class Comment {
-
- constructor (comment_text) {
- this.type = COMMAND_TYPES.comment;
- this.comment_text = comment_text;
- }
- }
- export class Reader {
-
- constructor (variable = null, row = null, column = null) {
- this.type = COMMAND_TYPES.reader;
- this.variable = variable;
- this.row = row;
- this.column = column;
- }
- }
- 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 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 (expression1, expression2, expression3, commands_block) {
- this.type = COMMAND_TYPES.repeatNtimes;
- 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, commands_blocks) {
- this.type = COMMAND_TYPES.switch;
- this.variable = variable;
- this.cases = cases;
- this.commands_blocks = commands_blocks;
- }
- }
- 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 Program {
- constructor () {
- this.functions = [];
- this.globals = [];
- }
- addFunction (function_to_add) {
- 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);
- }
- }
|