Exemple #1
0
        public override NodeLinkedList compile(ref LinkedListNode <Token> currentToken)
        {
            Token  valueToken = currentToken.Next.Next.Value;
            string valueName  = valueToken.value;

            //Compile left of +
            //var leftCompiled = CompilerFactory.Instance.CreateCompiledStatement(currentToken);

            currentToken = currentToken.Next.Next;
            try
            {
                CompiledStatement cs  = CompilerFactory.Instance.CreateCompiledStatement(currentToken);
                NodeLinkedList    nll = cs.compile(ref currentToken);
                Compiled.Add(nll);
            }
            catch
            {
                if (valueToken.type == TokenType.Number)
                {
                    Compiled.Add(new DirectFunctionCallNode(DirectFunctionCallNode.CONSTANTTORETURN, valueToken));
                }
                else if (valueToken.type == TokenType.Variable)
                {
                    Compiled.Add(new DirectFunctionCallNode(DirectFunctionCallNode.VARIABLETORETURN, valueName));
                }
                currentToken = currentToken.Next;
            }

            Compiled.Add(new FunctionCallNode("Print"));

            currentToken = currentToken.Next.Next;
            return(Compiled);
        }
Exemple #2
0
        public override NodeLinkedList compile(ref LinkedListNode <Token> currentToken)
        {
            Token  leftToken  = currentToken.Value;
            string leftName   = leftToken.value;
            Token  rightToken = currentToken.Next.Next.Value;
            string rightName  = rightToken.value;

            //Compile left of +
            //var leftCompiled = CompilerFactory.Instance.CreateCompiledStatement(currentToken);

            //simple assignment
            if (currentToken.Next.Next.Next.Value.type == TokenType.Endstatement)
            {
                //Temp variable for right
                if (rightToken.type == TokenType.Number)
                {
                    Compiled.Add(new DirectFunctionCallNode(DirectFunctionCallNode.CONSTANTTORETURN, rightToken));
                }
                else if (rightToken.type == TokenType.Variable)
                {
                    Compiled.Add(new DirectFunctionCallNode(DirectFunctionCallNode.VARIABLETORETURN, rightName));
                }
                currentToken = currentToken.Next.Next.Next.Next;
            }
            else
            {
                currentToken = currentToken.Next.Next;
                CompiledStatement cs  = CompilerFactory.Instance.CreateCompiledStatement(currentToken);
                NodeLinkedList    nll = cs.compile(ref currentToken);
                Compiled.Add(nll);
                currentToken = currentToken.Next;
            }
            Compiled.Add(new DirectFunctionCallNode(DirectFunctionCallNode.RETURNTOVARIABLE, leftName));
            return(Compiled);
        }