|
@@ -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
|
|
|
+ );
|
|
|
+}
|