コード例 #1
0
 //sub compile method OLD
 public virtual Token compile(Token currentToken, Token endToken, NodeLinkedList nodeList, Node before)
 {
     while (currentToken != null)
     {
         currentToken = CompilerFactory.getInstance().getCompiler(currentToken).compile(currentToken, endToken, nodeList, before);
     }
     return(null);
 }
コード例 #2
0
        //Initial compile method
        public NodeLinkedList compile(List <Token> tokens)
        {
            Token nextToken = tokens.First();

            while (nextToken != null)
            {
                Compiler compilerType = CompilerFactory.getInstance().getCompiler(nextToken);
                nextToken = compilerType.compile(nextToken, null, compiledNodes, null);
                //Console.WriteLine(compiledNodes); // Already get printed in the methods. So not needed here anymore.
            }
            print();
            return(compiledNodes);
        }
コード例 #3
0
        public override Token compile(Token currentToken, Token lastToken, NodeLinkedList nodeLinkedList, Node before)
        {
            int level = currentToken.level;

            if (before != null)
            {
                before.insertPrevious(firstNodeDoNothing);
            }
            else
            {
                nodeLinkedList.insertBefore(before, firstNodeDoNothing);
            }

            List <TokenExpected> expected = new List <TokenExpected>();

            expected.Add(new TokenExpected(level, TokenType.IfStatement));
            expected.Add(new TokenExpected(level, TokenType.EllipsisOpen));
            expected.Add(new TokenExpected(level + 1, TokenType.ANY));
            expected.Add(new TokenExpected(level, TokenType.EllipsisClose));
            expected.Add(new TokenExpected(level, TokenType.BracketsOpen));
            expected.Add(new TokenExpected(level + 1, TokenType.ANY));
            expected.Add(new TokenExpected(level, TokenType.BracketsClose));

            foreach (TokenExpected expt in expected)
            {
                // If no currentToken anymore, return null to get out of the compiler loop
                if (currentToken == null)
                {
                    return(null);
                }

                if (expt.level == level)
                {
                    if (currentToken.tokenType != expt.tokenType)
                    {
                        if (expt.tokenType != currentToken.tokenType)
                        {
                            if (expt.tokenType == TokenType.BracketsOpen ||
                                (expt.tokenType == TokenType.BracketsClose && openedBracket))
                            {
                                openedBracket = false;
                            }
                            else
                            {
                                throw new Exception_UnexpectedEnd("#CP0001 :: Unexpected end of statement.");
                            }
                        }
                    }
                    else
                    {
                        currentToken = currentToken.nextToken;
                    }
                }
                else if (expt.level >= level)
                {
                    if (compileCondition == null)
                    {
                        compileCondition = new CompileCondition();
                        currentToken     = compileCondition.compile(currentToken, lastToken, nodeLinkedList, conditionalJump);
                    }
                    else
                    {
                        while (currentToken.tokenType != TokenType.BracketsClose && currentToken.tokenType != TokenType.EllipsisClose)
                        {
                            compileStatement = CompilerFactory.getInstance().getCompiler(currentToken);
                            currentToken     = compileStatement.compile(currentToken, lastToken, nodeLinkedList, falseNodeDoNothing);
                        }
                    }
                }
            }

            return(currentToken);
        }