Esempio n. 1
0
        private static void ParseNodeSetVariable(ScriptProgram scriptProgram, Node root, TokenStream stream)
        {
            var node = new SetVarNode();

            root.AddChildNode(node);

            string     name  = "";
            Expression value = null; // TODO This will be parsed as an expression
            string     scope = "";

            while (stream.GetCurrent().TokenType == SemanticTokenType.NodeParameter)
            {
                var parameter = stream.Pop();
                if (parameter.TokenValue == "name:")
                {
                    name = stream.Pop().TokenValue;
                }
                else if (parameter.TokenValue == "value:")
                {
                    value = ParseExpression(scriptProgram.GlobalVariables, stream);
                }
                else if (parameter.TokenValue == "scope:")
                {
                    scope = stream.Pop().TokenValue;
                }
                else
                {
                    throw new Exception("Unknown parameter:" + parameter.TokenValue);
                }
            }

            // TODO Add compile type checking for variable existance and scope
            node.expression = value;
            node.variableId = name;
        }
Esempio n. 2
0
        private static Node ConstuctNode(BinaryReader br, Guid id, NodeType nodeType, CommandType commandType)
        {
            //Console.WriteLine(nodeType);
            switch (nodeType)
            {
            case NodeType.Script:
            {
                var scriptNode = new ScriptNode();
                scriptNode.Id = id;
                scriptNode.readData(br);
                return(scriptNode);
            }

            case NodeType.Page:
            {
                var pageNode = new PageNode();
                pageNode.Id = id;
                pageNode.readData(br);
                return(pageNode);
            }

            case NodeType.OnceOnly:
            {
                var onceOnly = new OnceOnlyNode();
                onceOnly.Id = id;
                onceOnly.readData(br);
                return(onceOnly);
            }

            case NodeType.ConditionalTrue:
            {
                var node = new ConditionalTrueNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.ConditionalFalse:
            {
                var node = new ConditionalFalseNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.OptionsChoice:
            {
                var node = new ShowOptionsNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.Option:
            {
                var node = new OptionNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.ParallelNode:
            {
                var node = new ParallelNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.BlockNode:
            {
                var node = new BlockNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.ConditionalIf:
            {
                var node = new ConditionalExpressionNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.Command:
            {
                switch (commandType)
                {
                case CommandType.Say:
                {
                    var command = new SayNode();
                    command.Id = id;
                    command.readData(br);
                    return(command);
                }

                case CommandType.CallPage:
                {
                    var command = new CallPageNode();
                    command.Id = id;
                    command.readData(br);
                    return(command);
                }

                case CommandType.Return:
                {
                    var command = new ReturnNode();
                    command.Id = id;
                    command.readData(br);
                    return(command);
                }

                case CommandType.Wait:
                {
                    var command = new WaitNode();
                    command.Id = id;
                    command.readData(br);
                    return(command);
                }

                case CommandType.Print:
                {
                    var command = new PrintNode();
                    command.Id = id;
                    command.readData(br);
                    return(command);
                }

                case CommandType.SetVar:
                {
                    var command = new SetVarNode();
                    command.Id = id;
                    command.readData(br);
                    return(command);
                }

                default:
                    throw new Exception("Unhandled Node Type:" + nodeType + ":" + commandType);
                }
            }

            // case NodeType.Say
            default:
                throw new Exception("Unhandled Node Type:" + nodeType);
            }
            return(null);
        }