Quellcode durchsuchen

Finalizada para ser disponibilizada

Igor vor 5 Jahren
Ursprung
Commit
7f9c7402e9
100 geänderte Dateien mit 1274 neuen und 457 gelöschten Zeilen
  1. 26 11
      download.html
  2. 792 305
      ivprogh/build/ivprog.bundle.js
  3. 1 1
      ivprogh/build/ivprog.bundle.js.map
  4. 0 0
      ivprogh/css/ivprog-term.css
  5. 75 10
      ivprogh/css/ivprog-visual-1.0.css
  6. 0 0
      ivprogh/i18n/en/error.json
  7. 0 0
      ivprogh/i18n/en/index.js
  8. 0 0
      ivprogh/i18n/en/message.json
  9. 8 2
      ivprogh/i18n/en/ui.json
  10. 0 0
      ivprogh/i18n/es/error.json
  11. 0 0
      ivprogh/i18n/es/index.js
  12. 0 0
      ivprogh/i18n/es/message.json
  13. 8 2
      ivprogh/i18n/es/ui.json
  14. 0 0
      ivprogh/i18n/i18n-database.json
  15. 0 0
      ivprogh/i18n/index.js
  16. 0 0
      ivprogh/i18n/pt/error.json
  17. 0 0
      ivprogh/i18n/pt/index.js
  18. 0 0
      ivprogh/i18n/pt/message.json
  19. 8 2
      ivprogh/i18n/pt/ui.json
  20. 0 0
      ivprogh/img/background-panel.png
  21. 0 0
      ivprogh/index.html
  22. 0 0
      ivprogh/js/Sortable.js
  23. 1 1
      ivprogh/js/assessment/ivprogAssessment.js
  24. 0 0
      ivprogh/js/ast/ASA.txt
  25. 0 0
      ivprogh/js/ast/commands/arrayAssign.js
  26. 0 0
      ivprogh/js/ast/commands/arrayDeclaration.js
  27. 0 0
      ivprogh/js/ast/commands/assign.js
  28. 0 0
      ivprogh/js/ast/commands/break.js
  29. 0 0
      ivprogh/js/ast/commands/case.js
  30. 0 0
      ivprogh/js/ast/commands/command.js
  31. 0 0
      ivprogh/js/ast/commands/commandBlock.js
  32. 0 0
      ivprogh/js/ast/commands/declaration.js
  33. 0 0
      ivprogh/js/ast/commands/doWhile.js
  34. 0 0
      ivprogh/js/ast/commands/for.js
  35. 0 0
      ivprogh/js/ast/commands/formalParameter.js
  36. 0 0
      ivprogh/js/ast/commands/function.js
  37. 0 0
      ivprogh/js/ast/commands/ifThenElse.js
  38. 0 0
      ivprogh/js/ast/commands/index.js
  39. 0 0
      ivprogh/js/ast/commands/return.js
  40. 0 0
      ivprogh/js/ast/commands/switch.js
  41. 0 0
      ivprogh/js/ast/commands/sysCall.js
  42. 0 0
      ivprogh/js/ast/commands/while.js
  43. 0 0
      ivprogh/js/ast/error/syntaxError.js
  44. 0 0
      ivprogh/js/ast/error/syntaxErrorFactory.js
  45. 0 0
      ivprogh/js/ast/expressions/arrayAccess.js
  46. 1 1
      ivprogh/js/ast/expressions/arrayLiteral.js
  47. 0 0
      ivprogh/js/ast/expressions/boolLiteral.js
  48. 0 0
      ivprogh/js/ast/expressions/expression.js
  49. 0 0
      ivprogh/js/ast/expressions/functionCall.js
  50. 0 0
      ivprogh/js/ast/expressions/index.js
  51. 0 0
      ivprogh/js/ast/expressions/infixApp.js
  52. 0 0
      ivprogh/js/ast/expressions/intLiteral.js
  53. 0 0
      ivprogh/js/ast/expressions/literal.js
  54. 0 0
      ivprogh/js/ast/expressions/realLiteral.js
  55. 0 0
      ivprogh/js/ast/expressions/stringLiteral.js
  56. 0 0
      ivprogh/js/ast/expressions/unaryApp.js
  57. 0 0
      ivprogh/js/ast/expressions/variableLiteral.js
  58. 0 0
      ivprogh/js/ast/ivprogParser.js
  59. 0 0
      ivprogh/js/ast/operators.js
  60. 0 0
      ivprogh/js/ast/sourceInfo.js
  61. 117 38
      ivprogh/js/iassign-integration-functions.js
  62. 0 0
      ivprogh/js/io/domConsole.js
  63. 0 0
      ivprogh/js/io/domInput.js
  64. 0 0
      ivprogh/js/io/domOutput.js
  65. 0 0
      ivprogh/js/io/input.js
  66. 0 0
      ivprogh/js/io/output.js
  67. 0 0
      ivprogh/js/jquery-3.3.1.min.js
  68. 0 0
      ivprogh/js/jquery-ui.js
  69. 0 0
      ivprogh/js/jquery.json-editor.min.js
  70. 0 0
      ivprogh/js/main.js
  71. 33 0
      ivprogh/js/processor/compatibilityTable.js
  72. 0 0
      ivprogh/js/processor/context.js
  73. 0 0
      ivprogh/js/processor/definedFunctions.js
  74. 0 0
      ivprogh/js/processor/error/processorErrorFactory.js
  75. 0 0
      ivprogh/js/processor/error/runtimeError.js
  76. 0 0
      ivprogh/js/processor/error/semanticError.js
  77. 125 42
      ivprogh/js/processor/ivprogProcessor.js
  78. 0 0
      ivprogh/js/processor/lib/arrays.js
  79. 2 12
      ivprogh/js/processor/lib/io.js
  80. 0 0
      ivprogh/js/processor/lib/lang.js
  81. 0 0
      ivprogh/js/processor/lib/math.js
  82. 0 0
      ivprogh/js/processor/lib/strings.js
  83. 0 0
      ivprogh/js/processor/modes.js
  84. 55 29
      ivprogh/js/processor/semantic/semanticAnalyser.js
  85. 22 1
      ivprogh/js/processor/store/store.js
  86. 0 0
      ivprogh/js/processor/store/storeObject.js
  87. 0 0
      ivprogh/js/processor/store/storeObjectArray.js
  88. 0 0
      ivprogh/js/processor/store/storeObjectArrayAddress.js
  89. 0 0
      ivprogh/js/processor/store/storeObjectArrayAddressRef.js
  90. 0 0
      ivprogh/js/processor/store/storeObjectRef.js
  91. 0 0
      ivprogh/js/runner.js
  92. 0 0
      ivprogh/js/semantic/.versions
  93. 0 0
      ivprogh/js/semantic/LICENSE
  94. 0 0
      ivprogh/js/semantic/README.md
  95. 0 0
      ivprogh/js/semantic/components/accordion.css
  96. 0 0
      ivprogh/js/semantic/components/accordion.js
  97. 0 0
      ivprogh/js/semantic/components/accordion.min.css
  98. 0 0
      ivprogh/js/semantic/components/accordion.min.js
  99. 0 0
      ivprogh/js/semantic/components/ad.css
  100. 0 0
      ivprogh/js/semantic/components/ad.min.css

+ 26 - 11
download.html

@@ -80,7 +80,7 @@
         </div>
 
         <div class="col-md-4 box-download">
-          <h4 class="my-4 ivprogh-title-download"> <span class="octicon octicon-desktop-download"></span> Baixar o iVProgH</h4>
+          <h4 class="my-4 ivprogh-title-download"> <span class="octicon octicon-desktop-download"></span> Descarregar o iVProgH</h4>
           
           <li>Totalmente gratuito e código livre</li>
           <li>Inclui avaliador automático</li>
@@ -89,8 +89,8 @@
           <li>Só precisa de um navegador para funcionar!</li>
           
           <div class="div-button">
-            <a class="btn btn-primary download-ivprog" href="#" role="button" title=""> <span class="octicon octicon-desktop-download"></span> Download</a>
-            <span class="span-version">Atualização 2018/12/18</span>
+            <a class="btn btn-primary download-ivprog" href="versions/ivprogh_stable.tar.gz" role="button" title=""> <span class="octicon octicon-desktop-download"></span> Download</a>
+            <span class="span-version">Atualização 2019/01/12</span>
           </div>
         </div>
       </div>
@@ -101,11 +101,11 @@
 
       <div class="row">
         <div class="col-md-12">
-          <p>Ao longo do tempo, o iVProg passou por melhorias e modificações, mantendo total compatibilidade com os navegadores atuais. Inicialmente foi desenvolvido em Java no formato de applet (Versão I - Java e Versão II - Java), precisou ser reescrito após o bloqueio da execução de applets pelos principais navegadores do mercado, resultando na Versão I - HTML.</p>
+          <p>Ao longo do tempo, o iVProg passou por melhorias e modificações, mantendo total compatibilidade com os navegadores atuais. Inicialmente foi desenvolvido em Java no formato de applet (Versão I - Java e Versão II - Java), precisou ser reescrito após o bloqueio da execução de applets pelos principais navegadores do mercado, resultando na Versão III - HTML.</p>
           
-          <p>A Versão III - HTML continua funcionando nos navegadores e integradas a ambientes virtuais. Contudo, novos recursos foram implementados, como vetores, matriz e funções (Versão IV - HTML, que é a mais recente).</p>
+          <p>A Versão III - HTML continua funcionando nos navegadores e pode ser integrada à sistemas Web. Contudo, para possibilitar novos recursos (como vetores, matrizes e funções), foi desenvolvida uma versão completamente nova (Versão IV - HTML).</p>
 
-          <p>Abaixo, você encontra as versões anteriores, que podem ser baixadas e utilizadas livremente.</p>
+          <p>Abaixo, você encontra as versões anteriores, que podem ser descarregadas e utilizadas livremente.</p>
         </div>
       </div>
       <div class="modal fade" id="enlargeImageModal" tabindex="-1" role="dialog" aria-labelledby="enlargeImageModal" aria-hidden="true">
@@ -126,19 +126,19 @@
       <div class="container">
         <div class="row thumbs-ivprog-download">
           <div class="col-md-1"></div>
-          <div class="col-md-3 item">
+          <div class="col-md-3 item" data-version="1">
             <img class="img-fluid zoom-images" src="img/img_ivprog_java_1.png" alt="Versão I - Java">
             <hr>
             <span class="history-ivprog-version">Versão I - Java</span>
             <span class="history-ivprog-time">2009 - 2012</span>
           </div>
-          <div class="col-md-3 item">
+          <div class="col-md-3 item" data-version="2">
             <img class="img-fluid zoom-images" src="img/img_ivprog_java_2.1.0.png" alt="Versão II - Java">
             <hr>
             <span class="history-ivprog-version">Versão II - Java</span>
             <span class="history-ivprog-time">2013 - 2015</span>
           </div>
-          <div class="col-md-3 item">
+          <div class="col-md-3 item" data-version="3">
             <img class="img-fluid zoom-images" src="img/img_ivprog_html_1.png" alt="Versão III - HTML">
             <hr>
             <span class="history-ivprog-version">Versão III - HTML</span>
@@ -172,9 +172,24 @@
           $('.enlargeImageModalSource').attr('src', $(this).attr('src'));
           $('#enlargeImageModal').modal('show');
         });
-       $('.item').on('click', ':not(.zoom-images)', function(e) {
+       $('.item').on('click', function(e) {
           e.stopPropagation();
-          console.log('teste');
+          if (e.target.nodeName.toLowerCase() === 'img') {
+            return;
+          }
+          var r_url = '';
+          switch ($(this).data('version')) {
+            case 1:
+              r_url = 'legacy/versao1/index.html';
+              break;
+            case 2:
+              r_url = 'legacy/versao2/index.html';
+              break;
+            case 3:
+              r_url = 'legacy/versao3/index.html';
+              break;
+          }
+          document.location = r_url;
        });
   });
     </script>

Datei-Diff unterdrückt, da er zu groß ist
+ 792 - 305
ivprogh/build/ivprog.bundle.js


Datei-Diff unterdrückt, da er zu groß ist
+ 1 - 1
ivprogh/build/ivprog.bundle.js.map


+ 0 - 0
ivprogh/css/ivprog-term.css


+ 75 - 10
ivprogh/css/ivprog-visual-1.0.css

@@ -154,7 +154,7 @@ body {
 .expression_operand_1, .expression_operand_2, .operator, .div_comment_text, .value_rendered, .parameters_function_called, .parameters_function_called div, .expression_elements,
 .expression_element, .var_rendered, .menu_add_item, .component_element, .component_element, .conditional_expression, .variable_attribution, .attribution_expression, .var_value_expression,
 .incrementation_field, .incrementation_variable, .first_operand, .operator, .second_operand, .variable_to_switch, .variable_case, .button_remove_case, .editing_name_var, .parameter_div_edit,
-.all_elements_write, .container_var_element_control, .inline_add_command {
+.all_elements_write, .container_var_element_control, .inline_add_command, .restart_expression, .div_parent_handler, .div_drag_writer {
 	display: inline;
 }
 
@@ -280,11 +280,12 @@ div.buttons_manage_columns {
 }
 .ui.comment, .ui.reader, .ui.writer, .ui.attribution, .ui.iftrue, .ui.repeatNtimes, .ui.whiletrue, .ui.dowhiletrue, .ui.switch, .ui.functioncall,
 .ui.return {
-	border: 1px solid gray;
 	padding: 5px;
-	border-radius: 5px;
 	margin: 5px;
-	background: #f9f9f9;
+	background: #f7f2c9;
+    border: 2px solid #4d4be3;
+    border-radius: 0.25em;
+    box-shadow: 1px 1px;
 }
 .ui.repeatNtimes .separator_character {
 	margin-right: 10px;
@@ -354,7 +355,10 @@ div.buttons_manage_columns {
 
 .ui.icon.red.exclamation.triangle.error_icon {
 	float: left;
-    margin-left: -30px;
+    margin-left: -1.6em;
+    z-index: 10;
+    position: absolute;
+    font-size: 1.5em;
 }
 
 .height_100 {
@@ -769,11 +773,6 @@ div.function_name_div_updated:active,
 	opacity: 1 !important;
 }
 
-.command_container {
-    background: #e9dede !important;
-	border: 2px solid #e76060 !important;
-    border-radius: 0.25em !important;
-}
 .command_drag {
 	cursor: move;
 }
@@ -790,4 +789,70 @@ div.function_name_div_updated:active,
 }
 div.ui.checkbox.transition.visible {
 	margin-bottom: 1em;
+}
+.var_menu_select_content_error {
+	background: #ff0000;
+    color: white !important;
+    border: 2px solid #3125ee;
+}
+.ui.comment:hover, .ui.reader:hover, .ui.writer:hover, .ui.attribution:hover, .ui.functioncall:hover,
+.ui.return:hover {
+    background: #f2e67f;
+}
+
+.ui.iftrue:hover, .ui.repeatNtimes:hover, .ui.whiletrue:hover, .ui.dowhiletrue:hover, .ui.switch:hover {
+	background: #c6c8f2;
+}
+
+.ui.iftrue, .ui.repeatNtimes, .ui.whiletrue, .ui.dowhiletrue, .ui.switch {
+    background: #787fe721;
+}
+.ui.popup.invalid-identifier {
+	background: #ff3232;
+    color: white;
+    font-weight: bold;
+    border: 1px solid black;
+}
+.ui.popup.invalid-identifier:before {
+	background: #ff3232;
+	border-right: 1px solid black;
+    border-bottom: 1px solid black;
+}
+.ui.popup.invalid-identifier i.ui.icon.inverted.exclamation.triangle.yellow {
+	margin-left: -.5em;
+    margin-right: .4em;
+}
+.ui.repeatNtimes.command_container .ui.block_commands, 
+.ui.whiletrue.command_container .ui.block_commands {
+	margin-top: .8em;
+}
+
+.ui.restart_expression {
+	margin-left: .4em;
+    cursor: pointer;
+    color: brown;
+}
+
+.div_parent_handler {
+	padding-top: 5px;
+    padding-bottom: 6px;
+    background: #7a7acf;
+    border-radius: 4px;
+}
+
+.div_parent_handler i.times {
+	margin-left: .3em;
+	cursor: pointer;
+}
+
+.div_parent_handler i.ellipsis {
+	cursor: move;
+}
+
+.div_parent_handler i.handler {
+	opacity: 0;
+}
+
+.div_parent_handler:hover i.handler {
+	opacity: 1;
 }

+ 0 - 0
ivprogh/i18n/en/error.json


+ 0 - 0
ivprogh/i18n/en/index.js


+ 0 - 0
ivprogh/i18n/en/message.json


+ 8 - 2
ivprogh/i18n/en/ui.json

@@ -44,7 +44,7 @@
   "text_code_switch": "switch",
   "text_code_case": "case",
   "text_logic_expression": "Logic Expression",
-  "text_arithmetic_expression": "Arithmetic Expression",
+  "text_arithmetic_expression": "Relational Expression",
   "text_iftrue": "If true then",
   "text_receives": "receives",
   "text_repeatNtimes": "Repeat N times",
@@ -94,9 +94,15 @@
   "var_menu_select_var": "Select a var",
   "var_menu_select_all": "Select",
   "var_menu_select_function": "Select a function",
-  "expression_menu_select": "Select an expression",
+  "expression_menu_select": "Construct any logical condition",
   "math": "Mathematic",
   "text_t": "Text",
+  "inform_valid_name": "Inform a valid name!",
+  "inform_valid_content": "Enter some content!",
+  "inform_valid_expression": "Construct the logical condition!",
+  "inform_valid_name_duplicated": "This name is already in use by other function.",
+  "inform_valid_global_duplicated": "A global variable with this name already exists.",
+  "inform_valid_variable_duplicated" : "A local variable with this name already exists.",
   "arrangement": "Arrangement",
   "conversion": "Conversion",
   "$sin": "sin",

+ 0 - 0
ivprogh/i18n/es/error.json


+ 0 - 0
ivprogh/i18n/es/index.js


+ 0 - 0
ivprogh/i18n/es/message.json


+ 8 - 2
ivprogh/i18n/es/ui.json

@@ -46,7 +46,7 @@
   "text_code_switch": "switch",
   "text_code_case": "case",
   "text_logic_expression": "Logic Expression",
-  "text_arithmetic_expression": "Arithmetic Expression",
+  "text_arithmetic_expression": "Relational Expression",
   "text_iftrue": "If true then",
   "text_repeatNtimes": "Repeat N times",
   "text_receives": "receives",
@@ -94,13 +94,19 @@
   "var_menu_select_var": "Select a var",
   "var_menu_select_all": "Select",
   "var_menu_select_function": "Select a function",
-  "expression_menu_select": "Select an expression",
+  "expression_menu_select": "Construct any logical condition",
   "$sin": "sen",
   "math": "Mathematic",
   "text": "Text",
   "arrangement": "Arrangement",
   "conversion": "Conversion",
   "math": "Mathematic",
+  "inform_valid_name": "Inform a valid name!",
+  "inform_valid_content": "Enter some content!",
+  "inform_valid_expression": "Construct the logical condition!",
+  "inform_valid_name_duplicated": "This name is already in use by other function.",
+  "inform_valid_global_duplicated": "A global variable with this name already exists.",
+  "inform_valid_variable_duplicated" : "A local variable with this name already exists.",
   "text_t": "Text",
   "arrangement": "Arrangement",
   "conversion": "Conversion",

+ 0 - 0
ivprogh/i18n/i18n-database.json


+ 0 - 0
ivprogh/i18n/index.js


+ 0 - 0
ivprogh/i18n/pt/error.json


+ 0 - 0
ivprogh/i18n/pt/index.js


+ 0 - 0
ivprogh/i18n/pt/message.json


+ 8 - 2
ivprogh/i18n/pt/ui.json

@@ -52,7 +52,7 @@
   "text_code_switch": "escolha",
   "text_code_case": "caso",
   "text_logic_expression": "Expressão Lógica",
-  "text_arithmetic_expression": "Expressão Aritmética",
+  "text_arithmetic_expression": "Expressão Relacional",
   "text_iftrue": "Se verdadeiro então",
   "text_repeatNtimes": "Repita N vezes",
   "text_receives": "recebe",
@@ -100,10 +100,16 @@
   "var_menu_select_var": "Selecione uma variável",
   "var_menu_select_all": "Selecione",
   "var_menu_select_function": "Selecione uma função",
-  "expression_menu_select": "Selecione uma expressão",
+  "expression_menu_select": "Construir uma expressão lógica",
   "$sin": "sen",
   "math": "Matematica",
   "text_t": "Texto",
+  "inform_valid_name": "Informe um nome válido!",
+  "inform_valid_content": "Informe o conteúdo!",
+  "inform_valid_expression": "Construa uma expressão lógica!",
+  "inform_valid_name_duplicated": "Este nome já está em uso por outra função!",
+  "inform_valid_global_duplicated": "Já existe uma variável global com o nome informado.",
+  "inform_valid_variable_duplicated" : "Já existe uma variável local com o nome informado.",
   "arrangement": "Arranjo",
   "conversion": "Conversao",
   "$sin": "seno",

+ 0 - 0
ivprogh/img/background-panel.png


+ 0 - 0
ivprogh/index.html


+ 0 - 0
ivprogh/js/Sortable.js


+ 1 - 1
ivprogh/js/assessment/ivprogAssessment.js

@@ -22,7 +22,7 @@ export class IVProgAssessment {
       const partialTests = this.testCases.map( (t, name) => {
         return this.partialEvaluateTestCase(new IVProgProcessor(validTree), t.input, t.output, name);
       });
-      const testResult = partialTests.reduce((acc, curr) => acc.then( v => curr(v)), Promise.resolve(0));
+      const testResult = partialTests.reduce((acc, curr) => acc.then(curr), Promise.resolve(0));
       return testResult.then(total => Promise.resolve(total / this.testCases.length))
         .catch(err => {
           this.domConsole.err("Erro durante a execução do programa");// try and show error messages through domconsole

+ 0 - 0
ivprogh/js/ast/ASA.txt


+ 0 - 0
ivprogh/js/ast/commands/arrayAssign.js


+ 0 - 0
ivprogh/js/ast/commands/arrayDeclaration.js


+ 0 - 0
ivprogh/js/ast/commands/assign.js


+ 0 - 0
ivprogh/js/ast/commands/break.js


+ 0 - 0
ivprogh/js/ast/commands/case.js


+ 0 - 0
ivprogh/js/ast/commands/command.js


+ 0 - 0
ivprogh/js/ast/commands/commandBlock.js


+ 0 - 0
ivprogh/js/ast/commands/declaration.js


+ 0 - 0
ivprogh/js/ast/commands/doWhile.js


+ 0 - 0
ivprogh/js/ast/commands/for.js


+ 0 - 0
ivprogh/js/ast/commands/formalParameter.js


+ 0 - 0
ivprogh/js/ast/commands/function.js


+ 0 - 0
ivprogh/js/ast/commands/ifThenElse.js


+ 0 - 0
ivprogh/js/ast/commands/index.js


+ 0 - 0
ivprogh/js/ast/commands/return.js


+ 0 - 0
ivprogh/js/ast/commands/switch.js


+ 0 - 0
ivprogh/js/ast/commands/sysCall.js


+ 0 - 0
ivprogh/js/ast/commands/while.js


+ 0 - 0
ivprogh/js/ast/error/syntaxError.js


+ 0 - 0
ivprogh/js/ast/error/syntaxErrorFactory.js


+ 0 - 0
ivprogh/js/ast/expressions/arrayAccess.js


+ 1 - 1
ivprogh/js/ast/expressions/arrayLiteral.js

@@ -25,7 +25,7 @@ export class ArrayLiteral extends Literal {
     if (!(element instanceof ArrayLiteral)){
       return null;
     } else {
-      return element.value[0].value.length;
+      return element.value[0].length;
     }
   }
 

+ 0 - 0
ivprogh/js/ast/expressions/boolLiteral.js


+ 0 - 0
ivprogh/js/ast/expressions/expression.js


+ 0 - 0
ivprogh/js/ast/expressions/functionCall.js


+ 0 - 0
ivprogh/js/ast/expressions/index.js


+ 0 - 0
ivprogh/js/ast/expressions/infixApp.js


+ 0 - 0
ivprogh/js/ast/expressions/intLiteral.js


+ 0 - 0
ivprogh/js/ast/expressions/literal.js


+ 0 - 0
ivprogh/js/ast/expressions/realLiteral.js


+ 0 - 0
ivprogh/js/ast/expressions/stringLiteral.js


+ 0 - 0
ivprogh/js/ast/expressions/unaryApp.js


+ 0 - 0
ivprogh/js/ast/expressions/variableLiteral.js


+ 0 - 0
ivprogh/js/ast/ivprogParser.js


+ 0 - 0
ivprogh/js/ast/operators.js


+ 0 - 0
ivprogh/js/ast/sourceInfo.js


+ 117 - 38
ivprogh/js/iassign-integration-functions.js

@@ -30,7 +30,12 @@ function getAnswer () {
         // Montar o retorno com a resposta do aluno
         var contentToSend = previousContent.split("\n::algorithm::")[0];
         contentToSend += '\n::algorithm::\n';
-        contentToSend += JSON.stringify(window.program_obj);
+        contentToSend += JSON.stringify(window.program_obj, function(key, value) {
+            if (key == 'dom_object') {
+                return;
+            }
+            return value; 
+        });
 
         contentToSend += '\n::logs::';
         contentToSend += getTrackingLogs();
@@ -47,10 +52,17 @@ function getAnswer () {
 
         if ($("input[name='include_algo']").is(':checked')) {
             ret += '\n::algorithm::\n';
-            ret += JSON.stringify(window.program_obj);
+            ret += JSON.stringify(window.program_obj, function(key, value) {
+                
+                if (key == 'dom_object') {
+                    return;
+                }
+                return value; 
+            });
         }
 
         return ret;
+
     }
 }
 
@@ -115,27 +127,54 @@ function getiLMContent () {
     // O parâmetro "iLM_PARAM_Assignment" fornece o URL do endereço que deve ser
     // requisitado via AJAX para a captura dos dados da atividade
     $.get(iLMparameters.iLM_PARAM_Assignment, function (data) {
+        // Aluno está trabalhando em alguma atividade:
         if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
             previousContent = data;
             prepareActivityToStudent(data);
-        } else {
-
+        } else { // Professor está editando uma atividade:
+            previousContent = data;
+            prepareActivityToEdit(data);
         }
+
+        window.block_render = false;
+        renderAlgorithm();
     });
 }
 
-function prepareActivityToStudent (ilm_cont) {
+function prepareActivityToEdit (ilm_cont) {
     var content = JSON.parse(ilm_cont.split('\n::algorithm::')[0]);
     testCases = content.testcases;
     settingsDataTypes = content.settings_data_types;
     settingsCommands = content.settings_commands;
     settingsFunctions = content.settings_functions;
+
+    for (var i = 0; i < testCases.length; i++) {
+        addTestCase(testCases[i]);
+    }
+
     if (ilm_cont.split('\n::algorithm::')[1]) {
         algorithm_in_ilm = ilm_cont.split('\n::algorithm::')[1].split('\n::logs::')[0];
-        window.program_obj.functions = JSON.parse(algorithm_in_ilm).functions;
-        window.program_obj.globals = JSON.parse(algorithm_in_ilm).globals;
+        $("input[name='include_algo']").prop('checked', true);
+        includePreviousAlgorithm();
+        renderAlgorithm();
+    }
+}
 
-        window.watchW.watch(window.program_obj.globals, function(){
+function includePreviousAlgorithm () {
+    window.program_obj.functions = JSON.parse(algorithm_in_ilm).functions;
+    window.program_obj.globals = JSON.parse(algorithm_in_ilm).globals;
+
+    window.watchW.watch(window.program_obj.globals, function(){
+      if (window.insertContext) {
+        setTimeout(function(){ renderAlgorithm(); }, 300);
+        window.insertContext = false;
+      } else {
+        renderAlgorithm();
+      }
+    }, 1);
+
+    for (var i = 0; i < window.program_obj.functions.length; i ++) {
+        window.watchW.watch(window.program_obj.functions[i].parameters_list, function(){
           if (window.insertContext) {
             setTimeout(function(){ renderAlgorithm(); }, 300);
             window.insertContext = false;
@@ -144,26 +183,7 @@ function prepareActivityToStudent (ilm_cont) {
           }
         }, 1);
 
-        for (var i = 0; i < window.program_obj.functions.length; i ++) {
-            window.watchW.watch(window.program_obj.functions[i].parameters_list, function(){
-              if (window.insertContext) {
-                setTimeout(function(){ renderAlgorithm(); }, 300);
-                window.insertContext = false;
-              } else {
-                renderAlgorithm();
-              }
-            }, 1);
-
-            window.watchW.watch(window.program_obj.functions[i].variables_list, function(){
-              if (window.insertContext) {
-                setTimeout(function(){ renderAlgorithm(); }, 300);
-                window.insertContext = false;
-              } else {
-                renderAlgorithm();
-              }
-            }, 1);
-        }
-        window.watchW.watch(window.program_obj.functions, function(){
+        window.watchW.watch(window.program_obj.functions[i].variables_list, function(){
           if (window.insertContext) {
             setTimeout(function(){ renderAlgorithm(); }, 300);
             window.insertContext = false;
@@ -171,6 +191,31 @@ function prepareActivityToStudent (ilm_cont) {
             renderAlgorithm();
           }
         }, 1);
+
+        if (window.program_obj.functions[i].is_main) {
+            window.program_obj.functions[i].name = LocalizedStrings.getUI("start");
+        }
+    }
+    window.watchW.watch(window.program_obj.functions, function(){
+      if (window.insertContext) {
+        setTimeout(function(){ renderAlgorithm(); }, 300);
+        window.insertContext = false;
+      } else {
+        renderAlgorithm();
+      }
+    }, 1);
+}
+
+function prepareActivityToStudent (ilm_cont) {
+    var content = JSON.parse(ilm_cont.split('\n::algorithm::')[0]);
+    testCases = content.testcases;
+    settingsDataTypes = content.settings_data_types;
+    settingsCommands = content.settings_commands;
+    settingsFunctions = content.settings_functions;
+
+    if (ilm_cont.split('\n::algorithm::')[1]) {
+        algorithm_in_ilm = ilm_cont.split('\n::algorithm::')[1].split('\n::logs::')[0];
+        includePreviousAlgorithm();
     }
     $('.assessment_button').removeClass('disabled');
     renderAlgorithm();
@@ -207,6 +252,12 @@ $(document).ready(function() {
         // Caso não esteja em modo de resolução de atividade, a visualização no momento
         // é para a elaboração de atividade:
         //$('.elaboracao').css("display","block");
+
+        // Se possuir o parâmetro iLMparameters.iLM_PARAM_Assignment, o professor
+        // está editando uma atividade:
+        if (iLMparameters.iLM_PARAM_Assignment) {
+            getiLMContent();
+        }
     }
 
     if (!testCases) {
@@ -259,13 +310,39 @@ function prepareTableTestCases (div_el) {
     $('.button_add_case').on('click', function(e) {
         addTestCase();
     });
-
 }
 
 var hist = false;
 
-function addTestCase () {
-    var new_row = $('<tr><td class="counter"></td><td class="expandingArea"><textarea rows="1" name="input" class="text_area_input"></textarea></td><td class="expandingArea"><textarea rows="1" name="output" class="text_area_output"></textarea></td><td class="btn_actions"><div class="ui button_remove_case"><i class="red icon times large"></i></div></td></tr>');
+function addTestCase (test_case = null) {
+    var new_row = null;
+    if (test_case) {
+        var text_row = '';
+
+        text_row += '<tr><td class="counter"></td><td class="expandingArea"><textarea rows="'+test_case.input.length+'" name="input" class="text_area_input">';
+
+        for (var i = 0; i < test_case.input.length; i ++) {
+            text_row += test_case.input[i];
+            if ((i + 1) < test_case.input.length) {
+                text_row += '\n';
+            }
+        }
+        
+        text_row += '</textarea></td><td class="expandingArea"><textarea rows="'+test_case.output.length+'" name="output" class="text_area_output">';
+
+        for (var i = 0; i < test_case.output.length; i ++) {
+            text_row += test_case.output[i];
+            if ((i + 1) < test_case.output.length) {
+                text_row += '\n';
+            }
+        }
+
+        text_row += '</textarea></td><td class="btn_actions"><div class="ui button_remove_case"><i class="red icon times large"></i></div></td></tr>';
+
+        new_row = $(text_row);
+    } else {
+        new_row = $('<tr><td class="counter"></td><td class="expandingArea"><textarea rows="1" name="input" class="text_area_input"></textarea></td><td class="expandingArea"><textarea rows="1" name="output" class="text_area_output"></textarea></td><td class="btn_actions"><div class="ui button_remove_case"><i class="red icon times large"></i></div></td></tr>');
+    }
     $('.content_cases').append(new_row);
 
     new_row.find('.button_remove_case').click(function(e) {
@@ -273,7 +350,7 @@ function addTestCase () {
         updateTestCaseCounter();
     });
 
-    $('textarea').on('input', function(e) {
+    new_row.find('textarea').on('input', function(e) {
         var lines = $(this).val().split('\n').length;
         $(this).attr('rows', lines);
     });
@@ -287,10 +364,12 @@ function addTestCase () {
             addTestCase();
         }
      });
-     if (!hist) {
-        $( ".content_cases tr:last" ).find('.text_area_input').focus();
-     } else {
-        hist = false;
+     if (test_case == null) {
+        if (!hist) {
+            $( ".content_cases tr:last" ).find('.text_area_input').focus();
+         } else {
+            hist = false;
+         }
      }
 }
 
@@ -368,7 +447,7 @@ $( document ).ready(function() {
         orderIcons();
         orderWidth();
     }
-
+    renderAlgorithm();
 });
 
 function orderWidth() {
@@ -393,7 +472,7 @@ function inIframe () {
 
 
 function full_screen() {
-     // check if user allows full screen of elements. This can be enabled or disabled in browser config. By default its enabled.
+    // check if user allows full screen of elements. This can be enabled or disabled in browser config. By default its enabled.
     //its also used to check if browser supports full screen api.
     if("fullscreenEnabled" in document || "webkitFullscreenEnabled" in document || "mozFullScreenEnabled" in document || "msFullscreenEnabled" in document) {
         if(document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled) {

+ 0 - 0
ivprogh/js/io/domConsole.js


+ 0 - 0
ivprogh/js/io/domInput.js


+ 0 - 0
ivprogh/js/io/domOutput.js


+ 0 - 0
ivprogh/js/io/input.js


+ 0 - 0
ivprogh/js/io/output.js


+ 0 - 0
ivprogh/js/jquery-3.3.1.min.js


+ 0 - 0
ivprogh/js/jquery-ui.js


+ 0 - 0
ivprogh/js/jquery.json-editor.min.js


+ 0 - 0
ivprogh/js/main.js


+ 33 - 0
ivprogh/js/processor/compatibilityTable.js

@@ -1,6 +1,7 @@
 import { Types } from './../typeSystem/types';
 import { Operators } from './../ast/operators';
 import { MultiType } from '../typeSystem/multiType';
+import { Config } from '../util/config';
 
 function buildInfixAddTable () {
   const table = [[], [], [], []];
@@ -133,6 +134,13 @@ export function resultTypeAfterInfixOp (operator, leftExpressionType, rightExpre
         }
       }
       if(newMulti.length <= 0) {
+        if(Config.enable_type_casting) {
+          if(leftExpressionType.isCompatible(Types.INTEGER) || leftExpressionType.isCompatible(Types.REAL)) {
+            if(rightExpressionType.isCompatible(Types.INTEGER) || rightExpressionType.isCompatible(Types.REAL)) {
+              return new MultiType([Types.INTEGER, Types.REAL]);
+            }
+          }
+        }
         return Types.UNDEFINED;
       } else {
         return new MultiType(newMulti)
@@ -141,17 +149,42 @@ export function resultTypeAfterInfixOp (operator, leftExpressionType, rightExpre
       if(leftExpressionType.isCompatible(rightExpressionType)) {
         return rightExpressionType;
       } else {
+        if(Config.enable_type_casting) {
+          if(leftExpressionType.isCompatible(Types.INTEGER) || leftExpressionType.isCompatible(Types.REAL)) {
+            if(rightExpressionType.isCompatible(Types.INTEGER) || rightExpressionType.isCompatible(Types.REAL)) {
+              return rightExpressionType;
+            }
+          }
+        }
         return Types.UNDEFINED;
       }
     } else if(rightExpressionType instanceof MultiType) {
       if(rightExpressionType.isCompatible(leftExpressionType)) {
         return leftExpressionType;
       } else {
+        if(Config.enable_type_casting) {
+          if(leftExpressionType.isCompatible(Types.INTEGER) || leftExpressionType.isCompatible(Types.REAL)) {
+            if(rightExpressionType.isCompatible(Types.INTEGER) || rightExpressionType.isCompatible(Types.REAL)) {
+              return leftExpressionType;
+            }
+          }
+        }
         return Types.UNDEFINED;
       }
     }
     const resultType = infixMap.get(operator)[leftExpressionType.ord][rightExpressionType.ord];
     if (resultType === null || resultType === undefined) {
+      if(Config.enable_type_casting) {
+        if(leftExpressionType.isCompatible(Types.INTEGER) || leftExpressionType.isCompatible(Types.REAL)) {
+          if(rightExpressionType.isCompatible(Types.INTEGER) || rightExpressionType.isCompatible(Types.REAL)) {
+            if(operator === Operators.MOD) {
+              return Types.INTEGER;
+            } else if (operator.ord >= 5 && operator.ord <= 10){
+              return Types.BOOLEAN;
+            }
+          }
+        }
+      }
       return Types.UNDEFINED
     }
     return resultType;

+ 0 - 0
ivprogh/js/processor/context.js


+ 0 - 0
ivprogh/js/processor/definedFunctions.js


+ 0 - 0
ivprogh/js/processor/error/processorErrorFactory.js


+ 0 - 0
ivprogh/js/processor/error/runtimeError.js


+ 0 - 0
ivprogh/js/processor/error/semanticError.js


+ 125 - 42
ivprogh/js/processor/ivprogProcessor.js

@@ -86,21 +86,20 @@ export class IVProgProcessor {
 
   interpretAST () {
     this.prepareState();
-    this.initGlobal();
-    const mainFunc = this.findMainFunction();
-    if(mainFunc === null) {
-      throw ProcessorErrorFactory.main_missing();
-    }
-    return this.runFunction(mainFunc, [], this.globalStore);
+    return this.initGlobal().then( _ => {
+      const mainFunc = this.findMainFunction();
+      if(mainFunc === null) {
+        throw ProcessorErrorFactory.main_missing();
+      }
+      return this.runFunction(mainFunc, [], this.globalStore);
+    });
   }
 
   initGlobal () {
     if(!this.checkContext(Context.BASE)) {
       throw ProcessorErrorFactory.invalid_global_var();
     }
-    this.ast.global.forEach(decl => {
-      this.executeCommand(this.globalStore, decl).then(sto => this.globalStore = sto);
-    });
+    return this.executeCommands(this.globalStore, this.ast.global);
   }
 
   findMainFunction () {
@@ -163,27 +162,36 @@ export class IVProgProcessor {
     return Promise.all(promises$).then(values => {
       for (let i = 0; i < values.length; i++) {
         const stoObj = values[i];
-        const exp = actualList[i]
+        const exp = actualList[i];
+        let shouldTypeCast = false;
         const formalParameter = formalList[i];
-        if(formalParameter.type.isCompatible(stoObj.type)) {
-          if(formalParameter.byRef && !stoObj.inStore) {
-            throw ProcessorErrorFactory.invalid_ref(funcName, exp.toString());
+        if(!formalParameter.type.isCompatible(stoObj.type)) {
+          if (Config.enable_type_casting && !formalParameter.byRef
+            && Store.canImplicitTypeCast(formalParameter.type, stoObj.type)) {
+              shouldTypeCast =  true;
+          } else {
+            throw ProcessorErrorFactory.invalid_parameter_type(funcName, exp.toString());
           }
+        }
 
-          if(formalParameter.byRef) {
-            let ref = null;
-            if (stoObj instanceof StoreObjectArrayAddress) {
-              ref = new StoreObjectArrayAddressRef(stoObj);
-            } else {
-              ref = new StoreObjectRef(stoObj.id, callerStore);
-            }
-            calleeStore.insertStore(formalParameter.id, ref);
+        if(formalParameter.byRef && !stoObj.inStore) {
+          throw ProcessorErrorFactory.invalid_ref(funcName, exp.toString());
+        }
+
+        if(formalParameter.byRef) {
+          let ref = null;
+          if (stoObj instanceof StoreObjectArrayAddress) {
+            ref = new StoreObjectArrayAddressRef(stoObj);
           } else {
-            let realValue = this.parseStoreObjectValue(stoObj);
-            calleeStore.insertStore(formalParameter.id, realValue);
+            ref = new StoreObjectRef(stoObj.id, callerStore);
           }
+          calleeStore.insertStore(formalParameter.id, ref);
         } else {
-          throw ProcessorErrorFactory.invalid_parameter_type(funcName, exp.toString());
+          let realValue = this.parseStoreObjectValue(stoObj);
+          if (shouldTypeCast) {
+            realValue = Store.doImplicitCasting(formalParameter.type, realValue);
+          }
+          calleeStore.insertStore(formalParameter.id, realValue);
         }
       }
       return calleeStore;
@@ -324,6 +332,7 @@ export class IVProgProcessor {
       const whileBlock = new Commands.CommandBlock([],
         cmd.commands.concat(increment));
       const forAsWhile = new Commands.While(condition, whileBlock);
+      forAsWhile.sourceInfo = cmd.sourceInfo;
       //END for -> while rewrite
       const newCmdList = [initCmd,forAsWhile];
       return this.executeCommands(store, newCmdList);
@@ -477,9 +486,20 @@ export class IVProgProcessor {
 
   executeAssign (store, cmd) {
     try {
+      const inStore = store.applyStore(cmd.id);
       const $value = this.evaluateExpression(store, cmd.expression);
       return $value.then( vl => {
         let realValue = this.parseStoreObjectValue(vl);
+        if(!inStore.type.isCompatible(realValue.type)) {
+          if(Config.enable_type_casting && Store.canImplicitTypeCast(inStore.type, vl.type)) {
+            realValue = Store.doImplicitCasting(inStore.type, realValue);
+          } else {
+            const stringInfo = inStore.type.stringInfo()
+            const info = stringInfo[0]
+            return Promise.reject(ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, cmd.sourceInfo));
+          }
+        }
+        
         store.updateStore(cmd.id, realValue) 
         return store;
       });
@@ -533,7 +553,7 @@ export class IVProgProcessor {
 
       const newArray = Object.assign(new StoreObjectArray(null,null,null), mustBeArray);
       if (column !== null) {
-        if (value.type instanceof CompoundType) {
+        if (value.type instanceof CompoundType || !newArray.type.canAccept(value.type)) {
           const type = mustBeArray.type.innerType;
           const stringInfo = type.stringInfo()
           const info = stringInfo[0]
@@ -542,7 +562,7 @@ export class IVProgProcessor {
         newArray.value[line].value[column] = value;
         store.updateStore(cmd.id, newArray);
       } else {
-        if(mustBeArray.columns !== null && value.type instanceof CompoundType) {
+        if((mustBeArray.columns !== null && value.type instanceof CompoundType) || !newArray.type.canAccept(value.type)) {
           const type = mustBeArray.type;
           const stringInfo = type.stringInfo()
           const info = stringInfo[0]
@@ -613,15 +633,24 @@ export class IVProgProcessor {
         return $value.then(vl => {
           let realValue = vl;
           if (vl !== null) {
+            if(!vl.type.isCompatible(cmd.type)) {
+              if(Config.enable_type_casting && Store.canImplicitTypeCast(cmd.type, vl.type)) {
+                realValue = Store.doImplicitCasting(cmd.type, realValue);
+              } else {
+                const stringInfo = typeInfo.type.stringInfo();
+                const info = stringInfo[0];
+                return Promise.reject(ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, cmd.sourceInfo));
+              }
+            }
             if(vl instanceof StoreObjectArrayAddress) {
               if(vl.type instanceof CompoundType) {
-                realValue = Object.assign(new StoreObjectArray(null,null,null), vl.refValue);
+                return Promise.reject(new Error("!!!Critical Error: Compatibility check failed, a Type accepts a CompoundType"))
               } else {
                 realValue = Object.assign(new StoreObject(null,null), vl.refValue);
               }
             }
           } else {
-            realValue = new StoreObject(cmd.type,0);
+            realValue = new StoreObject(cmd.type, 0);
           }
           realValue.readOnly = cmd.isConst;
           store.updateStore(cmd.id, realValue);
@@ -837,16 +866,21 @@ export class IVProgProcessor {
     const $left = this.evaluateExpression(store, infixApp.left);
     const $right = this.evaluateExpression(store, infixApp.right);
     return Promise.all([$left, $right]).then(values => {
+      let shouldImplicitCast = false;
       const left = values[0];
       const right = values[1];
-      const resultType = resultTypeAfterInfixOp(infixApp.op, left.type, right.type);
+      let resultType = resultTypeAfterInfixOp(infixApp.op, left.type, right.type);
       if (Types.UNDEFINED.isCompatible(resultType)) {
-        const stringInfoLeft = left.type.stringInfo();
-        const infoLeft = stringInfoLeft[0];
-        const stringInfoRight = right.type.stringInfo();
-        const infoRight = stringInfoRight[0];
-        return Promise.reject(ProcessorErrorFactory.invalid_infix_op_full(infixApp.op, infoLeft.type, infoLeft.dim,
-          infoRight.type,infoRight.dim,infixApp.sourceInfo));
+        if (Config.enable_type_casting && Store.canImplicitTypeCast(left.type, right.type)) {
+          shouldImplicitCast = true;
+        } else {
+          const stringInfoLeft = left.type.stringInfo();
+          const infoLeft = stringInfoLeft[0];
+          const stringInfoRight = right.type.stringInfo();
+          const infoRight = stringInfoRight[0];
+          return Promise.reject(ProcessorErrorFactory.invalid_infix_op_full(infixApp.op, infoLeft.type, infoLeft.dim,
+            infoRight.type,infoRight.dim,infixApp.sourceInfo));
+        }
       }
       let result = null;
       switch (infixApp.op.ord) {
@@ -881,55 +915,104 @@ export class IVProgProcessor {
           return new StoreObject(resultType, result);
         }
         case Operators.MOD.ord: {
-          result = left.value.modulo(right.value);
+          let leftValue = left.value;
+          let rightValue = right.value;
+          if(shouldImplicitCast) {
+            resultType = Types.INTEGER;
+            leftValue = leftValue.trunc();
+            rightValue = rightValue.trunc();
+          }
+          result = leftValue.modulo(rightValue);
           if(result.dp() > Config.decimalPlaces) {
             result = new Decimal(result.toFixed(Config.decimalPlaces));
           }
           return new StoreObject(resultType, result);
         }          
         case Operators.GT.ord: {
+          let leftValue = left.value;
+          let rightValue = right.value;
           if (Types.STRING.isCompatible(left.type)) {
             result = left.value.length > right.value.length;
           } else {
-            result = left.value.gt(right.value);
+            if (shouldImplicitCast) {
+              resultType = Types.BOOLEAN;
+              leftValue = leftValue.trunc();
+              rightValue = rightValue.trunc();
+            }
+            result = leftValue.gt(rightValue);
           }
           return new StoreObject(resultType, result);
         }
         case Operators.GE.ord: {
+          let leftValue = left.value;
+          let rightValue = right.value;
           if (Types.STRING.isCompatible(left.type)) {
             result = left.value.length >= right.value.length;
           } else {
-            result = left.value.gte(right.value);
+            if (shouldImplicitCast) {
+              resultType = Types.BOOLEAN;
+              leftValue = leftValue.trunc();
+              rightValue = rightValue.trunc();
+            }
+            result = leftValue.gte(rightValue);
           }
           return new StoreObject(resultType, result);
         }
         case Operators.LT.ord: {
+          let leftValue = left.value;
+          let rightValue = right.value;
           if (Types.STRING.isCompatible(left.type)) {
             result = left.value.length < right.value.length;
           } else {
-            result = left.value.lt(right.value);
+            if (shouldImplicitCast) {
+              resultType = Types.BOOLEAN;
+              leftValue = leftValue.trunc();
+              rightValue = rightValue.trunc();
+            }
+            result = leftValue.lt(rightValue);
           }
           return new StoreObject(resultType, result);
         }
         case Operators.LE.ord: {
+          let leftValue = left.value;
+          let rightValue = right.value;
           if (Types.STRING.isCompatible(left.type)) {
             result = left.value.length <= right.value.length;
           } else {
-            result = left.value.lte(right.value);
+            if (shouldImplicitCast) {
+              resultType = Types.BOOLEAN;
+              leftValue = leftValue.trunc();
+              rightValue = rightValue.trunc();
+            }
+            result = leftValue.lte(rightValue);
           }
           return new StoreObject(resultType, result);
         }
         case Operators.EQ.ord: {
+          let leftValue = left.value;
+          let rightValue = right.value;
           if (Types.INTEGER.isCompatible(left.type) || Types.REAL.isCompatible(left.type)) {
-            result = left.value.eq(right.value);
+            if (shouldImplicitCast) {
+              resultType = Types.BOOLEAN;
+              leftValue = leftValue.trunc();
+              rightValue = rightValue.trunc();
+            }
+            result = leftValue.eq(rightValue);
           } else {
             result = left.value === right.value;
           }
           return new StoreObject(resultType, result);
         }
         case Operators.NEQ.ord: {
+          let leftValue = left.value;
+          let rightValue = right.value;
           if (Types.INTEGER.isCompatible(left.type) || Types.REAL.isCompatible(left.type)) {
-            result = !left.value.eq(right.value);
+            if (shouldImplicitCast) {
+              resultType = Types.BOOLEAN;
+              leftValue = leftValue.trunc();
+              rightValue = rightValue.trunc();
+            }
+            result = !leftValue.eq(rightValue);
           } else {
             result = left.value !== right.value;
           }

+ 0 - 0
ivprogh/js/processor/lib/arrays.js


+ 2 - 12
ivprogh/js/processor/lib/io.js

@@ -1,22 +1,12 @@
 import { StoreObject } from './../store/storeObject';
 import * as Commands from './../../ast/commands';
-import {toInt, toString, toBool, toReal} from './../../typeSystem/parsers';
+import {toInt, toString, toBool, toReal, convertToString} from './../../typeSystem/parsers';
 import { Types } from './../../typeSystem/types';
 
 export function createOutputFun () {
   const writeFunction = function (store, _) {
     const val = store.applyStore('p1');
-    if(val.type.isCompatible(Types.INTEGER)) {
-      this.output.sendOutput(val.value.toString());
-    } else if (val.type.isCompatible(Types.REAL)) {
-      if (val.value.dp() <= 0) {
-        this.output.sendOutput(val.value.toFixed(1));  
-      } else {
-        this.output.sendOutput(val.value.toString());
-      }
-    } else {
-      this.output.sendOutput(val.value);
-    }
+    this.output.sendOutput(convertToString(val.value, val.type));
     return Promise.resolve(store);
   }
   const block = new Commands.CommandBlock([], [new Commands.SysCall(writeFunction)]);

+ 0 - 0
ivprogh/js/processor/lib/lang.js


+ 0 - 0
ivprogh/js/processor/lib/math.js


+ 0 - 0
ivprogh/js/processor/lib/strings.js


+ 0 - 0
ivprogh/js/processor/modes.js


+ 55 - 29
ivprogh/js/processor/semantic/semanticAnalyser.js

@@ -8,6 +8,8 @@ import { resultTypeAfterInfixOp, resultTypeAfterUnaryOp } from '../compatibility
 import { Types } from '../../typeSystem/types';
 import { CompoundType } from '../../typeSystem/compoundType';
 import { MultiType } from '../../typeSystem/multiType';
+import { Config } from '../../util/config';
+import { Store } from '../store/store';
 
 export class SemanticAnalyser {
 
@@ -55,6 +57,7 @@ export class SemanticAnalyser {
   }
 
   findFunction (name) {
+    console.log(name);
     if(name.match(/^\$.+$/)) {
       const fun = LanguageDefinedFunction.getFunction(name);
       if(!!!fun) {
@@ -124,12 +127,14 @@ export class SemanticAnalyser {
           throw ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, declaration.sourceInfo);
         }
         this.insertSymbol(declaration.id, {id: declaration.id, type: declaration.type})
-      } else if(!declaration.type.isCompatible(resultType)) {
+      } else if((!declaration.type.isCompatible(resultType) && !Config.enable_type_casting)
+        || (!declaration.type.isCompatible(resultType) && Config.enable_type_casting
+        && !Store.canImplicitTypeCast(declaration.type, resultType))) {
         const stringInfo = declaration.type.stringInfo();
         const info = stringInfo[0];
         throw ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, declaration.sourceInfo);
       } else {
-        this.insertSymbol(declaration.id, {id: declaration.id, type: declaration.type})
+        this.insertSymbol(declaration.id, {id: declaration.id, type: declaration.type});
       }
     }
   }
@@ -237,29 +242,28 @@ export class SemanticAnalyser {
   }
 
   evaluateArrayLiteral (id, lines, columns, type, literal) {
-    if (literal instanceof ArrayLiteral) {
-      if (columns === null) {
-        // it's a vector...
-        const dimType = this.evaluateExpressionType(lines);
-        if (!dimType.isCompatible(Types.INTEGER)) {
-          throw ProcessorErrorFactory.array_dimension_not_int_full(literal.sourceInfo);
-        }
-        if ((lines instanceof IntLiteral)) {
-          if (!lines.value.eq(literal.value.length)) {
-            if(type.dimensions > 1) {
-              throw ProcessorErrorFactory.matrix_line_outbounds_full(id, literal.value.length, lines.values.toNumber(), literal.sourceInfo)
-            } else {
-              throw ProcessorErrorFactory.vector_line_outbounds_full(id, literal.value.length, lines.values.toNumber(), literal.sourceInfo)
-            }
-          } else if (lines.value.isNeg()) {
-            throw ProcessorErrorFactory.array_dimension_not_positive_full(literal.sourceInfo);
+    /* if (literal instanceof ArrayLiteral) {
+      const dimType = this.evaluateExpressionType(lines);
+      if (!dimType.isCompatible(Types.INTEGER)) {
+        throw ProcessorErrorFactory.array_dimension_not_int_full(literal.sourceInfo);
+      }
+      if ((lines instanceof IntLiteral)) {
+        if (!lines.value.eq(literal.value.length)) {
+          if(type.dimensions > 1) {
+            throw ProcessorErrorFactory.matrix_line_outbounds_full(id, literal.value.length, lines.value.toNumber(), literal.sourceInfo)
+          } else {
+            throw ProcessorErrorFactory.vector_line_outbounds_full(id, literal.value.length, lines.value.toNumber(), literal.sourceInfo)
           }
-          
+        } else if (lines.value.isNeg()) {
+          throw ProcessorErrorFactory.array_dimension_not_positive_full(literal.sourceInfo);
         }
+      }
+      if (columns === null) {
+        // it's a vector...
         literal.value.reduce((last, next) => {
           const eType = this.evaluateExpressionType(next);
           if (!last.canAccept(eType)) {
-            const strInfo = last.stringInfo();invalid
+            const strInfo = last.stringInfo();
             const info = strInfo[0];
             const strExp = literal.toString();
             throw ProcessorErrorFactory.incompatible_types_array_full(strExp,info.type, info.dim, literal.sourceInfo);
@@ -273,20 +277,20 @@ export class SemanticAnalyser {
           throw ProcessorErrorFactory.array_dimension_not_int_full(literal.sourceInfo);
         }
         if ((columns instanceof IntLiteral)) {
-          if (!columns.value.eq(literal.value.length)) {
+          const columnValue = literal.value[0].value.length;
+          if (!columns.value.eq(columnValue)) {
             if(type.dimensions > 1) {
-              throw ProcessorErrorFactory.matrix_column_outbounds_full(id, literal.value.length, columns.values.toNumber(), literal.sourceInfo)
+              throw ProcessorErrorFactory.matrix_column_outbounds_full(id, literal.value.length, columns.value.toNumber(), literal.sourceInfo)
             } else {
               throw ProcessorErrorFactory.invalid_matrix_access_full(id, literal.sourceInfo);
             }
           } else if (columns.value.isNeg()) {
             throw ProcessorErrorFactory.array_dimension_not_positive_full(literal.sourceInfo);
           }
-          
-        }
-        for (let i = 0; i < columns; i++) {
-          const anotherArray = literal.value[i];
-          this.evaluateArrayLiteral(id, lines, null, type, anotherArray)
+          for (let i = 0; i < columns; i++) {
+            const anotherArray = literal.value[i];
+            this.evaluateArrayLiteral(id, columns, null, type, anotherArray)
+          }
         }
       }
 
@@ -306,7 +310,8 @@ export class SemanticAnalyser {
         throw ProcessorErrorFactory.incompatible_types_array_full(strExp,info.type, info.dim, literal.sourceInfo);
       }
       return true;
-    }
+    } */
+    return true;
   }
 
   assertFunction (fun) {
@@ -421,7 +426,9 @@ export class SemanticAnalyser {
         this.evaluateArrayLiteral(cmd.id, typeInfo.lines, typeInfo.columns, typeInfo.type, exp);
       } else {
         const resultType = this.evaluateExpressionType(exp);
-        if(!resultType.isCompatible(typeInfo.type)) {
+        if((!resultType.isCompatible(typeInfo.type) && !Config.enable_type_casting)
+          || (!resultType.isCompatible(typeInfo.type) && Config.enable_type_casting
+          && !Store.canImplicitTypeCast(typeInfo.type, resultType))) {
           const stringInfo = typeInfo.type.stringInfo();
           const info = stringInfo[0];
           throw ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, cmd.sourceInfo);
@@ -503,13 +510,32 @@ export class SemanticAnalyser {
           }
         }
         if(shared <= 0) {
+          if(Config.enable_type_casting && !formalParam.byRef) {
+            if(resultType.isCompatible(Types.INTEGER) || resultType.isCompatible(Types.REAL)) {
+              if(formalParam.type.isCompatible(Types.INTEGER) || formalParam.type.isCompatible(Types.REAL)) {
+                continue;
+              }
+            }
+          }
           throw ProcessorErrorFactory.invalid_parameter_type_full(id, param.toString(), param.sourceInfo);
         }
       } else if (resultType instanceof MultiType) {
         if(!resultType.isCompatible(formalParam.type)) {
+          if(Config.enable_type_casting && !formalParam.byRef) {
+            if(resultType.isCompatible(Types.INTEGER) || resultType.isCompatible(Types.REAL)) {
+              if(formalParam.type.isCompatible(Types.INTEGER) || formalParam.type.isCompatible(Types.REAL)) {
+                continue;
+              }
+            }
+          }
           throw ProcessorErrorFactory.invalid_parameter_type_full(id, param.toString(), param.sourceInfo);
         }
       } else if(!formalParam.type.isCompatible(resultType)) {
+        if(Config.enable_type_casting && !formalParam.byRef) {
+          if (Store.canImplicitTypeCast(formalParam.type, resultType)) {
+            continue;
+          }
+        }
         throw ProcessorErrorFactory.invalid_parameter_type_full(id, param.toString(), param.sourceInfo);
       }
 

+ 22 - 1
ivprogh/js/processor/store/store.js

@@ -1,7 +1,29 @@
 import { Modes } from './../modes';
+import { Types } from "./../../typeSystem/types";
+import { StoreObject } from './storeObject';
 
 export class Store {
 
+  static canImplicitTypeCast (castType, sourceType) {
+    if (castType.isCompatible(Types.INTEGER) || castType.isCompatible(Types.REAL)) {
+      if (sourceType.isCompatible(Types.INTEGER) || sourceType.isCompatible(Types.REAL)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  static doImplicitCasting (castType, stoObj) {
+    if(!Store.canImplicitTypeCast(castType, stoObj.type)) {
+      throw new Error("!!!Critical error: attempted to type cast invalid types");
+    }
+    if(Types.INTEGER.isCompatible(castType)) {
+      return new StoreObject(castType, stoObj.value.trunc());
+    } else {
+      return new StoreObject(castType, stoObj.value);
+    }
+  }
+
   constructor(name) {
     this.name = name;
     this.store = {};
@@ -18,7 +40,6 @@ export class Store {
       if (this.nextStore !== null) {
         return this.nextStore.applyStore(id);
       } else {
-        // TODO: better error message
         throw new Error(`Variable ${id} not found.`);
       }
     }

+ 0 - 0
ivprogh/js/processor/store/storeObject.js


+ 0 - 0
ivprogh/js/processor/store/storeObjectArray.js


+ 0 - 0
ivprogh/js/processor/store/storeObjectArrayAddress.js


+ 0 - 0
ivprogh/js/processor/store/storeObjectArrayAddressRef.js


+ 0 - 0
ivprogh/js/processor/store/storeObjectRef.js


+ 0 - 0
ivprogh/js/runner.js


+ 0 - 0
ivprogh/js/semantic/.versions


+ 0 - 0
ivprogh/js/semantic/LICENSE


+ 0 - 0
ivprogh/js/semantic/README.md


+ 0 - 0
ivprogh/js/semantic/components/accordion.css


+ 0 - 0
ivprogh/js/semantic/components/accordion.js


+ 0 - 0
ivprogh/js/semantic/components/accordion.min.css


+ 0 - 0
ivprogh/js/semantic/components/accordion.min.js


+ 0 - 0
ivprogh/js/semantic/components/ad.css


+ 0 - 0
ivprogh/js/semantic/components/ad.min.css


Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.