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); //Temp variable for left if (leftToken.type == TokenType.Number) { leftName = CompiledStatement.getUniqueId(); Compiled.Add(new DirectFunctionCallNode(DirectFunctionCallNode.CONSTANTTORETURN, leftToken)); Compiled.Add(new DirectFunctionCallNode(DirectFunctionCallNode.RETURNTOVARIABLE, leftName)); } //Temp variable for right if (rightToken.type == TokenType.Number) { rightName = CompiledStatement.getUniqueId(); Compiled.Add(new DirectFunctionCallNode(DirectFunctionCallNode.CONSTANTTORETURN, rightToken)); Compiled.Add(new DirectFunctionCallNode(DirectFunctionCallNode.RETURNTOVARIABLE, rightName)); } currentToken = currentToken.Next; if (currentToken.Value.type == TokenType.Multiply) { Compiled.Add(new FunctionCallNode("Multiply", leftName, rightName)); } currentToken = currentToken.Next.Next; return(Compiled); }
public override NodeLinkedList compile(ref LinkedListNode <Token> currentToken) { Token leftToken = currentToken.Value; string leftName = leftToken.value; currentToken = currentToken.Next; Token operatorToken = currentToken.Value; currentToken = currentToken.Next; Token rightToken = currentToken.Value; string rightName = rightToken.value; if (leftToken.type == TokenType.Number) { leftName = CompiledStatement.getUniqueId(); Compiled.Add(new DirectFunctionCallNode("ConstantToReturn", leftToken.value)); Compiled.Add(new DirectFunctionCallNode("ReturnToVariable", leftName)); } if (rightToken.type == TokenType.Number) { rightName = CompiledStatement.getUniqueId(); Compiled.Add(new DirectFunctionCallNode("ConstantToReturn", leftToken.value)); Compiled.Add(new DirectFunctionCallNode("ReturnToVariable", rightName)); } switch (operatorToken.type) { case TokenType.Equals: Compiled.Add(new FunctionCallNode("AreEqual", leftName, rightName)); break; case TokenType.SmallerThan: Compiled.Add(new FunctionCallNode("IsSmaller", leftName, rightName)); break; case TokenType.Largerthan: Compiled.Add(new FunctionCallNode("IsLarger", leftName, rightName)); break; case TokenType.SmallerOrEqualThan: Compiled.Add(new FunctionCallNode("IsSmallerOrEqual", leftName, rightName)); break; case TokenType.LargerOrEqualThan: Compiled.Add(new FunctionCallNode("IsLargerOrEqual", leftName, rightName)); break; default: break; } currentToken = currentToken.Next; return(Compiled); }