|
@@ -1,6 +1,8 @@
|
|
|
// iVProg - www.usp.br/line/ivprog
|
|
|
// LInE - Free Education, Private Data
|
|
|
|
|
|
+// This is used when is loaded "ivph" file under the button "upload"
|
|
|
+
|
|
|
import * as Models from '../visualUI/ivprog_elements';
|
|
|
import { LocalizedStrings } from "./../services/localizedStringsService";
|
|
|
import * as VariableValueMenuManagement from '../visualUI/commands/variable_value_menu';
|
|
@@ -89,9 +91,26 @@ function parseFunction (function_obj) {
|
|
|
window.program_obj.addFunction(new_function);
|
|
|
}
|
|
|
|
|
|
+// Auxiliary to debug
|
|
|
+function printCommandText (code) {
|
|
|
+ if (code) {
|
|
|
+ //if (code.commands) return "commands.length=" + code.commands.length; else return "Object.commands <empty>";
|
|
|
+ var aux = "";
|
|
|
+ if (code.globals) aux = "#globals=" + code.globals.length;
|
|
|
+ else aux = "#globals=0";
|
|
|
+ if (code.functions) aux += ", #functions=" + code.functions.length;
|
|
|
+ else aux += ", #functions=0";
|
|
|
+ return aux;
|
|
|
+ }
|
|
|
+ return "Object <empty>";
|
|
|
+ }
|
|
|
|
|
|
+// @calledby Recursive, "parserCodeVisual(.)": preparedFunction.commands = parseCommands(rawFunction.commands, preparedFunction);
|
|
|
+// @calledby Generic parser, "parseCommands(.)": temp.push(parseCommands(command, function_obj));
|
|
|
+// @calledby Each parser command as "function parseIfTrue(command,function_obj)": "ifTrueBlock=parseCommands(command.ifTrue,function_obj)" and "ifFalseBlock=parseCommands(command.ifFalse,function_obj)"
|
|
|
export function parserCodeVisual (code_obj = null) {
|
|
|
- console.log(".ivprog/js/util/codeParser.js: parserCodeVisual(.)");
|
|
|
+ console.log("codeParser.js!parserCodeVisual(.): code_obj has " + printCommandText(code_obj)); // JSON.stringify(code_obj));
|
|
|
+ console.trace();
|
|
|
window.conteudo = code_obj
|
|
|
|
|
|
// Globals:
|
|
@@ -114,7 +133,8 @@ export function parserCodeVisual (code_obj = null) {
|
|
|
|
|
|
|
|
|
function parseCommands (commands_block, function_obj) {
|
|
|
- console.log(".ivprog/js/util/codeParser.js: parseCommands(.): commands_block=" + JSON.stringify(commands_block));
|
|
|
+ console.log("codeParser.js!parseCommands(.): commands_block=" + printCommandText(commands_block)); // JSON.stringify(commands_block));
|
|
|
+ // console.trace();
|
|
|
if (Array.isArray(commands_block)) {
|
|
|
var temp = [];
|
|
|
commands_block.forEach(function(command) {
|
|
@@ -207,9 +227,11 @@ function parseAttribution (command, function_obj) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-//TODO
|
|
|
+// By Gleyce 2025/06/23
|
|
|
function parseComment (command, function_obj) {
|
|
|
- return new Models.Comment(null);
|
|
|
+ // return new Models.Comment(null);
|
|
|
+ var comment_text = new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_value, command.comment_text, null, null, false);
|
|
|
+ return new Models.Comment(comment_text);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -233,7 +255,7 @@ function parseFunctionCall (command, function_obj) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-function parseIfTrue(command, function_obj) {
|
|
|
+function parseIfTrue (command, function_obj) {
|
|
|
var expression = CodeParser.expressionParserCodeVisual(command.expression, function_obj);
|
|
|
var ifTrueBlock = parseCommands(command.ifTrue, function_obj);
|
|
|
var ifFalseBlock = parseCommands(command.ifFalse, function_obj);
|
|
@@ -242,7 +264,8 @@ function parseIfTrue(command, function_obj) {
|
|
|
|
|
|
|
|
|
function parseRepeatNTimes (command, function_obj) {
|
|
|
- console.log(".ivprog/js/util/codeParser.js: parseRepeatNTimes(.): command=" + JSON.stringify(command));
|
|
|
+ //D console.log("codeParser.js!parseRepeatNTimes(.): command=" + JSON.stringify(command));
|
|
|
+ console.log("codeParser.js!parseRepeatNTimes(.): command=" + command);
|
|
|
var var_attribution = CodeParser.expressionParserCodeVisual(command.var_attribution, function_obj);
|
|
|
var_attribution = var_attribution[0];
|
|
|
|
|
@@ -264,6 +287,7 @@ function parseRepeatNTimes (command, function_obj) {
|
|
|
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] ]);
|
|
|
+ console.log("codeParser.js!parseRepeatNTimes(.): expression3=" + expression3);
|
|
|
|
|
|
return new Models.RepeatNTimes(
|
|
|
var_attribution,
|