public void AddExecutionNode(ExecutionNode node)
        {
            if (executionNodes.ContainsKey(node.ID))
            {
                throw new InvalidOperationException(string.Format("AddExecutionNode: ExecutionTree already contains a node with ID `{0}`.", node.ID));
            }

            executionNodes.Add(node.ID, node);
        }
Exemple #2
0
        public void AddExecutionNode(ExecutionNode node)
        {
            if (executionNodes.ContainsKey(node.ID))
            {
                throw new InvalidOperationException(string.Format("AddExecutionNode: ExecutionTree already contains a node with ID `{0}`.", node.ID));
            }

            executionNodes.Add(node.ID, node);
        }
Exemple #3
0
        public HrmpProgram Parse(string filepath)
        {
            HrmpProgram program = null;

            using (StreamReader file = new StreamReader(filepath))
            {
                string      lastLabel   = null;
                CommandList commandList = new CommandList();

                string line;
                while ((line = file.ReadLine()) != null)
                {
                    ICommand command = ParseLine(line);
                    if (command == null)
                    {
                        // Not a command, check if it is a label for a jump.
                        if (line.EndsWith(":"))
                        {
                            // If there was a previous label, save the current commandList to that ExecutionNode.
                            if (lastLabel != null && program != null)
                            {
                                ExecutionNode en = new ExecutionNode(lastLabel, commandList);
                                program.AddExecutionNode(en);
                            }
                            // Else, create the main ExecutionNode and create the HrmpProgram.
                            else
                            {
                                ExecutionNode en = new ExecutionNode("main", commandList);
                                program = new HrmpProgram(en);
                            }

                            // Clear the current commandList.
                            commandList.Clear();

                            // Save the label for the next ExecutionNode.
                            line      = line.Remove(line.Count() - 1);
                            lastLabel = line;
                        }

                        continue;
                    }
                    // Else, it is a command.
                    else
                    {
                        commandList.Add(command);
                    }
                }

                // End of file, so add the current commandList.
                // If there was a previous label, save the current commandList to that ExecutionNode.
                if (lastLabel != null && program != null)
                {
                    ExecutionNode en = new ExecutionNode(lastLabel, commandList);
                    program.AddExecutionNode(en);
                }
                // Else, create the main ExecutionNode and create the HrmpProgram.
                else
                {
                    ExecutionNode en = new ExecutionNode("main", commandList);
                    program = new HrmpProgram(en);
                }

                file.Close();
            }

            return(program);
        }
        public HrmpProgram Parse(string filepath)
        {
            HrmpProgram program = null;

            using (StreamReader file = new StreamReader(filepath))
            {
                string lastLabel = null;
                CommandList commandList = new CommandList();

                string line;
                while ((line = file.ReadLine()) != null)
                {
                    ICommand command = ParseLine(line);
                    if (command == null)
                    {
                        // Not a command, check if it is a label for a jump.
                        if (line.EndsWith(":"))
                        {
                            // If there was a previous label, save the current commandList to that ExecutionNode.
                            if (lastLabel != null && program != null)
                            {
                                ExecutionNode en = new ExecutionNode(lastLabel, commandList);
                                program.AddExecutionNode(en);
                            }
                            // Else, create the main ExecutionNode and create the HrmpProgram.
                            else
                            {
                                ExecutionNode en = new ExecutionNode("main", commandList);
                                program = new HrmpProgram(en);
                            }

                            // Clear the current commandList.
                            commandList.Clear();

                            // Save the label for the next ExecutionNode.
                            line = line.Remove(line.Count() - 1);
                            lastLabel = line;
                        }

                        continue;
                    }
                    // Else, it is a command.
                    else
                    {
                        commandList.Add(command);
                    }
                }

                // End of file, so add the current commandList.
                // If there was a previous label, save the current commandList to that ExecutionNode.
                if (lastLabel != null && program != null)
                {
                    ExecutionNode en = new ExecutionNode(lastLabel, commandList);
                    program.AddExecutionNode(en);
                }
                // Else, create the main ExecutionNode and create the HrmpProgram.
                else
                {
                    ExecutionNode en = new ExecutionNode("main", commandList);
                    program = new HrmpProgram(en);
                }

                file.Close();
            }

            return program;
        }
 public HrmpProgram(ExecutionNode startNode)
 {
     this.startNode = startNode;
     executionNodes = new ExecutionNodes();
 }
Exemple #6
0
 public HrmpProgram(ExecutionNode startNode)
 {
     this.startNode = startNode;
     executionNodes = new ExecutionNodes();
 }