diff --git a/Core/CodeNS/XMLParser.cs b/Core/CodeNS/XMLParser.cs index d36c2233c5d2a004c540fa2ddb60b2a08b4f0355..7620d40001dfb5037ec3d078eb08843c976efe69 100644 --- a/Core/CodeNS/XMLParser.cs +++ b/Core/CodeNS/XMLParser.cs @@ -1,7 +1,7 @@ -using Core.CommandsNS; -using Core.DataTypeNS; +using Core.DataTypeNS; using Core.FunctionNS; using Core.MemoryNS; +using Core.StatementNS; using System.Collections; using System.Xml.Linq; using System.Xml.XPath; @@ -38,8 +38,8 @@ namespace Core.CodeNS public static List<string> AvailableStructures { get; private set; } private static XElement? xElement = null; - public static void Init(XElement element) - { + public static void Init(XElement element) + { xElement = element; AvailableStructures = new List<string>(); XElement[] structures = xElement.XPathSelectElements("./structure").ToArray(); @@ -77,7 +77,7 @@ namespace Core.CodeNS if (structureParameters != null && structureParameters.Length > 0) { - foreach(XElement structureParameter in structureParameters) + foreach (XElement structureParameter in structureParameters) { string parName = structureParameter.Attribute("name").Value; EDataType dataType = EDataTypeConverter.TextToDataType(structureParameter.Attribute("type").Value); @@ -162,15 +162,15 @@ namespace Core.CodeNS } } - XElement[] FunctionCommands = FunctionElement.XPathSelectElements("./body/*").ToArray(); + XElement[] FunctionStatements = FunctionElement.XPathSelectElements("./body/*").ToArray(); - if (FunctionCommands.Length == 0) + if (FunctionStatements.Length == 0) { - Console.WriteLine("Error: No commands in function"); + Console.WriteLine("Error: No statements in function"); return; } - parseCommands(FunctionCommands); + parseStatements(FunctionStatements); } public static void parseParameters(XElement[] FunctionParameters, Queue<StackObj> parameters) @@ -222,7 +222,7 @@ namespace Core.CodeNS } } - public static void parseCommands(XElement[] FunctionCommands) + public static void parseStatements(XElement[] FunctionStatements) { Function f = Memory.peekFunction(); @@ -232,134 +232,134 @@ namespace Core.CodeNS return; } - f.Commands = processCommands(FunctionCommands); + f.Statements = processStatements(FunctionStatements); } - private static Queue<ACommand> processCommands(XElement[] commands) + private static Queue<AStatement> processStatements(XElement[] statements) { - Queue<ACommand> queue = new Queue<ACommand>(); - foreach (XElement command in commands) + Queue<AStatement> queue = new Queue<AStatement>(); + foreach (XElement statement in statements) { - string commandName = command.Name.ToString(); - Action action = commandName switch + string statementName = statement.Name.ToString(); + Action action = statementName switch { - "declare" => () => queue.Enqueue(HandleDeclare(command)), - "assign" => () => queue.Enqueue(HandleAssign(command)), - "output" => () => queue.Enqueue(HandleOutput(command)), - "input" => () => queue.Enqueue(HandleInput(command)), - "call" => () => queue.Enqueue(HandleCall(command)), - "if" => () => queue.Enqueue(HandleIf(command)), - "for" => () => queue.Enqueue(HandleFor(command)), - "while" => () => queue.Enqueue(HandleWhile(command)), - "do" => () => queue.Enqueue(HandleDo(command)), - "break" => () => queue.Enqueue(HandleBreak(command)), - "continue" => () => queue.Enqueue(HandleContinue(command)), - // + dalsi chybejici commandy - to je asi vsechno - _ => () => Console.WriteLine("Spatny command") + "declare" => () => queue.Enqueue(HandleDeclare(statement)), + "assign" => () => queue.Enqueue(HandleAssign(statement)), + "output" => () => queue.Enqueue(HandleOutput(statement)), + "input" => () => queue.Enqueue(HandleInput(statement)), + "call" => () => queue.Enqueue(HandleCall(statement)), + "if" => () => queue.Enqueue(HandleIf(statement)), + "for" => () => queue.Enqueue(HandleFor(statement)), + "while" => () => queue.Enqueue(HandleWhile(statement)), + "do" => () => queue.Enqueue(HandleDo(statement)), + "break" => () => queue.Enqueue(HandleBreak(statement)), + "continue" => () => queue.Enqueue(HandleContinue(statement)), + // + dalsi chybejici statementy - to je asi vsechno + _ => () => Console.WriteLine("Spatny statement") }; action.Invoke(); } return queue; } - private static ACommand HandleDeclare(XElement command) + private static AStatement HandleDeclare(XElement statement) { - string nameStr = command.Attribute("name")?.Value; - string type = command.Attribute("type")?.Value; + string nameStr = statement.Attribute("name")?.Value; + string type = statement.Attribute("type")?.Value; - return new DeclareCommand(nameStr, type); + return new DeclareStatement(nameStr, type); } - private static ACommand HandleAssign(XElement command) + private static AStatement HandleAssign(XElement statement) { - string name = command.Attribute("variable")?.Value; - string expression = command.Attribute("expression")?.Value; + string name = statement.Attribute("variable")?.Value; + string expression = statement.Attribute("expression")?.Value; - return new AssignCommand(name, expression); + return new AssignStatement(name, expression); } - private static ACommand HandleOutput(XElement command) + private static AStatement HandleOutput(XElement statement) { - string expression = command.Attribute("expression")?.Value; - bool newLine = bool.Parse(command.Attribute("newline")?.Value); + string expression = statement.Attribute("expression")?.Value; + bool newLine = bool.Parse(statement.Attribute("newline")?.Value); - return new OutputCommand(expression, newLine); + return new OutputStatement(expression, newLine); } - private static ACommand HandleInput(XElement command) + private static AStatement HandleInput(XElement statement) { - string variableName = command.Attribute("variable")?.Value; - string prompt = command.Attribute("prompt")?.Value; + string variableName = statement.Attribute("variable")?.Value; + string prompt = statement.Attribute("prompt")?.Value; - return new InputCommand(variableName, prompt); + return new InputStatement(variableName, prompt); } - private static ACommand HandleCall(XElement command) + private static AStatement HandleCall(XElement statement) { - string expression = command.Attribute("expression")?.Value; + string expression = statement.Attribute("expression")?.Value; - return new CallCommand(expression); + return new CallStatement(expression); } - private static ACommand HandleIf(XElement command) + private static AStatement HandleIf(XElement statement) { - string expression = command.Attribute("expression")?.Value; - XElement[] ifCommands = command.XPathSelectElements("./then/*").ToArray(); - XElement[] elseCommands = command.XPathSelectElements("./else/*").ToArray(); + string expression = statement.Attribute("expression")?.Value; + XElement[] ifElements = statement.XPathSelectElements("./then/*").ToArray(); + XElement[] elseElements = statement.XPathSelectElements("./else/*").ToArray(); - Queue<ACommand> ifCmds = processCommands(ifCommands); - Queue<ACommand> elseCmds = processCommands(elseCommands); + Queue<AStatement> ifStatements = processStatements(ifElements); + Queue<AStatement> elseStatements = processStatements(elseElements); - return new IfCommand(expression, ifCmds, elseCmds); + return new IfStatement(expression, ifStatements, elseStatements); } - private static ACommand HandleFor(XElement command) + private static AStatement HandleFor(XElement statement) { - string variable = command.Attribute("variable")?.Value; - string start = command.Attribute("start")?.Value; - string end = command.Attribute("end")?.Value; - string step = command.Attribute("step")?.Value; - string direction = command.Attribute("direction")?.Value; + string variable = statement.Attribute("variable")?.Value; + string start = statement.Attribute("start")?.Value; + string end = statement.Attribute("end")?.Value; + string step = statement.Attribute("step")?.Value; + string direction = statement.Attribute("direction")?.Value; - XElement[] xCommands = command.XPathSelectElements("./*").ToArray(); + XElement[] xStatements = statement.XPathSelectElements("./*").ToArray(); - List<ACommand> commands = processCommands(xCommands).ToList(); + List<AStatement> statements = processStatements(xStatements).ToList(); - return new ForCommand(variable, start, end, step, direction, commands); + return new ForStatement(variable, start, end, step, direction, statements); } - private static ACommand HandleWhile(XElement command) + private static AStatement HandleWhile(XElement statement) { - string expression = command.Attribute("expression")?.Value; + string expression = statement.Attribute("expression")?.Value; - XElement[] xCommands = command.XPathSelectElements("./*").ToArray(); + XElement[] xStatements = statement.XPathSelectElements("./*").ToArray(); - List<ACommand> commands = processCommands(xCommands).ToList(); + List<AStatement> statements = processStatements(xStatements).ToList(); - return new WhileCommand(expression, commands); + return new WhileStatement(expression, statements); } - private static ACommand HandleDo(XElement command) + private static AStatement HandleDo(XElement statement) { - string expression = command.Attribute("expression")?.Value; + string expression = statement.Attribute("expression")?.Value; - XElement[] xCommands = command.XPathSelectElements("./*").ToArray(); + XElement[] xStatements = statement.XPathSelectElements("./*").ToArray(); - List<ACommand> commands = processCommands(xCommands).ToList(); + List<AStatement> statements = processStatements(xStatements).ToList(); - return new DoCommand(expression, commands); + return new DoStatement(expression, statements); } - private static ACommand HandleBreak(XElement command) + private static AStatement HandleBreak(XElement statement) { - return new BreakCommand(); + return new BreakStatement(); } - private static ACommand HandleContinue(XElement command) + private static AStatement HandleContinue(XElement statement) { - return new ContinueCommand(); + return new ContinueStatement(); } } } diff --git a/Core/CommandsNS/AComplexLogic.cs b/Core/CommandsNS/AComplexLogic.cs deleted file mode 100644 index 6a516cca989cc101f96dd47f98fb312af01793ea..0000000000000000000000000000000000000000 --- a/Core/CommandsNS/AComplexLogic.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Core.FunctionNS; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Core.CommandsNS -{ - public abstract class AComplexLogic : AStepable - { - public Function Func { get; set; } - public abstract override void Step(); - public override void WakeUp() - { - if (activeCommand != null) - { - Step(); - } - } - - public List<ACommand> CopyCommands(List<ACommand> commands) - { - List<ACommand> newList = new List<ACommand>(); - - foreach (ACommand cmd in commands) - { - newList.Add((ACommand)cmd.Clone()); - } - - return newList; - } - - public Queue<ACommand> CopyCommands(Queue<ACommand> commands) - { - Queue<ACommand> newList = new Queue<ACommand>(); - - foreach (ACommand cmd in commands) - { - newList.Enqueue((ACommand)cmd.Clone()); - } - - return newList; - } - } -} diff --git a/Core/CommandsNS/If.cs b/Core/CommandsNS/If.cs deleted file mode 100644 index b9cd86f09398cae1abb6d1f462744b768c0351d3..0000000000000000000000000000000000000000 --- a/Core/CommandsNS/If.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Core.DataTypeNS; -using Core.FunctionNS; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; - -namespace Core.CommandsNS -{ - public class If : AComplexLogic - { - public Queue<ACommand> Commands; - - public If(Function function, Queue<ACommand> commands) - { - Func = function; - ParamsAndVars = new Dictionary<string, StackObj>(); - Commands = CopyCommands(commands); - } - - public override void Step() - { - if (activeCommand == null) - { - if (Commands.Count == 0) - { - Func.ComplexLogic.Pop(); - return; - } - activeCommand = Commands.Dequeue(); - } - if (activeCommand.Execute(Func)) - { - activeCommand = null; - } - } - } -} diff --git a/Core/DataTypeNS/Array.cs b/Core/DataTypeNS/Array.cs index 12aa3b98a247a58651e1bae77160b9be756d7ae6..7f50bbfdad2e9000ad4a5ab5700ed1acb8864993 100644 --- a/Core/DataTypeNS/Array.cs +++ b/Core/DataTypeNS/Array.cs @@ -1,13 +1,4 @@ using Core.MemoryNS; -using System; -using System.Collections; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; -using static System.Runtime.InteropServices.JavaScript.JSType; namespace Core.DataTypeNS { @@ -36,7 +27,8 @@ namespace Core.DataTypeNS { Values[i] = createSubArray(new Queue<int>(sizes), dataType); } - } else + } + else { for (int i = 0; i < this.Size; i++) { @@ -82,7 +74,8 @@ namespace Core.DataTypeNS if (Dimensions > 1 && que.Count > 1) { Values[que.Dequeue()].GetArray().setValue(que, stackObj); - } else if (Dimensions == 1 && que.Count == 1) + } + else if (Dimensions == 1 && que.Count == 1) { Values[que.Dequeue()] = stackObj; } diff --git a/Core/DataTypeNS/EDataType.cs b/Core/DataTypeNS/EDataType.cs index b86ffd0bdbcf0a14353093d446551e4e3825e4ee..4dfaa71bd9f36fbd028fd09ff77a4a1d9db90047 100644 --- a/Core/DataTypeNS/EDataType.cs +++ b/Core/DataTypeNS/EDataType.cs @@ -1,10 +1,4 @@ using Core.CodeNS; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; namespace Core.DataTypeNS { diff --git a/Core/DataTypeNS/IHeapObj.cs b/Core/DataTypeNS/IHeapObj.cs index d66ffdbf458a460ad45ded58fb5f556df3c7e2ea..b3ceee21649da099dee907e4756a813694a929e3 100644 --- a/Core/DataTypeNS/IHeapObj.cs +++ b/Core/DataTypeNS/IHeapObj.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Core.DataTypeNS +namespace Core.DataTypeNS { public abstract class IHeapObj { diff --git a/Core/DataTypeNS/StackObj.cs b/Core/DataTypeNS/StackObj.cs index 7d1deec065debd63a2f2c8885bbe3df65255b1c1..67328a66e4a8588034b1e183ccb8189bba4714db 100644 --- a/Core/DataTypeNS/StackObj.cs +++ b/Core/DataTypeNS/StackObj.cs @@ -1,9 +1,4 @@ using Core.MemoryNS; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Core.DataTypeNS { @@ -118,7 +113,7 @@ namespace Core.DataTypeNS { IHeapObj structure = Memory.getHeapObj((Int32)this.Value); if (structure != null) - { + { return (Structure)structure; } } diff --git a/Core/DataTypeNS/Structure.cs b/Core/DataTypeNS/Structure.cs index cd8109faf49f10f1e3202dd4e6d75a201871055b..94d41ebe36e24218aeb5ce029fbc9daf47bed5a7 100644 --- a/Core/DataTypeNS/Structure.cs +++ b/Core/DataTypeNS/Structure.cs @@ -1,17 +1,13 @@ using Core.CodeNS; using Core.MemoryNS; -using System; -using System.Collections.Generic; -using System.Linq; using System.Text; -using System.Threading.Tasks; using System.Xml.Linq; namespace Core.DataTypeNS { public class Structure : IHeapObj { - public string Name { get; private set; } + public string Name { get; private set; } private int References; private Dictionary<string, StackObj> Parametrs; private Dictionary<string, XElement> Functions; diff --git a/Core/ExpressionSolverNS/AFSSolver.cs b/Core/ExpressionSolverNS/AFSSolver.cs index 15efecc42d39727e5c460a08c25317411ec9865f..3929ea16e7a2690627d0db718ed06ec3e857b097 100644 --- a/Core/ExpressionSolverNS/AFSSolver.cs +++ b/Core/ExpressionSolverNS/AFSSolver.cs @@ -1,7 +1,5 @@ using Core.DataTypeNS; using Core.MemoryNS; -using System.Xml.Linq; -using static System.Net.Mime.MediaTypeNames; using Array = Core.DataTypeNS.Array; namespace Core.ExpressionSolverNS @@ -46,7 +44,8 @@ namespace Core.ExpressionSolverNS i = i + arrayLenght; index = i; firstToken = false; - } else + } + else { preprocessStructure(token.Substring(index, i)); index = i; @@ -82,7 +81,8 @@ namespace Core.ExpressionSolverNS Console.WriteLine("ERROR"); } this.Result = stackObj; - } else + } + else { bracketIndex = 0; } diff --git a/Core/ExpressionSolverNS/ExpressionSolver.cs b/Core/ExpressionSolverNS/ExpressionSolver.cs index b94198174af13fe048b49a9e0d12fa5882890889..9d78a46e25adbdb958f844945ce5815afb7df581 100644 --- a/Core/ExpressionSolverNS/ExpressionSolver.cs +++ b/Core/ExpressionSolverNS/ExpressionSolver.cs @@ -1,15 +1,11 @@ -using System; -using System.Collections; -using System.Linq; +using org.matheval; using System.Text; -using System.Threading.Tasks; -using org.matheval; namespace Core.ExpressionSolverNS { - using MemoryNS; - using FunctionNS; using Core.DataTypeNS; + using FunctionNS; + using MemoryNS; public class ExpressionSolver : ITreeNode { @@ -50,8 +46,8 @@ namespace Core.ExpressionSolverNS { if (this.Expression != null) { - if (IsMainNode) - { + if (IsMainNode) + { preprocessExpression(); } Hit hit = cutExpression(this.Expression); @@ -62,8 +58,9 @@ namespace Core.ExpressionSolverNS } if (hit == null) { - if(processNoHit()) { return true; } - } else + if (processNoHit()) { return true; } + } + else { this.Operator = hit.Character; if (hit.Index != 0) @@ -73,7 +70,8 @@ namespace Core.ExpressionSolverNS this.RNode = new ExpressionSolver(Expression.Substring(hit.Index + hit.Character.Length), false); } return evaluate(); - } else + } + else { Console.WriteLine("ERROR"); return false; @@ -165,14 +163,16 @@ namespace Core.ExpressionSolverNS this.Result = new StackObj(3.1415); this.IsSolved = true; return true; - } else if (this.Expression.Contains("\"")) + } + else if (this.Expression.Contains("\"")) { // TEXT this.Expression = Expression.Substring(1, Expression.Length - 2); this.Result = new StackObj(this.Expression); this.IsSolved = true; return true; - } else if (this.Expression.Contains("[") || this.Expression.Contains(".") || this.Expression.Contains("(")) + } + else if (this.Expression.Contains("[") || this.Expression.Contains(".") || this.Expression.Contains("(")) { // ARRAY, FUNCTION, STRUCTURE OR COMBINATION this.LNode = new AFSSolver(this.Expression); @@ -248,10 +248,10 @@ namespace Core.ExpressionSolverNS string character = Char.ToString(expression.ElementAt(i)); if (character.Equals("(")) { sumOfBracket--; } else if (character.Equals(")")) { sumOfBracket++; } - if (character.Equals("\"")) - { + if (character.Equals("\"")) + { if (rightSumOfQuotation) { rightSumOfQuotation = false; } - else { rightSumOfQuotation = true; } + else { rightSumOfQuotation = true; } } else if (sumOfBracket == 0 && rightSumOfQuotation && SingleOperators.Contains(character)) { diff --git a/Core/ExpressionSolverNS/FunctionSolver.cs b/Core/ExpressionSolverNS/FunctionSolver.cs index 5adff7b076983ddbd6e36bbf07ae66ab2cf66819..a744ae52fb36d319b94937b7f926d0e42e09de20 100644 --- a/Core/ExpressionSolverNS/FunctionSolver.cs +++ b/Core/ExpressionSolverNS/FunctionSolver.cs @@ -1,15 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Core.ExpressionSolverNS +namespace Core.ExpressionSolverNS { - using MemoryNS; using Core.CodeNS; using Core.DataTypeNS; + using MemoryNS; using org.matheval; + using System.Text; internal class FunctionSolver : ITreeNode { @@ -20,17 +15,18 @@ namespace Core.ExpressionSolverNS private bool FunctionCreated = false; private bool ParSolved = false; private int NumberOfPar = 0; - public bool FromCall { get; set; } + public bool FromCall { get; set; } private ITreeNode Parent; public FunctionSolver(string name, Queue<string> unsolvedParameters, ITreeNode parent) { this.Name = name; this.UnsolvedPar = unsolvedParameters; - if (unsolvedParameters != null ) + if (unsolvedParameters != null) { this.NumberOfPar = unsolvedParameters.Count(); - } else { this.NumberOfPar = 0; } + } + else { this.NumberOfPar = 0; } this.FromCall = false; this.Parent = parent; } @@ -47,17 +43,22 @@ namespace Core.ExpressionSolverNS if (Parent.GetStackObj() != null) { Parent.GetStackObj().GetStructure().callFunction(Name, SolvedPar); - } else + } + else { string expressionF = XMLParser.functionNameInExpression(Name); bool implementedF = XMLParser.functionIsImplemented(Name); - if (expressionF != null) { + if (expressionF != null) + { SolveFWithExpression(expressionF); return true; - } else if (implementedF) { - SolveImplementedF(); + } + else if (implementedF) + { + SolveImplementedF(); return true; - } else + } + else { XMLParser.createFunction(Name, SolvedPar); } @@ -151,7 +152,8 @@ namespace Core.ExpressionSolverNS else if (i > 0) { this.Result = new StackObj(1); } this.IsSolved = true; return; - } else if (st.Type == EDataType.REAL) + } + else if (st.Type == EDataType.REAL) { Double i = (Double)st.Value; if (i < 0) { this.Result = new StackObj(-1); } @@ -181,7 +183,7 @@ namespace Core.ExpressionSolverNS StackObj stIndex = SolvedPar.Dequeue(); if (stString != null && stIndex != null) { - string text = (string) stString.Value; + string text = (string)stString.Value; if (Int32.TryParse(stIndex.Value.ToString(), out Int32 num)) { this.Result = new StackObj(text.ElementAt(num)); @@ -296,7 +298,8 @@ namespace Core.ExpressionSolverNS { this.Result = new StackObj(st.GetArray().Size); this.IsSolved = true; - } else + } + else { Console.WriteLine("Size function: Wrong StackObj"); } diff --git a/Core/ExpressionSolverNS/ITreeNode.cs b/Core/ExpressionSolverNS/ITreeNode.cs index a5a2221595b6158d3ad8d06c92a274988def5135..b00338e7ed46d33409e291a2c3f2b81133c3c054 100644 --- a/Core/ExpressionSolverNS/ITreeNode.cs +++ b/Core/ExpressionSolverNS/ITreeNode.cs @@ -1,9 +1,4 @@ using Core.DataTypeNS; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Core.ExpressionSolverNS { diff --git a/Core/FunctionNS/AStepable.cs b/Core/FunctionNS/AStepable.cs index 0c0ae0457833269064b6e694d5b6ecf8be24200c..2ac2017e5e5415c302e28dc60efc298e5a393ab6 100644 --- a/Core/FunctionNS/AStepable.cs +++ b/Core/FunctionNS/AStepable.cs @@ -1,12 +1,12 @@ -using Core.CommandsNS; using Core.DataTypeNS; +using Core.StatementNS; namespace Core.FunctionNS { public abstract class AStepable { public Dictionary<string, StackObj> ParamsAndVars { get; set; } - public ACommand activeCommand { get; set; } + public AStatement activeStatement { get; set; } public abstract void Step(); public abstract void WakeUp(); } diff --git a/Core/FunctionNS/Function.cs b/Core/FunctionNS/Function.cs index 920d2ccfdbb832b552419a8690e7d5e55eb2b403..cbfe1f3a3951ee60ed37418c395fdf2a27d0abea 100644 --- a/Core/FunctionNS/Function.cs +++ b/Core/FunctionNS/Function.cs @@ -1,6 +1,6 @@ -using Core.CommandsNS; using Core.DataTypeNS; using Core.MemoryNS; +using Core.StatementNS; using System.Collections; namespace Core.FunctionNS @@ -12,11 +12,11 @@ namespace Core.FunctionNS */ public string Name { get; set; } public string ReturnValName { get; set; } - public Queue<ACommand> Commands; - public Stack<AComplexLogic> ComplexLogic { get; } + public Queue<AStatement> Statements; + public Stack<AComplexLogic> ComplexLogic { get; } public Structure Structure { get; set; } - public Function(string name, string returnValName) => (Name, ReturnValName, ParamsAndVars, Commands, ComplexLogic) = (name, returnValName, new Dictionary<string, StackObj>(), new Queue<ACommand>(), new Stack<AComplexLogic>()); + public Function(string name, string returnValName) => (Name, ReturnValName, ParamsAndVars, Statements, ComplexLogic) = (name, returnValName, new Dictionary<string, StackObj>(), new Queue<AStatement>(), new Stack<AComplexLogic>()); /* * Code @@ -28,18 +28,18 @@ namespace Core.FunctionNS ComplexLogic.Peek().Step(); return; } - if (activeCommand == null) + if (activeStatement == null) { - if (Commands.Count == 0) + if (Statements.Count == 0) { End(); return; } - activeCommand = Commands.Dequeue(); + activeStatement = Statements.Dequeue(); } - if (activeCommand.Execute(this)) + if (activeStatement.Execute(this)) { - activeCommand = null; + activeStatement = null; } } @@ -49,7 +49,7 @@ namespace Core.FunctionNS { ComplexLogic.Peek().WakeUp(); } - else if (activeCommand != null) + else if (activeStatement != null) { Step(); } @@ -59,15 +59,17 @@ namespace Core.FunctionNS { if (ReturnValName != null) { - StackObj s = getVariableByName(ReturnValName); + StackObj s = getVariableByName(ReturnValName); if (s != null) { Memory.pushReturnValue(s); - } else + } + else { Memory.pushReturnValue(new StackObj("None", EDataType.WRONG)); } - } else + } + else { Memory.pushReturnValue(new StackObj("None", EDataType.WRONG)); } diff --git a/Core/Interpreter.cs b/Core/Interpreter.cs index 31a847352fad36e186c1967f5a2540344310ff80..cc4cca6d01bc112c3000192e5a7693778f95723a 100644 --- a/Core/Interpreter.cs +++ b/Core/Interpreter.cs @@ -4,8 +4,9 @@ using Core.MemoryNS; using FunctionNS; using System.Xml.Linq; + using System.Xml.Schema; - internal class Interpreter + public class Interpreter { private static bool RunTests = false; private static int NumberOfTests = 21; @@ -51,6 +52,21 @@ } XDocument doc = XDocument.Load(xmlFile); + var schema = new XmlSchemaSet(); + schema.Add("", Directory.GetCurrentDirectory() + "\\..\\..\\..\\fprg.xsd"); + + doc.Validate(schema, (xdoc, err) => + { + XmlSeverityType type = XmlSeverityType.Warning; + + if (Enum.TryParse<XmlSeverityType>("Error", out type)) + { + if (type == XmlSeverityType.Error) + { + throw new Exception(err.Message); + } + } + }); if (doc.Root == null) { diff --git a/Core/MemoryNS/Memory.cs b/Core/MemoryNS/Memory.cs index b63af8083543e562a5bde2985de23f7b345e904c..ca125f217be6c362e9a457f7e96503335070f9cb 100644 --- a/Core/MemoryNS/Memory.cs +++ b/Core/MemoryNS/Memory.cs @@ -1,13 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Core.MemoryNS +namespace Core.MemoryNS { - using FunctionNS; using DataTypeNS; + using FunctionNS; using System.Collections; public static class Memory @@ -21,13 +15,13 @@ namespace Core.MemoryNS */ public static void pushFunction(Function function) { functionStack.Push(function); } - public static Function? popFunction() + public static Function? popFunction() { - try { return functionStack.Pop(); } + try { return functionStack.Pop(); } catch { return null; } } - public static Function? peekFunction() + public static Function? peekFunction() { try { return functionStack.Peek(); } catch { return null; } @@ -36,7 +30,7 @@ namespace Core.MemoryNS /* * Heap methods */ - public static int addHeapObj(IHeapObj heapObj) + public static int addHeapObj(IHeapObj heapObj) { for (int i = 0; i < heap.Count + 1; i++) { @@ -47,7 +41,7 @@ namespace Core.MemoryNS heap.Insert(i, heapObj); return i; }; - } + } catch { heap.Insert(i, heapObj); @@ -65,11 +59,13 @@ namespace Core.MemoryNS if (heapObj == null) { return -1; - } else + } + else { return addHeapObj(heapObj.clone()); } - } catch + } + catch { return -1; } @@ -92,7 +88,8 @@ namespace Core.MemoryNS try { heap[index] = null; - } catch { } + } + catch { } } /* diff --git a/Core/StatementNS/AComplexLogic.cs b/Core/StatementNS/AComplexLogic.cs new file mode 100644 index 0000000000000000000000000000000000000000..3960052673dd606c0148ff81f16ffcc81554ca89 --- /dev/null +++ b/Core/StatementNS/AComplexLogic.cs @@ -0,0 +1,41 @@ +using Core.FunctionNS; + +namespace Core.StatementNS +{ + public abstract class AComplexLogic : AStepable + { + public Function Func { get; set; } + public abstract override void Step(); + public override void WakeUp() + { + if (activeStatement != null) + { + Step(); + } + } + + public List<AStatement> CopyStatements(List<AStatement> statements) + { + List<AStatement> newList = new List<AStatement>(); + + foreach (AStatement statement in statements) + { + newList.Add((AStatement)statement.Clone()); + } + + return newList; + } + + public Queue<AStatement> CopyStatements(Queue<AStatement> statements) + { + Queue<AStatement> newList = new Queue<AStatement>(); + + foreach (AStatement statement in statements) + { + newList.Enqueue((AStatement)statement.Clone()); + } + + return newList; + } + } +} diff --git a/Core/CommandsNS/ACycles.cs b/Core/StatementNS/ACycles.cs similarity index 88% rename from Core/CommandsNS/ACycles.cs rename to Core/StatementNS/ACycles.cs index bf767c922caba05ff5600141ce47d1efcdcb53e6..7a6f5009643f744006fc5fbdbfb57ad05e6b66d5 100644 --- a/Core/CommandsNS/ACycles.cs +++ b/Core/StatementNS/ACycles.cs @@ -1,4 +1,4 @@ -namespace Core.CommandsNS +namespace Core.StatementNS { public abstract class ACycles : AComplexLogic { diff --git a/Core/CommandsNS/ACommand.cs b/Core/StatementNS/AStatement.cs similarity index 79% rename from Core/CommandsNS/ACommand.cs rename to Core/StatementNS/AStatement.cs index 66d3cb747c6e2f53dbfeb5afe776f9c4716689f1..5b2519503c2c7166dec073cd41c2dfafe5e09f20 100644 --- a/Core/CommandsNS/ACommand.cs +++ b/Core/StatementNS/AStatement.cs @@ -1,24 +1,18 @@ using Core.DataTypeNS; using Core.ExpressionSolverNS; using Core.MemoryNS; -using org.matheval.Node; -using System.Collections; -using System.ComponentModel.DataAnnotations; -using static System.Runtime.InteropServices.JavaScript.JSType; -using org.matheval.Node; -using System.Collections.Generic; -using Function = Core.FunctionNS.Function; using Array = Core.DataTypeNS.Array; +using Function = Core.FunctionNS.Function; -namespace Core.CommandsNS +namespace Core.StatementNS { - public abstract class ACommand : ICloneable + public abstract class AStatement : ICloneable { public abstract bool Execute(Function function); public abstract object Clone(); } - public class AssignCommand : ACommand + public class AssignStatement : AStatement { public string VariableName { get; } public string Expression { get; } @@ -26,7 +20,7 @@ namespace Core.CommandsNS private ExpressionSolver variableExSolver; private ArraySolver arraySolver; - public AssignCommand(string variableName, string expression) => + public AssignStatement(string variableName, string expression) => (VariableName, Expression) = (variableName, expression); public override bool Execute(Function function) @@ -51,10 +45,11 @@ namespace Core.CommandsNS if (st != null) { st.Value = exSolver.GetValue(); - } else + } + else { Console.WriteLine(Expression); - Console.WriteLine("ACommand - Assignn - Execute"); + Console.WriteLine("AStatement - Assign - Execute"); } return true; } @@ -90,16 +85,16 @@ namespace Core.CommandsNS public override object Clone() { - return new AssignCommand(this.VariableName, this.Expression); + return new AssignStatement(this.VariableName, this.Expression); } } - public class DeclareCommand : ACommand + public class DeclareStatement : AStatement { public string Name { get; } public string Type { get; } - public DeclareCommand(string name, string type) => + public DeclareStatement(string name, string type) => (Name, Type) = (name, type); public override bool Execute(Function function) @@ -130,19 +125,19 @@ namespace Core.CommandsNS return true; } - public override ACommand Clone() + public override AStatement Clone() { - return new DeclareCommand(this.Name, this.Type); + return new DeclareStatement(this.Name, this.Type); } } - public class OutputCommand : ACommand + public class OutputStatement : AStatement { public string Expression { get; } public bool NewLine { get; } private ExpressionSolver exSolver; - public OutputCommand(string expression, bool newline) => + public OutputStatement(string expression, bool newline) => (Expression, NewLine) = (expression, newline); public override bool Execute(Function function) @@ -168,17 +163,17 @@ namespace Core.CommandsNS return false; } - public override ACommand Clone() + public override AStatement Clone() { - return new OutputCommand(this.Expression, this.NewLine); + return new OutputStatement(this.Expression, this.NewLine); } } - public class CallCommand : ACommand + public class CallStatement : AStatement { public string Expression { get; } private AFSSolver solver; - public CallCommand(string expression) => + public CallStatement(string expression) => Expression = expression; public override bool Execute(Function function) @@ -207,18 +202,18 @@ namespace Core.CommandsNS return solver.Solve(); } - public override ACommand Clone() + public override AStatement Clone() { - return new CallCommand(this.Expression); + return new CallStatement(this.Expression); } } - public class InputCommand : ACommand + public class InputStatement : AStatement { public string VariableName { get; } public string Prompt { get; } - public InputCommand(string variableName, string prompt) => + public InputStatement(string variableName, string prompt) => (VariableName, Prompt) = (variableName, prompt); public override bool Execute(Function function) @@ -237,22 +232,22 @@ namespace Core.CommandsNS return true; } - public override ACommand Clone() + public override AStatement Clone() { - return new InputCommand(this.VariableName, this.Prompt); + return new InputStatement(this.VariableName, this.Prompt); } } - public class IfCommand : ACommand + public class IfStatement : AStatement { public string Expression { get; } - public Queue<ACommand> IfCommands { get; } - public Queue<ACommand> ElseCommands { get; } - private Queue<ACommand> UsedCommands; + public Queue<AStatement> IfStatements { get; } + public Queue<AStatement> ElseStatements { get; } + private Queue<AStatement> UsedStatements; private ExpressionSolver exSolver; - public IfCommand(string expression, Queue<ACommand> ifCommands, Queue<ACommand> elseCommands) => - (Expression, IfCommands, ElseCommands) = (expression, ifCommands, elseCommands); + public IfStatement(string expression, Queue<AStatement> ifStatements, Queue<AStatement> elseStatements) => + (Expression, IfStatements, ElseStatements) = (expression, ifStatements, elseStatements); public override bool Execute(Function function) { @@ -267,39 +262,39 @@ namespace Core.CommandsNS Console.WriteLine("Expression nevratil boolean"); } bool isTrue = (bool)exSolver.GetValue(); - function.ComplexLogic.Push(new If(function, isTrue ? IfCommands : ElseCommands)); + function.ComplexLogic.Push(new If(function, isTrue ? IfStatements : ElseStatements)); return true; } return false; } - public override ACommand Clone() + public override AStatement Clone() { - return new IfCommand(this.Expression, this.IfCommands, this.ElseCommands); + return new IfStatement(this.Expression, this.IfStatements, this.ElseStatements); } } - public class ForCommand : ACommand + public class ForStatement : AStatement { public string VariableName { get; } public string Start { get; } public string End { get; } public string _Step { get; } public string Direction { get; } - public List<ACommand> Commands { get; } + public List<AStatement> Statements { get; } private ExpressionSolver? exSolver; private bool[] processStages = new bool[3]; private object StartVal { set; get; } - public ForCommand(string variableName, string start, string end, string step, string direction, List<ACommand> commands) + public ForStatement(string variableName, string start, string end, string step, string direction, List<AStatement> statements) { VariableName = variableName; Start = start; End = end; _Step = step; Direction = direction; - Commands = commands; + Statements = statements; processStages.AsSpan().Fill(false); } @@ -375,7 +370,7 @@ namespace Core.CommandsNS direction = true; } - function.ComplexLogic.Push(new For(function, VariableName, StartVal, End, _Step, direction, Commands)); + function.ComplexLogic.Push(new For(function, VariableName, StartVal, End, _Step, direction, Statements)); processStages.AsSpan().Fill(false); @@ -415,21 +410,21 @@ namespace Core.CommandsNS return false; } - public override ACommand Clone() + public override AStatement Clone() { - return new ForCommand(this.VariableName, this.Start, this.End, this._Step, this.Direction, this.Commands); + return new ForStatement(this.VariableName, this.Start, this.End, this._Step, this.Direction, this.Statements); } } - public class WhileCommand : ACommand + public class WhileStatement : AStatement { public string Expression { get; } - public List<ACommand> Commands { get; } + public List<AStatement> Statements { get; } private ExpressionSolver exSolver; - public WhileCommand(string expression, List<ACommand> commands) => - (Expression, Commands) = (expression, commands); + public WhileStatement(string expression, List<AStatement> statements) => + (Expression, Statements) = (expression, statements); public override bool Execute(Function function) { @@ -447,7 +442,7 @@ namespace Core.CommandsNS return false; } - function.ComplexLogic.Push(new While(function, Expression, Commands)); + function.ComplexLogic.Push(new While(function, Expression, Statements)); return true; } @@ -455,21 +450,21 @@ namespace Core.CommandsNS return false; } - public override ACommand Clone() + public override AStatement Clone() { - return new WhileCommand(this.Expression, this.Commands); + return new WhileStatement(this.Expression, this.Statements); } } - public class DoCommand : ACommand + public class DoStatement : AStatement { public string Expression { get; } - public List<ACommand> Commands { get; } + public List<AStatement> Statements { get; } private ExpressionSolver exSolver; - public DoCommand(string expression, List<ACommand> commands) => - (Expression, Commands) = (expression, commands); + public DoStatement(string expression, List<AStatement> statements) => + (Expression, Statements) = (expression, statements); public override bool Execute(Function function) { @@ -488,7 +483,7 @@ namespace Core.CommandsNS return false; } - function.ComplexLogic.Push(new DoWhile(function, Expression, Commands)); + function.ComplexLogic.Push(new DoWhile(function, Expression, Statements)); return true; } @@ -496,40 +491,40 @@ namespace Core.CommandsNS return false; } - public override ACommand Clone() + public override AStatement Clone() { - return new DoCommand(this.Expression, this.Commands); + return new DoStatement(this.Expression, this.Statements); } } - public class BreakCommand : ACommand + public class BreakStatement : AStatement { public override bool Execute(Function function) { - Console.WriteLine("Execute break command"); + Console.WriteLine("Execute break statement"); // TODO - kompletne ukonci for/while/do blok // asi se resi zahozenim funkce??? viz Memory.PopFunction() // bacha pravdepodobne bude vnorenej jeste v nejakym if bloku return true; } - public override ACommand Clone() + public override AStatement Clone() { throw new NotImplementedException(); } } - public class ContinueCommand : ACommand + public class ContinueStatement : AStatement { public override bool Execute(Function function) { - Console.WriteLine("Execute continue command"); + Console.WriteLine("Execute continue statement"); // TODO - mel by zmenit flow for/while/do cyklu. - // cykly si interne musi drzet nejaky counter na commandy - // a ten se timhle commandem resetuje + // cykly si interne musi drzet nejaky counter na statementy + // a ten se timhle statementem resetuje // bacha pravdepodobne bude vnorenej jeste v nejakym if bloku return true; } - public override ACommand Clone() + public override AStatement Clone() { throw new NotImplementedException(); } diff --git a/Core/CommandsNS/DoWhile.cs b/Core/StatementNS/DoWhile.cs similarity index 70% rename from Core/CommandsNS/DoWhile.cs rename to Core/StatementNS/DoWhile.cs index e4b4dd8932c0195998263cf19a3e5433e7e71f32..6cc5f9cfdd2e36b67c700ecba118d142ae9792f5 100644 --- a/Core/CommandsNS/DoWhile.cs +++ b/Core/StatementNS/DoWhile.cs @@ -1,48 +1,41 @@ using Core.DataTypeNS; using Core.ExpressionSolverNS; using Core.FunctionNS; -using System; -using System.Collections.Generic; -using System.Diagnostics.Metrics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using static Core.CommandsNS.ACycles; -namespace Core.CommandsNS +namespace Core.StatementNS { public class DoWhile : ACycles { private string Expression; - public List<ACommand> CommandsBackup = new List<ACommand>(); - public List<ACommand> Commands = new List<ACommand>(); + public List<AStatement> StatementsBackup = new List<AStatement>(); + public List<AStatement> Statements = new List<AStatement>(); private ExpressionSolver? exSolver; private int Counter = 0; - public DoWhile(Function function, string expression, List<ACommand> commands) + public DoWhile(Function function, string expression, List<AStatement> statements) { Func = function; ParamsAndVars = new Dictionary<string, StackObj>(); Expression = expression; - CommandsBackup = commands; - Commands = CopyCommands(commands); + StatementsBackup = statements; + Statements = CopyStatements(statements); } public override void Step() { - if (this.Counter < Commands.Count) + if (this.Counter < Statements.Count) { - if (activeCommand == null) + if (activeStatement == null) { - activeCommand = Commands.ElementAt(Counter); + activeStatement = Statements.ElementAt(Counter); } - if (activeCommand.Execute(Func)) + if (activeStatement.Execute(Func)) { - activeCommand = null; + activeStatement = null; Counter++; } } - else if (Counter == Commands.Count) + else if (Counter == Statements.Count) { switch (checkCondition()) { @@ -53,7 +46,7 @@ namespace Core.CommandsNS ParamsAndVars.Clear(); - Commands = CopyCommands(CommandsBackup); + Statements = CopyStatements(StatementsBackup); break; case EConditionStages.False: diff --git a/Core/CommandsNS/For.cs b/Core/StatementNS/For.cs similarity index 83% rename from Core/CommandsNS/For.cs rename to Core/StatementNS/For.cs index 032bcb793c38c403ab31cc226e3ed447aa1c1ec4..8b04a15180cc318a18f194595b6bfc3f6fe32008 100644 --- a/Core/CommandsNS/For.cs +++ b/Core/StatementNS/For.cs @@ -2,7 +2,7 @@ using Core.ExpressionSolverNS; using Core.FunctionNS; -namespace Core.CommandsNS +namespace Core.StatementNS { public class For : ACycles { @@ -10,17 +10,17 @@ namespace Core.CommandsNS private string End; private string _Step; private bool Direction; - public List<ACommand> CommandsBackup = new List<ACommand>(); - public List<ACommand> Commands = new List<ACommand>(); + public List<AStatement> StatementsBackup = new List<AStatement>(); + public List<AStatement> Statements = new List<AStatement>(); private ExpressionSolver? exSolver; private int Counter = -1; - public For(Function function, string varName, object start, string end, string _step, bool direction, List<ACommand> commands) + public For(Function function, string varName, object start, string end, string _step, bool direction, List<AStatement> statements) { Func = function; ParamsAndVars = new Dictionary<string, StackObj>(); - CommandsBackup = commands; - Commands = CopyCommands(commands); + StatementsBackup = statements; + Statements = CopyStatements(statements); modifyIterationVariable(varName, start); End = end; _Step = _step; @@ -44,21 +44,21 @@ namespace Core.CommandsNS return; } } - else if ((Counter > -1) && (Counter < Commands.Count)) + else if ((Counter > -1) && (Counter < Statements.Count)) { - if (activeCommand == null) + if (activeStatement == null) { - activeCommand = Commands.ElementAt(Counter); + activeStatement = Statements.ElementAt(Counter); } - if (activeCommand.Execute(Func)) + if (activeStatement.Execute(Func)) { - activeCommand = null; + activeStatement = null; Counter++; } } - else if (Counter == Commands.Count) + else if (Counter == Statements.Count) { if (iterate()) { @@ -145,7 +145,7 @@ namespace Core.CommandsNS ParamsAndVars.Clear(); - Commands = CopyCommands(CommandsBackup); + Statements = CopyStatements(StatementsBackup); return true; } diff --git a/Core/StatementNS/If.cs b/Core/StatementNS/If.cs new file mode 100644 index 0000000000000000000000000000000000000000..58513fe82f57afad02ed2b7dc6ac438ae1eb41e6 --- /dev/null +++ b/Core/StatementNS/If.cs @@ -0,0 +1,34 @@ +using Core.DataTypeNS; +using Core.FunctionNS; + +namespace Core.StatementNS +{ + public class If : AComplexLogic + { + public Queue<AStatement> Statements; + + public If(Function function, Queue<AStatement> statements) + { + Func = function; + ParamsAndVars = new Dictionary<string, StackObj>(); + Statements = CopyStatements(statements); + } + + public override void Step() + { + if (activeStatement == null) + { + if (Statements.Count == 0) + { + Func.ComplexLogic.Pop(); + return; + } + activeStatement = Statements.Dequeue(); + } + if (activeStatement.Execute(Func)) + { + activeStatement = null; + } + } + } +} diff --git a/Core/CommandsNS/While.cs b/Core/StatementNS/While.cs similarity index 75% rename from Core/CommandsNS/While.cs rename to Core/StatementNS/While.cs index f01f787ca952fe6671ad50e594beb48958279c82..ee0f03f7b83748898bdfcbe1a561015fe20b1aca 100644 --- a/Core/CommandsNS/While.cs +++ b/Core/StatementNS/While.cs @@ -2,23 +2,23 @@ using Core.ExpressionSolverNS; using Core.FunctionNS; -namespace Core.CommandsNS +namespace Core.StatementNS { public class While : ACycles { private string Expression; - public List<ACommand> CommandsBackup = new List<ACommand>(); - public List<ACommand> Commands = new List<ACommand>(); + public List<AStatement> StatementsBackup = new List<AStatement>(); + public List<AStatement> Statements = new List<AStatement>(); private ExpressionSolver? exSolver; private int Counter = -1; - public While(Function function, string expression, List<ACommand> commands) + public While(Function function, string expression, List<AStatement> statements) { Func = function; ParamsAndVars = new Dictionary<string, StackObj>(); Expression = expression; - CommandsBackup = commands; - Commands = CopyCommands(commands); + StatementsBackup = statements; + Statements = CopyStatements(statements); } public override void Step() { @@ -37,26 +37,26 @@ namespace Core.CommandsNS return; } } - else if ((Counter > -1) && (Counter < Commands.Count)) + else if ((Counter > -1) && (Counter < Statements.Count)) { - if (activeCommand == null) + if (activeStatement == null) { - activeCommand = Commands.ElementAt(Counter); + activeStatement = Statements.ElementAt(Counter); } - if (activeCommand.Execute(Func)) + if (activeStatement.Execute(Func)) { - activeCommand = null; + activeStatement = null; Counter++; } } - else if (Counter == Commands.Count) + else if (Counter == Statements.Count) { Counter = -1; ParamsAndVars.Clear(); - Commands = CopyCommands(CommandsBackup); + Statements = CopyStatements(StatementsBackup); } } diff --git a/Core/fprg.xsd b/Core/fprg.xsd new file mode 100644 index 0000000000000000000000000000000000000000..fe95e82113c1a01442e8c415a1df153dd6566ccf --- /dev/null +++ b/Core/fprg.xsd @@ -0,0 +1,310 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xs:schema + xmlns:xs="http://www.w3.org/2001/XMLSchema" + elementFormDefault="qualified"> + <xs:element name="flowgorithm"> + <xs:complexType> + <xs:sequence> + <xs:element name="attributes" minOccurs="0" maxOccurs="1" type="attributesProto"/> + <xs:element name="function" type="functionProto" maxOccurs="unbounded"/> + <xs:sequence> + <xs:element minOccurs="0" maxOccurs="unbounded" name="structure" type="structureProto"/> + </xs:sequence> + </xs:sequence> + <xs:attribute name="fileversion" type="xs:decimal" use="required" /> + </xs:complexType> + </xs:element> + + <xs:complexType name="structureProto"> + <xs:annotation> + <xs:documentation>A structure allows programs to both reuse code and simplify logic. Data is passed into structures using parameters. Structures define functions taht can be called.</xs:documentation> + </xs:annotation> + <xs:sequence> + <xs:element name="parameters" type="parametersProto"/> + <xs:sequence> + <xs:element minOccurs="0" maxOccurs="unbounded" name="function" type="functionProto"/> + </xs:sequence> + </xs:sequence> + <xs:attribute name="name" type="xs:string" use="required" /> + </xs:complexType> + + <xs:complexType name="attributesProto"> + <xs:sequence> + <xs:element minOccurs="0" maxOccurs="unbounded" name="attribute"> + <xs:complexType> + <xs:attribute name="name" type="attributeEnum"/> + <xs:attribute name="value" type="xs:string" use="required" /> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="functionProto"> + <xs:annotation> + <xs:documentation>A function allows programs to both reuse code and simplify logic. Data is passed into functions using parameters.</xs:documentation> + </xs:annotation> + <xs:sequence> + <xs:element name="parameters" type="parametersProto"/> + <xs:element name="body" type="bodyProto"/> + </xs:sequence> + <xs:attribute name="name" type="xs:string" use="required" /> + <xs:attribute name="type" type="returntypeEnum" use="required" /> + <xs:attribute name="variable" type="xs:string" use="required" /> + </xs:complexType> + + <xs:complexType name="parametersProto"> + <xs:sequence minOccurs="0" maxOccurs="unbounded"> + <xs:element name="parameter"> + <xs:complexType> + <xs:attribute name="name" type="xs:string" use="required" /> + <xs:attribute name="type" type="typeEnum" use="required" /> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="bodyProto"> + <xs:choice maxOccurs="unbounded" minOccurs="0"> + <xs:element name="assign" type="assignProto"/> + <xs:element name="breakpoint" type="breakpointProto"/> + <xs:element name="call" type="callProto"/> + <xs:element name="comment" type="commentProto"/> + <xs:element name="declare" type="declareProto"/> + <xs:element name="do" type="doProto"/> + <xs:element name="for" type="forProto"/> + <xs:element name="if" type="ifProto"/> + <xs:element name="input" type="inputProto"/> + <xs:element name="output" type="outputProto"/> + <xs:element name="while" type="whileProto"/> + <xs:element name="continue" type="continueProto"/> + <xs:element name="break" type="breakProto"/> + </xs:choice> + </xs:complexType> + + <xs:complexType name="assignProto"> + <xs:annotation> + <xs:documentation>An Assignment Statement calculates an expression and then stores the result in a variable.</xs:documentation> + </xs:annotation> + <xs:attribute name="variable" type="xs:string" use="required"> + <xs:annotation> + <xs:documentation>Variable Name.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="expression" type="xs:string" use="required"> + <xs:annotation> + <xs:documentation>Expression.</xs:documentation> + </xs:annotation> + </xs:attribute> + </xs:complexType> + + <xs:complexType name="breakpointProto"> + </xs:complexType> + + <xs:complexType name="callProto"> + <xs:annotation> + <xs:documentation>A Call Statement transfers control to a function. Information is passed into the function using 'arguments'.</xs:documentation> + </xs:annotation> + <xs:attribute name="expression" type="xs:string" use="required"> + <xs:annotation> + <xs:documentation>Function name. Delimit arguments with parenthesis.</xs:documentation> + </xs:annotation> + </xs:attribute> + </xs:complexType> + + <xs:complexType name="commentProto"> + <xs:annotation> + <xs:documentation>Comments don't affect how your program runs. They are used to document information about the program.</xs:documentation> + </xs:annotation> + <xs:attribute name="text" type="xs:string" use="required"> + <xs:annotation> + <xs:documentation>Comment text without double quotes.</xs:documentation> + </xs:annotation> + </xs:attribute> + </xs:complexType> + + <xs:complexType name="declareProto"> + <xs:annotation> + <xs:documentation>A Declare Statement is used to create variables and arrays. These are used to store data while the program runs.</xs:documentation> + </xs:annotation> + <xs:attribute name="name" type="xs:string" use="required"> + <xs:annotation> + <xs:documentation>Variable Names. It is possible to declare multiple comma separated variables</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="type" type="typeEnum" use="required"> + <xs:annotation> + <xs:documentation>Type of variable.</xs:documentation> + </xs:annotation> + </xs:attribute> + </xs:complexType> + + <xs:complexType name="doProto"> + <xs:annotation> + <xs:documentation>A Do Loop is similar to a While Loop except that the block of statements is executed at least once before the expression is checked.</xs:documentation> + </xs:annotation> + <xs:complexContent> + <xs:extension base="bodyProto"> + <xs:attribute name="expression" type="xs:string" use="required"> + <xs:annotation> + <xs:documentation>Conditional expression.</xs:documentation> + </xs:annotation> + </xs:attribute> + </xs:extension> + </xs:complexContent> + </xs:complexType> + + <xs:complexType name="forProto"> + <xs:annotation> + <xs:documentation>A For Loop increments or decrements a variable through a range of values. This is a common and useful replacement for a While Loop.</xs:documentation> + </xs:annotation> + <xs:complexContent> + <xs:extension base="bodyProto"> + <xs:attribute name="variable" type="xs:string" use="required"> + <xs:annotation> + <xs:documentation>Iteration variable.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="start" type="xs:string" use="required"> + <xs:annotation> + <xs:documentation>Start value.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="end" type="xs:string" use="required"> + <xs:annotation> + <xs:documentation>End value (inclusive).</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="direction" type="directionEnum" use="required"> + <xs:annotation> + <xs:documentation>Direction of iteration.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="step" type="xs:string" use="required"> + <xs:annotation> + <xs:documentation>Change of iteration variable (must be positive).</xs:documentation> + </xs:annotation> + </xs:attribute> + </xs:extension> + </xs:complexContent> + </xs:complexType> + + <xs:complexType name="ifProto"> + <xs:annotation> + <xs:documentation>An If Statement checks a Boolean expression then executes a true or false branch based on the result.</xs:documentation> + </xs:annotation> + <xs:sequence> + <xs:element name="then" minOccurs="1" maxOccurs="1" type="bodyProto"/> + <xs:element name="else" minOccurs="1" maxOccurs="1" type="bodyProto"/> + </xs:sequence> + <xs:attribute name="expression" type="xs:string" use="required"> + <xs:annotation> + <xs:documentation>Conditional expression.</xs:documentation> + </xs:annotation> + </xs:attribute> + </xs:complexType> + + <xs:complexType name="inputProto"> + <xs:annotation> + <xs:documentation>An Input Statement reads a value from the keyboard and stores the result in a variable.</xs:documentation> + </xs:annotation> + <xs:attribute name="variable" type="xs:string" use="required"> + <xs:annotation> + <xs:documentation>Variable name.</xs:documentation> + </xs:annotation> + </xs:attribute> + </xs:complexType> + + <xs:complexType name="outputProto"> + <xs:annotation> + <xs:documentation>An Output Statement evaluates an expression and then displays the result to the screen.</xs:documentation> + </xs:annotation> + <xs:attribute name="expression" type="xs:string" use="required"> + <xs:annotation> + <xs:documentation>Expression to output.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="newline" type="boolEnum" use="required"> + <xs:annotation> + <xs:documentation>Make a new line.</xs:documentation> + </xs:annotation> + </xs:attribute> + </xs:complexType> + + <xs:complexType name="whileProto"> + <xs:annotation> + <xs:documentation>A While Loop evaluates a Boolean expression and, if true, executes statements. It rechecks the expression and loops until it is false.</xs:documentation> + </xs:annotation> + <xs:complexContent> + <xs:extension base="bodyProto"> + <xs:attribute name="expression" type="xs:string" use="required"> + <xs:annotation> + <xs:documentation>Conditional expression.</xs:documentation> + </xs:annotation> + </xs:attribute> + </xs:extension> + </xs:complexContent> + </xs:complexType> + + <xs:complexType name="continueProto"> + <xs:annotation> + <xs:documentation>A Continue statement used in a cycle skips the rest of the loop's body and starts another iteration</xs:documentation> + </xs:annotation> + </xs:complexType> + + <xs:complexType name="breakProto"> + <xs:annotation> + <xs:documentation>A Break statement used in a cycle terminates the loop execution.</xs:documentation> + </xs:annotation> + </xs:complexType> + + <xs:simpleType name="attributeEnum"> + <xs:restriction base="xs:string"> + <xs:enumeration value="name" /> + <xs:enumeration value="authors" /> + <xs:enumeration value="about" /> + <xs:enumeration value="saved" /> + <xs:enumeration value="created" /> + <xs:enumeration value="edited" /> + </xs:restriction> + </xs:simpleType> + + <xs:simpleType name="typeEnum"> + <xs:restriction base="xs:string"> + <xs:enumeration value="Integer"/> + <xs:enumeration value="Real"/> + <xs:enumeration value="String"/> + <xs:enumeration value="Boolean"/> + <xs:enumeration value="Char"/> + <xs:enumeration value="[A-Z][a-zA-Z]*"/> + <xs:pattern value="(Integer|Real|String|Boolean|Char|[A-Z][a-zA-Z]*)(\[\])*((\[\])*)"/> + </xs:restriction> + </xs:simpleType> + + <xs:simpleType name="returntypeEnum"> + <xs:restriction base="xs:string"> + <xs:enumeration value="None"/> + <xs:enumeration value="Integer"/> + <xs:enumeration value="Real"/> + <xs:enumeration value="String"/> + <xs:enumeration value="Boolean"/> + <xs:enumeration value="Char"/> + <xs:enumeration value="[A-Z][a-zA-Z]*"/> + <xs:pattern value="(Integer|Real|String|Boolean|Char|[A-Z][a-zA-Z]*)(\[\])*((\[\])*)"/> + </xs:restriction> + </xs:simpleType> + + <xs:simpleType name="boolEnum"> + <xs:restriction base="xs:string"> + <xs:enumeration value="False"/> + <xs:enumeration value="True"/> + </xs:restriction> + </xs:simpleType> + + <xs:simpleType name="directionEnum"> + <xs:restriction base="xs:string"> + <xs:enumeration value="inc"/> + <xs:enumeration value="dec"/> + </xs:restriction> + </xs:simpleType> + +</xs:schema> \ No newline at end of file diff --git a/Core/test.fprg b/Core/test.fprg index 21dc6fcff198dbcd43d90d2849f63030660e85ae..1bdce3c8031accf42796a58bcb832955c2850ec4 100644 --- a/Core/test.fprg +++ b/Core/test.fprg @@ -21,14 +21,14 @@ <function name="a" type="Integer" variable="a"> <parameters/> <body> - <declare name="a" type="Integer" array="False" size=""/> + <declare name="a" type="Integer"/> <assign variable="a" expression="10"/> </body> </function> <function name="b" type="Integer" variable="b"> <parameters/> <body> - <declare name="b" type="Integer" array="False" size=""/> + <declare name="b" type="Integer"/> <assign variable="b" expression="5"/> </body> </function> @@ -45,4 +45,26 @@ </body> </function> </structure> + <structure name="Car"> + <parameters> + <parameter name="brand" type="String"/> + <parameter name="wheels" type="Integer"/> + </parameters> + <function name="setBrand" type="None" variable=""> + <parameters> + <parameter name="brand" type="String"/> + </parameters> + <body> + <assign variable="this.brand" expression="Audi"/> + </body> + </function> + <function name="setWheels" type="None" variable=""> + <parameters> + <parameter name="wheel" type="Integer"/> + </parameters> + <body> + <assign variable="this.wheels" expression="5"/> + </body> + </function> + </structure> </flowgorithm>