ivprog-visual-1.0.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 Variavel = function(tipo, nome, valor, dimensoes = 0, eh_constante = false, linhas = 0, colunas = 0) {
  5. this.tipo = tipo;
  6. this.nome = nome;
  7. this.valor = valor;
  8. this.dimensoes = dimensoes;
  9. this.eh_constante = eh_constante;
  10. this.linhas = linhas;
  11. this.colunas = colunas;
  12. };
  13. var Funcao = function(nome, tipo_retorno = tiposDados.void, dimensoes_retorno = 0, lista_parametros = null, eh_principal = false, esta_oculta = false, variaveis = null) {
  14. this.nome = nome;
  15. this.tipo_retorno = tipo_retorno;
  16. this.dimensoes_retorno = dimensoes_retorno;
  17. this.lista_parametros = lista_parametros;
  18. this.eh_principal = eh_principal;
  19. this.esta_oculta = esta_oculta;
  20. this.variaveis = variaveis;
  21. };
  22. var Comando = function(tipo) {
  23. this.tipo = tipo;
  24. };
  25. var Expressao = function(conteudo) {
  26. this.conteudo = conteudo;
  27. };
  28. var Programa = function () {
  29. this.funcoes = new Array();
  30. };
  31. function adicionarFuncao(funcao) {
  32. programa.funcoes.push(funcao);
  33. }
  34. function adicionarVariavel(funcao, variavel) {
  35. if (programa.funcoes[funcao].variaveis == null) {
  36. programa.funcoes[funcao].variaveis = new Array();
  37. }
  38. programa.funcoes[funcao].variaveis.push(variavel);
  39. }
  40. //var tex = i18n('text');
  41. // Adicionando a função principal automaticamente
  42. var programa = new Programa();
  43. var funcaoPrincipal = new Funcao(i18n("start"), tiposDados.void, 0, new Array(), true);
  44. //funcaoPrincipal.lista_parametros.push(new Variavel(tiposDados.text, "args"));
  45. adicionarFuncao(funcaoPrincipal);
  46. var funcaoSomar = new Funcao("somar", tiposDados.integer, 0, new Array(), false);
  47. funcaoSomar.lista_parametros.push(new Variavel(tiposDados.integer, "a"));
  48. funcaoSomar.lista_parametros.push(new Variavel(tiposDados.integer, "b"));
  49. adicionarFuncao(funcaoSomar);