2
0

2 Commits 74632352b4 ... 31aef4f032

Autor SHA1 Mensagem Data
  Igor 31aef4f032 textual to visual: finished há 2 anos atrás
  Igor 86ae07bd74 work in progress.... há 2 anos atrás

+ 67 - 14
js/util/codeParser.js

@@ -158,9 +158,17 @@ function parseCommands (commands_block, function_obj) {
       case Models.COMMAND_TYPES.iftrue:
         return parseIfTrue(commands_block, function_obj);
 
-      //case Models.COMMAND_TYPES.repeatNtimes:
-      default:
+      case Models.COMMAND_TYPES.repeatNtimes:
         return parseRepeatNTimes(commands_block, function_obj);
+
+      case Models.COMMAND_TYPES.whiletrue:
+        return parseWhileTrue(commands_block, function_obj);
+
+      case Models.COMMAND_TYPES.dowhiletrue:
+        return parseDoWhileTrue(commands_block, function_obj);
+
+      case Models.COMMAND_TYPES.switch:
+        return parseSwitch(commands_block, function_obj);
     }
     return null;
   }
@@ -216,7 +224,7 @@ function parseAttribution (command, function_obj) {
   );
 }
 
-function parseComment(command, function_obj) {
+function parseComment (command, function_obj) {
   // TODO
   return new Models.Comment(
     null
@@ -267,27 +275,72 @@ function parseRepeatNTimes(command, function_obj) {
   var expression2 = CodeParser.expressionParserCodeVisual(command.condition, function_obj);
   expression2 = expression2[0];
 
-  var expression3 = CodeParser.expressionParserCodeVisual(command.step_expression, function_obj);
-
-  console.log('expression3', expression3);
+  var var_step = CodeParser.expressionParserCodeVisual(command.step_expression, function_obj);
 
   var commands_block = parseCommands(command.commands, function_obj);
 
-  // var_attribution,
-  //   var_incrementation,
-  //   expression1,
-  //   expression2,
-  //   expression3,
-  //   commands_block
+  var operator = command.step_expression[0].value == '+' 
+                  ? Models.ARITHMETIC_TYPES.plus
+                  : Models.ARITHMETIC_TYPES.minus;
+
+  var expression3 = new Models.ExpressionElement(
+    Models.EXPRESSION_ELEMENTS.exp_op_exp, 
+    [ 
+      null,
+      operator, 
+      var_step[1]
+    ]);
 
   return new Models.RepeatNTimes(
     var_attribution,
     new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_variable, null, null, null, false),
     expression1,
     expression2,
-    null, 
+    expression3, 
     commands_block);
 
 }
 
-			
+function parseWhileTrue (command, function_obj) {
+
+  var expression = CodeParser.expressionParserCodeVisual(command.expression, function_obj);
+  var commands = parseCommands(command.commands, function_obj);
+
+  return new Models.WhileTrue(
+    expression, 
+    commands
+  );
+}
+
+function parseDoWhileTrue (command, function_obj) {
+  
+  var expression = CodeParser.expressionParserCodeVisual(command.expression, function_obj);
+  var commands = parseCommands(command.commands, function_obj);
+
+  return new Models.DoWhileTrue(
+    expression, 
+    commands
+  );
+}
+
+function parseSwitch (command, function_obj) {
+
+  var expression = CodeParser.expressionParserCodeVisual(command.expression, function_obj);
+
+  var sc = [];
+  if (command.cases) {
+    command.cases.forEach(function(case_el) {
+
+      var temp_exp = CodeParser.expressionParserCodeVisual(case_el.expression, function_obj);
+      var temp_commands = parseCommands(case_el.commands, function_obj);
+      var temp_case = new Models.SwitchCase(temp_exp[0], temp_commands);
+
+      sc.push(temp_case);
+    })
+  }
+
+	return new Models.Switch(
+    expression[0], 
+    sc
+  );
+}

+ 0 - 2
js/util/iassignHelpers.js

@@ -49,8 +49,6 @@ function setActivityConfig (config_json) {
 }
 
 function setPreviousAlgorithm (code) {
-  console.log('conteúdo: ')
-  console.log(code)
   
   var code_obj = null;
   try {

+ 0 - 5
js/visualUI/commands/generic_expression.js

@@ -1654,11 +1654,6 @@ export function searchFunction (function_name) {
 
 export function expressionParserCodeVisual (parsed, function_obj) {
 
-  console.log('\nparsed')
-  console.log(parsed)
-  console.log('\n\n')
-  
-
   if (!parsed) return null;
 
   var var_not_found = [];

+ 39 - 0
js/visualUI/functions.js

@@ -138,6 +138,25 @@ WatchJS.watch(window.program_obj.functions, function(){
 
 function addFunctionHandler () {
 
+  if (window.program_obj.functions) {
+		var in_use = false;
+		do {
+			in_use = false;
+			
+			var temp_name = LocalizedStrings.getUI('new_function') + '_' + counter_new_functions;
+
+			window.program_obj.functions.forEach(function(el) {
+				if (temp_name == el.name) {
+					in_use = true;
+				}
+			})
+
+			if (in_use)
+        counter_new_functions++;
+
+		} while (in_use);
+	}
+
 	const new_function = new Models.Function(LocalizedStrings.getUI("new_function") + "_" + counter_new_functions, Types.VOID, 0, [], false, false, [], new Models.Comment(LocalizedStrings.getUI('text_comment_start')));
 	program.addFunction(new_function);
 
@@ -156,6 +175,26 @@ function addParameter (function_obj, function_container/*, is_from_click = false
   if (function_obj.parameters_list == null) {
     function_obj.parameters_list = [];
   }
+
+  if (function_obj.parameters_list) {
+		var in_use = false;
+		do {
+			in_use = false;
+			
+			var temp_name = LocalizedStrings.getUI('new_parameter') + '_' + counter_new_parameters;
+
+			function_obj.parameters_list.forEach(function(el) {
+				if (temp_name == el.name) {
+					in_use = true;
+				}
+			})
+
+			if (in_use)
+        counter_new_parameters++;
+
+		} while (in_use);
+	}
+
   const new_parameter = new Models.Variable(Types.INTEGER, LocalizedStrings.getUI("new_parameter") + "_" + counter_new_parameters);
   function_obj.parameters_list.push(new_parameter);
   counter_new_parameters ++;

+ 20 - 0
js/visualUI/globals.js

@@ -8,6 +8,26 @@ var counter_new_globals = 0;
 
 export function addGlobal (program, is_from_click = false) {
 
+	// Verify if the next global name is in use:
+	if (program.globals) {
+		var in_use = false;
+		do {
+			in_use = false;
+			
+			var temp_name = LocalizedStrings.getUI('new_global') + '_' + counter_new_globals;
+
+			program.globals.forEach(function(el) {
+				if (temp_name == el.name) {
+					in_use = true;
+				}
+			})
+
+			if (in_use)
+				counter_new_globals++;
+
+		} while (in_use);
+	}
+
 	var new_global = new Models.Variable(Types.INTEGER, LocalizedStrings.getUI('new_global') + '_' + counter_new_globals, 0);
 	counter_new_globals ++;
 

+ 21 - 0
js/visualUI/variables.js

@@ -8,6 +8,27 @@ import { isValidIdentifier } from "./../util/utils";
 var counter_new_variables = 0;	
 
 export function addVariable (function_obj, function_container, is_in_click = false) {
+
+	// Verify if the next variable name is in use:
+	if (function_obj.variables_list) {
+		var in_use = false;
+		do {
+			in_use = false;
+			
+			var temp_name = LocalizedStrings.getUI('new_variable') + '_' + counter_new_variables;
+
+			function_obj.variables_list.forEach(function(el) {
+				if (temp_name == el.name) {
+					in_use = true;
+				}
+			})
+
+			if (in_use)
+				counter_new_variables++;
+
+		} while (in_use);
+	}
+
 	var new_var = new Models.Variable(Types.INTEGER, LocalizedStrings.getUI('new_variable') + '_' + counter_new_variables, 0);
 	if (function_obj.variables_list == null) {
 		function_obj.variables_list = [];