Ejemplo n.º 1
0
        public static ForStatementNode Parse(AstTreeNode lastNode, ScriptToken scriptToken, List <ScriptToken> tokens)
        {
            if (tokens[1].Type != EScriptTokenType.L_PAREN)
            {
                Console.WriteLine("Syntax error: Missing ('");
                return(null);
            }

            if (tokens[3].Type != EScriptTokenType.OF)
            {
                Console.WriteLine("Syntax error: Missing of");
                return(null);
            }

            tokens.RemoveAt(0); // consume for
            List <ScriptToken> loopDef      = ScriptTree.GetEnclosedTokens(tokens);
            ScriptToken        variableName = loopDef[0];

            loopDef.RemoveAt(0); // consume variable name
            loopDef.RemoveAt(0); // consume of
            AstTreeNode list  = ScriptTree.ProcessTokens(loopDef);
            AstTreeNode block = ScriptTree.ProcessTokens(ScriptTree.GetBlockTokens(tokens, EBlockType.BRACE, false)[0]);

            return(new ForStatementNode(
                       new LiteralNode <string>(variableName.Value),
                       list,
                       block
                       ));
        }
Ejemplo n.º 2
0
        public async Task TestGetEnclosedStatementTokens()
        {
            ScriptParser       parser = new ScriptParser();
            List <ScriptToken> tokens = parser.Tokenize("([1,2] + {1,2,3})");

            List <ScriptToken> enclosedTokens = ScriptTree.GetEnclosedTokens(tokens);

            Assert.Equal(EScriptTokenType.L_BRACKET, enclosedTokens[0].Type);
            Assert.Equal(EScriptTokenType.R_BRACKET, enclosedTokens[4].Type);

            Assert.Equal(EScriptTokenType.ADD, enclosedTokens[6].Type);

            Assert.Equal(EScriptTokenType.L_BRACE, enclosedTokens[8].Type);
            Assert.Equal(EScriptTokenType.R_BRACE, enclosedTokens[14].Type);
        }
        public static ArithmeticAssignmentNode Parse(AstTreeNode lastNode, ScriptToken scriptToken, List <ScriptToken> tokens)
        {
            if (lastNode == null || !(lastNode is IScopeMemberNode))
            {
                Console.WriteLine("Invalid assignment syntax.");
                return(null);
            }
            tokens.RemoveAt(0); // consume +=
            List <ScriptToken> assignmentTokens = ScriptTree.GetEnclosedTokens(tokens);

            return(new ArithmeticAssignmentNode(
                       (IScopeMemberNode)Convert.ChangeType(lastNode, lastNode is RootScopeMemberNode ? typeof(RootScopeMemberNode) : typeof(ScopeMemberNode)),
                       ScriptTree.ProcessTokens(assignmentTokens),
                       scriptToken.Type
                       ));
        }
Ejemplo n.º 4
0
        public static ArrayNode Parse(AstTreeNode lastNode, ScriptToken scriptToken, List <ScriptToken> tokens)
        {
            List <ScriptToken> values = ScriptTree.GetEnclosedTokens(tokens);
            List <AstTreeNode> nodes  = new List <AstTreeNode>();

            for (int i = 0; i < values.Count; i++)
            {
                ScriptToken arg = values[i];
                if (i % 2 == 0 && arg.Type != EScriptTokenType.COMMA)
                {
                    nodes.Add(new IntegerLiteralNode(arg.Value));
                }
                else
                {
                    Console.WriteLine("Syntax Error.");
                }
            }

            return(new ArrayNode(nodes));
        }
Ejemplo n.º 5
0
 public static ComparisonNode Parse(AstTreeNode lastNode, ScriptToken scriptToken, List <ScriptToken> tokens)
 {
     tokens.RemoveAt(0); // Remove comparison operator
     return(new ComparisonNode(lastNode, ScriptTree.ProcessTokens(ScriptTree.GetEnclosedTokens(tokens)), scriptToken.Type));
 }