ivprog-visual-1.0.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // Definição das classes utilizadas para armazenar o algoritmo
  2. // Não adicionar elementos ao tipoDados, pois existem componentes que dependem do seu tamanho e isso afetará seu funcionamento
  3. var tiposDados = Object.freeze({void:"void", integer:"integer", real:"real", text:"text", boolean:"boolean", vector:"vector"});
  4. var tiposComandos = Object.freeze({comment:"comment", reader:"reader", writer:"writer", attribution:"attribution", iftrue:"iftrue",
  5. repeatNtimes:"repeatNtimes", whiletrue:"whiletrue", dowhiletrue:"dowhiletrue", switch:"switch", functioncall:"functioncall"});
  6. var Variavel = function(tipo, nome, valor, dimensoes = 0, eh_constante = false, linhas = 0, colunas = 0) {
  7. this.tipo = tipo;
  8. this.nome = nome;
  9. this.valor = valor;
  10. this.dimensoes = dimensoes;
  11. this.eh_constante = eh_constante;
  12. this.linhas = linhas;
  13. this.colunas = colunas;
  14. };
  15. var Funcao = function(nome, tipo_retorno = tiposDados.void, dimensoes_retorno = 0, lista_parametros = null, eh_principal = false, esta_oculta = false, variaveis = null, comentario_funcao = null) {
  16. this.nome = nome;
  17. this.tipo_retorno = tipo_retorno;
  18. this.dimensoes_retorno = dimensoes_retorno;
  19. this.lista_parametros = lista_parametros;
  20. this.eh_principal = eh_principal;
  21. this.esta_oculta = esta_oculta;
  22. this.variaveis = variaveis;
  23. this.comentario_funcao = comentario_funcao;
  24. this.comandos = null;
  25. };
  26. var Comentario = function(texto_comentario) {
  27. this.tipo = tiposComandos.comment;
  28. this.texto_comentario = texto_comentario;
  29. };
  30. var Leitura = function(variavel) {
  31. this.tipo = tiposComandos.reader;
  32. this.variavel = variavel;
  33. };
  34. var Escrita = function(conteudo) {
  35. this.tipo = tiposComandos.writer;
  36. this.conteudo = conteudo;
  37. };
  38. var Atribuicao = function(variavel, expressao) {
  39. this.tipo = tiposComandos.attribution;
  40. this.variavel = variavel;
  41. this.expressao = expressao;
  42. };
  43. var SeVerdadeiro = function(expressao, commands_block, commands_else) {
  44. this.tipo = tiposComandos.iftrue;
  45. this.expressao = expressao;
  46. this.commands_block = commands_block;
  47. this.commands_else = commands_else;
  48. };
  49. var RepitaNVezes = function(expressao1, expressao2, expressao3, commands_block) {
  50. this.tipo = tiposComandos.repeatNtimes;
  51. this.expressao1 = expressao1;
  52. this.expressao2 = expressao2;
  53. this.expressao3 = expressao3;
  54. this.commands_block = commands_block;
  55. };
  56. var EnquantoVerdadeiro = function(expressao, commands_block) {
  57. this.tipo = tiposComandos.whiletrue;
  58. this.expressao = expressao;
  59. this.commands_block = commands_block;
  60. };
  61. var FacaEnquantoVerdadeiro = function(expressao, commands_block) {
  62. this.tipo = tiposComandos.dowhiletrue;
  63. this.expressao = expressao;
  64. this.commands_block = commands_block;
  65. };
  66. var Escolha = function(variavel, lista_casos_e_blocos) {
  67. this.tipo = tiposComandos.switch;
  68. this.variavel = variavel;
  69. this.lista_casos_e_blocos = lista_casos_e_blocos;
  70. };
  71. var ChamadaFuncao = function(funcao, lista_parametros) {
  72. this.tipo = tiposComandos.functioncall;
  73. this.funcao = funcao;
  74. this.lista_parametros = lista_parametros;
  75. }
  76. var Programa = function () {
  77. this.funcoes = new Array();
  78. this.globais = new Array();
  79. };
  80. function adicionarFuncao(funcao) {
  81. programa.funcoes.push(funcao);
  82. }
  83. function adicionarVariavel(funcao, variavel) {
  84. if (programa.funcoes[funcao].variaveis == null) {
  85. programa.funcoes[funcao].variaveis = new Array();
  86. }
  87. programa.funcoes[funcao].variaveis.push(variavel);
  88. }
  89. //var tex = i18n('text');
  90. // Adicionando a função principal automaticamente
  91. var programa = new Programa();
  92. var funcaoPrincipal = new Funcao(i18n("start"), tiposDados.void, 0, [], true);
  93. funcaoPrincipal.comentario_funcao = new Comentario(i18n('text_comment_main'));
  94. //funcaoPrincipal.lista_parametros.push(new Variavel(tiposDados.text, "args"));
  95. adicionarFuncao(funcaoPrincipal);
  96. var funcaoSomar = new Funcao("somar", tiposDados.integer, 0, [], false, false, null, new Comentario(i18n('text_comment_start')));
  97. funcaoSomar.lista_parametros.push(new Variavel(tiposDados.integer, "a"));
  98. funcaoSomar.lista_parametros.push(new Variavel(tiposDados.integer, "b"));
  99. //adicionarFuncao(funcaoSomar);