ivprog-visual-1.0.js 1.9 KB

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