codeParser.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import * as Models from '../visualUI/ivprog_elements';
  2. function parseGlobal (global_obj) {
  3. var new_global = new Models.Variable(
  4. global_obj.type,
  5. global_obj.name,
  6. global_obj.value);
  7. new_global.is_constant = global_obj.is_const;
  8. new_global.columns = global_obj.columns;
  9. new_global.dimension = global_obj.dimension;
  10. new_global.rows = global_obj.rows;
  11. window.program_obj.addGlobal(new_global);
  12. }
  13. function parseParameter (parameter_obj) {
  14. const new_parameter = new Models.Variable(
  15. parameter_obj.type,
  16. parameter_obj.name,
  17. null,
  18. parameter_obj.dimension,
  19. parameter_obj.is_const,
  20. parameter_obj.rows,
  21. parameter_obj.columns,
  22. parameter_obj.reference
  23. );
  24. return new_parameter;
  25. }
  26. function parseFunction (function_obj) {
  27. console.log(function_obj)
  28. const new_function = new Models.Function(
  29. function_obj.name,
  30. function_obj.return_type,
  31. function_obj.return_dimensions,
  32. [],
  33. false,
  34. false,
  35. []);
  36. if (!new_function.name) {
  37. new_function.name = LocalizedStrings.getUI("start");
  38. new_function.is_main = true;
  39. }
  40. if (function_obj.parameters_list) {
  41. function_obj.parameters_list.forEach(function(el){
  42. new_function.parameters_list.push(parseParameter(el));
  43. });
  44. }
  45. window.program_obj.addFunction(new_function);
  46. }
  47. export function parserCodeVisual (code_obj = null) {
  48. console.log('chegou!', code_obj)
  49. window.conteudo = code_obj
  50. // Globals:
  51. window.program_obj.globals = [];
  52. code_obj.globals.forEach(parseGlobal);
  53. // Functions:
  54. window.program_obj.functions = [];
  55. code_obj.functions.forEach(parseFunction);
  56. }