|
@@ -99,19 +99,16 @@ function breakWalker (_) {
|
|
/**
|
|
/**
|
|
* @param {Commands.For} forLoop
|
|
* @param {Commands.For} forLoop
|
|
* */
|
|
* */
|
|
-// function forWalker (forLoop) {
|
|
|
|
-//
|
|
|
|
-// const var_attribution = forLoop.for_id;
|
|
|
|
-// const commands = forLoop.commands.map(commandWalker)
|
|
|
|
-//
|
|
|
|
-// return {var_attribution,
|
|
|
|
-// var_incrementation,
|
|
|
|
-// expression1,
|
|
|
|
-// expression2,
|
|
|
|
-// expression3,
|
|
|
|
-// commands,
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
|
|
+function forWalker (forLoop) {
|
|
|
|
+ const var_attribution = expressionWalker(forLoop.for_id);
|
|
|
|
+ const var_initial = expressionWalker(forLoop.for_from);
|
|
|
|
+ const condition = expressionWalker(forLoop.for_to);
|
|
|
|
+ const step_expression = forLoop.for_pass
|
|
|
|
+ ? expressionWalker(forLoop.for_pass)
|
|
|
|
+ : [];
|
|
|
|
+ const commands = forLoop.commands.map(commandWalker);
|
|
|
|
+ return { var_attribution, var_initial, condition, step_expression, commands };
|
|
|
|
+}
|
|
|
|
|
|
/**
|
|
/**
|
|
* @param {Commands.While} whileLoop
|
|
* @param {Commands.While} whileLoop
|
|
@@ -205,6 +202,8 @@ function commandWalker (command) {
|
|
parsedCommand = returnWalker(command);
|
|
parsedCommand = returnWalker(command);
|
|
} else if (command instanceof Commands.Switch) {
|
|
} else if (command instanceof Commands.Switch) {
|
|
parsedCommand = switchWalker(command);
|
|
parsedCommand = switchWalker(command);
|
|
|
|
+ } else if (command instanceof Commands.For) {
|
|
|
|
+ parsedCommand = forWalker(command);
|
|
} else {
|
|
} else {
|
|
throw new Error("not implemented");
|
|
throw new Error("not implemented");
|
|
}
|
|
}
|
|
@@ -507,7 +506,7 @@ export function parseCode (text) {
|
|
const functions = program.functions.map(functionWalker);
|
|
const functions = program.functions.map(functionWalker);
|
|
return { globals, functions };
|
|
return { globals, functions };
|
|
} catch (e) {
|
|
} catch (e) {
|
|
- console.error(e)
|
|
|
|
|
|
+ console.error(e);
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|