Exemplo n.º 1
0
        public IntegerLiteralExpression CreateIntegerLiteral(long value)
        {
            IntegerLiteralExpression integer = new IntegerLiteralExpression(value);

            integer.ExpressionType = _tss.LongType;
            return(integer);
        }
        public void FunctionCallFunction_UsingLocalReference_PassesCorrectFunctionNodeToFunctionFunction()
        {
            IntegerLiteralExpression functionLit = new IntegerLiteralExpression("1.0", 1, 1);
            List <ExpressionNode>    funcParams  = new List <ExpressionNode> {
                functionLit
            };
            FunctionCallExpression funcCallExpr = new FunctionCallExpression("test", funcParams, 1, 1);

            funcCallExpr.LocalReference   = 0;
            funcCallExpr.GlobalReferences = new List <int>();
            IInterpreterGeneric parent = Substitute.For <IInterpreterGeneric>();

            parent.Dispatch(funcParams[0], Arg.Any <List <object> >(), TypeEnum.Function).Returns((Object)1);
            GenericHelper   functionHelper = SetUpHelper(parent);
            List <TypeNode> typeNodes      = new List <TypeNode> {
                new TypeNode(TypeEnum.Function, 1, 1)
            };
            FunctionTypeNode funcTypeNode = new FunctionTypeNode(null, typeNodes, 1, 1);
            FunctionNode     funcNode     = new FunctionNode("", null, null, funcTypeNode, 1, 1);
            AST ast = new AST(new List <FunctionNode> {
                funcNode
            }, null, 1, 1);

            functionHelper.SetASTRoot(ast);
            FunctionNode res = null;

            parent.Function <Function>(Arg.Do <FunctionNode>(x => res = x), Arg.Any <List <object> >());

            functionHelper.FunctionCall <Function>(funcCallExpr, new List <object> {
                new Function(0)
            });

            res.Should().BeEquivalentTo(funcNode);
        }
 public TypeNode Dispatch(ExpressionNode node, List <TypeNode> parameterTypes)
 {
     return(node switch
     {
         IBinaryNumberOperator n => _numberHelper.VisitBinaryNumOp(n, parameterTypes),
         IBinaryBooleanOperator n => _booleanHelper.VisitBinaryBoolOp(n, parameterTypes),
         IBinarySetOperator n => _setHelper.VisitBinarySetOp(n, parameterTypes),
         SubsetExpression n => _setHelper.VisitSubset(n, parameterTypes),
         SetExpression n => _setHelper.VisitSet(n, parameterTypes),
         NotExpression n => _booleanHelper.VisitNot(n, parameterTypes),
         FunctionCallExpression n => _declarationHelper.VisitFunctionCall(n, parameterTypes),
         IdentifierExpression n => _declarationHelper.VisitIdentifier(n, parameterTypes),
         IntegerLiteralExpression _ => _declarationHelper.VisitIntegerLiteral(),
         RealLiteralExpression _ => _declarationHelper.VisitRealLiteral(),
         BooleanLiteralExpression _ => _declarationHelper.VisitBooleanLiteral(),
         StringLiteralExpression _ => _declarationHelper.VisitStringLiteral(),
         EmptySetLiteralExpression _ => _declarationHelper.VisitEmptySetLiteral(),
         AdditionExpression n => _commonOperatorHelper.VisitAddition(n, parameterTypes),
         SubtractionExpression n => _commonOperatorHelper.VisitSubtraction(n, parameterTypes),
         AbsoluteValueExpression n => _commonOperatorHelper.VisitAbsoluteValue(n, parameterTypes),
         IRelationOperator n => _commonOperatorHelper.VisitRelationalOperator(n, parameterTypes),
         IEquivalenceOperator n => _commonOperatorHelper.VisitEquivalenceOperator(n, parameterTypes),
         NegativeExpression n => _numberHelper.VisitNegative(n, parameterTypes),
         ElementExpression n => _commonOperatorHelper.VisitElement(n, parameterTypes),
         ISetGraphField n => _commonOperatorHelper.VisitISetGraphField(n, parameterTypes),
         IFunctionGraphField n => _commonOperatorHelper.VisitIFunctionGraphField(n, parameterTypes),
         GraphExpression n => _commonOperatorHelper.VisitGraph(n, parameterTypes),
         AnonymousFunctionExpression n => _declarationHelper.VisitAnonymousFunction(n, parameterTypes),
         _ => throw new UnimplementedTypeCheckerException(node, "Dispatch"),
     });
Exemplo n.º 4
0
        public void TestGlobalStmts1()
        {
            Boo.Lang.Ast.Module module = BooTestCaseUtil.ParseTestCase("global_stmts_1.boo");

            Block g = module.Globals;

            Assert.AreEqual(1, g.Statements.Count);

            ExpressionStatement        es  = (ExpressionStatement)g.Statements[0];
            MethodInvocationExpression mce = (MethodInvocationExpression)es.Expression;

            Assert.AreEqual(1, mce.Arguments.Count);

            BinaryExpression be = (BinaryExpression)mce.Arguments[0];

            Assert.AreEqual(BinaryOperatorType.Add, be.Operator);

            mce = (MethodInvocationExpression)be.Left;
            IntegerLiteralExpression ile = (IntegerLiteralExpression)mce.Arguments[0];

            Assert.AreEqual("3", ile.Value);

            mce = (MethodInvocationExpression)be.Right;
            ile = (IntegerLiteralExpression)mce.Arguments[0];
            Assert.AreEqual("5", ile.Value);
        }
        public static IExpression ParseExpression(ConsideredTokens consideredTokens, Action tweakTokens, out ParseError error)
        {
            error = null;
            switch (consideredTokens.Current.Type)
            {
            case TokenType.INT:
            {
                if (consideredTokens.Next.Type == TokenType.SEMICOLON)
                {
                    var expression = new IntegerLiteralExpression(consideredTokens.Current);
                    tweakTokens();
                    tweakTokens();
                    return(expression);
                }

                if (consideredTokens.Next.Type == TokenType.PLUS)
                {
                    return(ParseOperatorExpression(consideredTokens, tweakTokens, out error));
                }
            }
            break;

            default: throw new NotImplementedException();
            }
            throw new NotImplementedException();
        }
Exemplo n.º 6
0
        internal static IInterpreterElement GetIntepreterElementWithParamsOut(IntegerLiteralExpression child, int id, Action <List <object> > action)
        {
            var res = Substitute.For <IInterpreterElement>();

            res.DispatchInt(child, Arg.Do <List <object> >(x => action(x))).Returns(id);
            return(res);
        }
Exemplo n.º 7
0
 override public void OnIntegerLiteralExpression(IntegerLiteralExpression e)
 {
     Write(e.Value.ToString());
     if (e.IsLong)
     {
         Write("L");
     }
 }
Exemplo n.º 8
0
        public override void Switch(IAstTransformer transformer, out Node resultingNode)
        {
            IntegerLiteralExpression thisNode = (IntegerLiteralExpression)this;
            Expression resultingTypedNode     = thisNode;

            transformer.OnIntegerLiteralExpression(thisNode, ref resultingTypedNode);
            resultingNode = resultingTypedNode;
        }
        public static FunctionNode GetFunctionNode(string id)
        {
            IntegerLiteralExpression intLitExpr       = new IntegerLiteralExpression(0, 0, 0);
            ConditionNode            conditionNode    = GetConditionNode(intLitExpr);
            FunctionTypeNode         functionTypeNode = GetFunctionTypeNode();
            List <string>            paramIDs         = new List <string>();

            return(new FunctionNode(id, conditionNode, paramIDs, functionTypeNode, 0, 0));
        }
Exemplo n.º 10
0
        public override Expression Parse(Parser parser, Token token)
        {
            var integerLiteralExpression = new IntegerLiteralExpression {
                Value = int.Parse(token.Value)
            };

            parser.Consume();

            return(integerLiteralExpression);
        }
Exemplo n.º 11
0
        public void Export_2Doubles2Ints_2ndLastNode_Value()
        {
            string input = "export 5.5 + 33.3 + 2 + 1 {\"\"}";

            AST ast = new LexParser(new ASTBuilder(new ExpressionHelper())).Run(input, false);

            IntegerLiteralExpression node = (IntegerLiteralExpression)ast.Exports[0].ExportValue.Children[0].Children[1];

            Assert.AreEqual(2, node.Value);
        }
Exemplo n.º 12
0
 public override void OnIntegerLiteralExpression(IntegerLiteralExpression node)
 {
     if (node.IsLong || node.Value < int.MinValue || node.Value > int.MaxValue)
     {
         _expression = new CodePrimitiveExpression(node.Value);
     }
     else
     {
         _expression = new CodePrimitiveExpression((int)node.Value);
     }
 }
Exemplo n.º 13
0
 public override void OnIntegerLiteralExpression(IntegerLiteralExpression node)
 {
     if (node.IsLong)
     {
         MakeLiteralResult("System.Int64");
     }
     else
     {
         MakeResult(projectContent.SystemTypes.Int32);
     }
 }
Exemplo n.º 14
0
        public void LiteralInteger_GivenInteger_ReturnsIntegerLiteral(int input, int expected)
        {
            IntegerLiteralExpression intLit = new IntegerLiteralExpression(input.ToString(), 1, 1);
            IInterpreterInteger      parent = Substitute.For <IInterpreterInteger>();

            parent.DispatchInt(intLit, Arg.Any <List <object> >()).Returns(input);
            IntegerHelper integerHelper = SetUpHelper(parent);

            int res = integerHelper.LiteralInteger(intLit, new List <object>());

            Assert.AreEqual(expected, res);
        }
        private List <BoundNode> GetBounds()
        {
            ExpressionNode   smallest = new IntegerLiteralExpression("0", 0, 0);
            ExpressionNode   largest  = new IntegerLiteralExpression("5", 0, 0);
            BoundNode        node1    = new BoundNode("i", smallest, largest, 0, 0);
            List <BoundNode> bounds   = new List <BoundNode>()
            {
                node1
            };

            return(bounds);
        }
        void ExpandComplexArraySlicing(SlicingExpression node)
        {
            if (node.Indices.Count > 1)
            {
                MethodInvocationExpression mie = null;
                var computeEnd = new ArrayLiteralExpression();
                var collapse   = new ArrayLiteralExpression();
                var ranges     = new ArrayLiteralExpression();
                for (int i = 0; i < node.Indices.Count; i++)
                {
                    ranges.Items.Add(node.Indices[i].Begin);
                    if (node.Indices[i].End == null)
                    {
                        var end = new BinaryExpression(BinaryOperatorType.Addition, node.Indices[i].Begin, new IntegerLiteralExpression(1));
                        ranges.Items.Add(end);
                        BindExpressionType(end, GetExpressionType(node.Indices[i].Begin));
                        computeEnd.Items.Add(new BoolLiteralExpression(false));
                        collapse.Items.Add(new BoolLiteralExpression(true));
                    }
                    else if (node.Indices[i].End == OmittedExpression.Default)
                    {
                        var end = new IntegerLiteralExpression(0);
                        ranges.Items.Add(end);
                        BindExpressionType(end, GetExpressionType(node.Indices[i].Begin));
                        computeEnd.Items.Add(new BoolLiteralExpression(true));
                        collapse.Items.Add(new BoolLiteralExpression(false));
                    }
                    else
                    {
                        ranges.Items.Add(node.Indices[i].End);
                        computeEnd.Items.Add(new BoolLiteralExpression(false));
                        collapse.Items.Add(new BoolLiteralExpression(false));
                    }
                }
                mie = CodeBuilder.CreateMethodInvocation(MethodCache.RuntimeServices_GetMultiDimensionalRange1, node.Target, ranges);
                mie.Arguments.Add(computeEnd);
                mie.Arguments.Add(collapse);

                BindExpressionType(ranges, TypeSystemServices.Map(typeof(int[])));
                BindExpressionType(computeEnd, TypeSystemServices.Map(typeof(bool[])));
                BindExpressionType(collapse, TypeSystemServices.Map(typeof(bool[])));
                node.ParentNode.Replace(node, mie);
            }
            else
            {
                var slice = node.Indices[0];
                var mie   = IsNullOrOmitted(slice.End)
                                        ? CodeBuilder.CreateMethodInvocation(MethodCache.RuntimeServices_GetRange1, node.Target, slice.Begin)
                                        : CodeBuilder.CreateMethodInvocation(MethodCache.RuntimeServices_GetRange2, node.Target, slice.Begin, slice.End);
                node.ParentNode.Replace(node, mie);
            }
        }
Exemplo n.º 17
0
        public void PowerInteger_TwoIntsButNegativeExponent_ThrowsException(int input1, int input2)
        {
            IntegerLiteralExpression realLit1 = new IntegerLiteralExpression(input1, 1, 1);
            IntegerLiteralExpression realLit2 = new IntegerLiteralExpression(input2, 2, 2);
            PowerExpression          powExpr  = new PowerExpression(realLit1, realLit2, 1, 1);
            IInterpreterInteger      parent   = Substitute.For <IInterpreterInteger>();

            parent.DispatchInt(realLit1, Arg.Any <List <object> >()).Returns(input1);
            parent.DispatchInt(realLit2, Arg.Any <List <object> >()).Returns(input2);
            IntegerHelper realHelper = SetUpHelper(parent);

            int res = realHelper.PowerInteger(powExpr, new List <object>());
        }
Exemplo n.º 18
0
        public void UnaryMinus()
        {
            string                   arg_58_0                 = "-42";
            UnaryExpression          unaryExpression          = new UnaryExpression(LexicalInfo.Empty);
            UnaryOperatorType        unaryOperatorType        = unaryExpression.Operator = UnaryOperatorType.UnaryNegation;
            UnaryExpression          arg_4F_0                 = unaryExpression;
            IntegerLiteralExpression integerLiteralExpression = new IntegerLiteralExpression(LexicalInfo.Empty);
            long       num        = integerLiteralExpression.Value = 42L;
            bool       flag       = integerLiteralExpression.IsLong = false;
            Expression expression = arg_4F_0.Operand = integerLiteralExpression;

            CSharpAssertModule.AssertCSharpCode(arg_58_0, unaryExpression);
        }
Exemplo n.º 19
0
 override public void LeaveUnaryExpression(UnaryExpression node)
 {
     if (UnaryOperatorType.UnaryNegation == node.Operator)
     {
         if (NodeType.IntegerLiteralExpression == node.Operand.NodeType)
         {
             IntegerLiteralExpression integer = (IntegerLiteralExpression)node.Operand;
             integer.Value      *= -1;
             integer.LexicalInfo = node.LexicalInfo;
             ReplaceCurrentNode(integer);
         }
     }
 }
Exemplo n.º 20
0
        public override void OnExpressionStatement(ExpressionStatement node)
        {
            base.OnExpressionStatement(node);

            IntegerLiteralExpression literal = node.Expression as IntegerLiteralExpression;

            if (null == literal)
            {
                return;
            }

            AssertLiteralInRange(literal, GetExpressionType(literal));
        }
Exemplo n.º 21
0
        public void AbsoluteInteger_Integer_ReturnsAbsoluteValue(int input, int expected)
        {
            IntegerLiteralExpression intLit  = new IntegerLiteralExpression(input.ToString(), 1, 1);
            AbsoluteValueExpression  absExpr = new AbsoluteValueExpression(intLit, 1, 1);

            absExpr.Type = TypeEnum.Integer;
            IInterpreterInteger parent = Substitute.For <IInterpreterInteger>();

            parent.DispatchInt(intLit, Arg.Any <List <object> >()).Returns(input);
            IntegerHelper integerHelper = SetUpHelper(parent);

            int res = integerHelper.AbsoluteInteger(absExpr, new List <object>());

            Assert.AreEqual(expected, res);
        }
Exemplo n.º 22
0
        public void MultiplicationInteger_TwoIntegers_ReturnsCorrectResultOfMultiplication(int input1, int input2, int expected)
        {
            IntegerLiteralExpression intLit1  = new IntegerLiteralExpression(input1.ToString(), 1, 1);
            IntegerLiteralExpression intLit2  = new IntegerLiteralExpression(input2.ToString(), 2, 2);
            MultiplicationExpression multExpr = new MultiplicationExpression(intLit1, intLit2, 1, 1);
            IInterpreterInteger      parent   = Substitute.For <IInterpreterInteger>();

            parent.DispatchInt(intLit1, Arg.Any <List <object> >()).Returns(input1);
            parent.DispatchInt(intLit2, Arg.Any <List <object> >()).Returns(input2);
            IntegerHelper integerHelper = SetUpHelper(parent);

            int res = integerHelper.MultiplicationInteger(multExpr, new List <object>());

            Assert.AreEqual(expected, res);
        }
Exemplo n.º 23
0
        public void PowerInteger_TwoInts_ReturnsCorrectResult(int input1, int input2, int expected)
        {
            IntegerLiteralExpression realLit1 = new IntegerLiteralExpression(input1, 1, 1);
            IntegerLiteralExpression realLit2 = new IntegerLiteralExpression(input2, 2, 2);
            PowerExpression          powExpr  = new PowerExpression(realLit1, realLit2, 1, 1);
            IInterpreterInteger      parent   = Substitute.For <IInterpreterInteger>();

            parent.DispatchInt(realLit1, Arg.Any <List <object> >()).Returns(input1);
            parent.DispatchInt(realLit2, Arg.Any <List <object> >()).Returns(input2);
            IntegerHelper realHelper = SetUpHelper(parent);

            int res = realHelper.PowerInteger(powExpr, new List <object>());

            Assert.AreEqual(expected, res);
        }
        private List <BoundNode> GetBounds(IInterpreterSet parent, List <int> minValues, List <int> maxValues)
        {
            List <BoundNode> bounds = new List <BoundNode>();

            for (int i = 0; i < minValues.Count; i++)
            {
                IntegerLiteralExpression min = new IntegerLiteralExpression(minValues[i], 0, 0);
                IntegerLiteralExpression max = new IntegerLiteralExpression(maxValues[i], 0, 0);
                bounds.Add(new BoundNode(null, min, max, 0, 0));

                parent.DispatchInt(min, Arg.Any <List <object> >()).Returns(minValues[i]);
                parent.DispatchInt(max, Arg.Any <List <object> >()).Returns(maxValues[i]);
            }

            return(bounds);
        }
Exemplo n.º 25
0
        public void Dispatch_IntegerLiteralAndObjectListAndIntegerType_CorrectListPassed()
        {
            List <Object> expected = new List <Object>()
            {
                23, 2.334, null
            };
            IntegerLiteralExpression input1  = new IntegerLiteralExpression("", 0, 0);
            IIntegerHelper           ihelper = Substitute.For <IIntegerHelper>();
            Interpreter   interpreter        = Utilities.GetIntepreterOnlyWith(ihelper);
            List <Object> res = null;

            ihelper.LiteralInteger(Arg.Any <IntegerLiteralExpression>(), Arg.Do <List <Object> >(x => res = x));

            interpreter.Dispatch(input1, expected, TypeEnum.Integer);

            res.Should().BeEquivalentTo(expected);
        }
Exemplo n.º 26
0
        public void Dispatch_IntegerLiteralAndObjectListAndIntegerType_CorrectValueReturned()
        {
            int expected = 17;
            IntegerLiteralExpression input1 = new IntegerLiteralExpression("", 0, 0);
            List <Object>            input2 = new List <Object>()
            {
                23, 2.334, null
            };
            IIntegerHelper ihelper     = Substitute.For <IIntegerHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(ihelper);

            ihelper.LiteralInteger(Arg.Any <IntegerLiteralExpression>(), Arg.Any <List <Object> >()).Returns(expected);

            int res = (int)interpreter.Dispatch(input1, input2, TypeEnum.Integer);

            Assert.AreEqual(expected, res);
        }
Exemplo n.º 27
0
        public void NegativeInteger_Integer_CorrectNegativeValue(int input, int expected)
        {
            IntegerLiteralExpression intLitExpr = new IntegerLiteralExpression(input, 0, 0);

            NegativeExpression negExpr = new NegativeExpression(new List <ExpressionNode>()
            {
                intLitExpr
            }, 0, 0);

            IInterpreterInteger parent = Substitute.For <IInterpreterInteger>();

            parent.DispatchInt(intLitExpr, Arg.Any <List <object> >()).Returns(input);
            IntegerHelper integerHelper = SetUpHelper(parent);

            double res = integerHelper.NegativeInteger(negExpr, new List <object>());

            Assert.AreEqual(expected, res);
        }
        public void DispatchInteger_IntegerLiteralAndObjectList_CorrectIntegerLiteralExprPassed()
        {
            IntegerLiteralExpression expected = new IntegerLiteralExpression("", 0, 0);
            IntegerLiteralExpression input1   = expected;
            List <Object>            input2   = new List <Object>()
            {
                23, 2.334, null
            };
            IIntegerHelper           ihelper     = Substitute.For <IIntegerHelper>();
            Interpreter              interpreter = Utilities.GetIntepreterOnlyWith(ihelper);
            IntegerLiteralExpression res         = null;

            ihelper.LiteralInteger(Arg.Do <IntegerLiteralExpression>(x => res = x), Arg.Any <List <Object> >());

            interpreter.DispatchInt(input1, input2);

            res.Should().BeEquivalentTo(expected);
        }
Exemplo n.º 29
0
        void AssertLiteralInRange(IntegerLiteralExpression literal, IType type)
        {
            bool ok = true;

            if (type == TypeSystemServices.ByteType)
            {
                ok = (literal.Value >= byte.MinValue && literal.Value <= byte.MaxValue);
            }
            else if (type == TypeSystemServices.SByteType)
            {
                ok = (literal.Value >= sbyte.MinValue && literal.Value <= sbyte.MaxValue);
            }
            else if (type == TypeSystemServices.ShortType)
            {
                ok = (literal.Value >= short.MinValue && literal.Value <= short.MaxValue);
            }
            else if (type == TypeSystemServices.UShortType)
            {
                ok = (literal.Value >= ushort.MinValue && literal.Value <= ushort.MaxValue);
            }
            else if (type == TypeSystemServices.IntType)
            {
                ok = (literal.Value >= int.MinValue && literal.Value <= int.MaxValue);
            }
            else if (type == TypeSystemServices.UIntType)
            {
                ok = (literal.Value >= uint.MinValue && literal.Value <= uint.MaxValue);
            }
            else if (type == TypeSystemServices.LongType)
            {
                ok = (literal.Value >= long.MinValue && literal.Value <= long.MaxValue);
            }

            if (!ok)
            {
                Error(CompilerErrorFactory.ConstantCannotBeConverted(literal, type));
            }
        }
Exemplo n.º 30
0
			protected internal override void VisitIntegerLiteralExpression(IntegerLiteralExpression expression)
			{
				_writer.Append("{0}", expression.Value.ToString(CultureInfo.InvariantCulture));
			}
Exemplo n.º 31
0
		public EnumMember(LexicalInfo token, IntegerLiteralExpression initializer) : base(token)
		{
			this.Initializer = initializer;
		}
Exemplo n.º 32
0
			protected internal override void VisitIntegerLiteralExpression(IntegerLiteralExpression expression)
			{
				_expr = Ssm.Expr.NewIntExpr(expression.Value);
			}
Exemplo n.º 33
0
 public virtual void Visit(IntegerLiteralExpression node)
 {
     DefaultVisit(node);
 }
Exemplo n.º 34
0
		/// <summary>
		///     Visits an element of type <see cref="IntegerLiteralExpression" />.
		/// </summary>
		/// <param name="expression">The <see cref="IntegerLiteralExpression" /> instance that should be visited.</param>
		protected internal virtual void VisitIntegerLiteralExpression(IntegerLiteralExpression expression)
		{
			DefaultVisit(expression);
		}
Exemplo n.º 35
0
 public virtual void Visit(IntegerLiteralExpression node)
 {
 }
Exemplo n.º 36
0
 public override void OnIntegerLiteralExpression(IntegerLiteralExpression e)
 {
     Write(e.Value.ToString());
 }
Exemplo n.º 37
0
		public EnumMember(IntegerLiteralExpression initializer)
		{
			this.Initializer = initializer;
		}
Exemplo n.º 38
0
        /// <summary>
        /// Parses a simple expression (no function calls on top-level expression.
        /// </summary>
        public static bool AcceptAtom(string Text, int Start, out Expression Expression, out int LastChar)
        {
            // Procedure
            if (AcceptString(Text, Start, "{", out LastChar))
            {
                ProcedureExpression procedure;
                AcceptWhitespace(Text, LastChar, out LastChar);
                AcceptProcedure(Text, LastChar, out procedure, out LastChar);
                AcceptWhitespace(Text, LastChar, out LastChar);
                if (AcceptString(Text, LastChar, "}", out LastChar))
                {
                    Expression = procedure;
                    return true;
                }
            }

            // Variable
            Operator op;
            string varname;
            if (AcceptWord(Text, Start, out varname, out LastChar) && ValidVariable(varname) && !LookupOperator(varname, out op))
            {
                Expression = new VariableExpression(varname);
                return true;
            }

            // Parentheses
            if (AcceptString(Text, Start, "(", out LastChar))
            {
                // Operator
                int nc = LastChar;
                if (AcceptWord(Text, nc, out varname, out LastChar) && LookupOperator(varname, out op))
                {
                    if (AcceptString(Text, LastChar, ")", out LastChar))
                    {
                        Expression = new VariableExpression(varname);
                        return true;
                    }
                }

                Expression exp;
                AcceptWhitespace(Text, nc, out LastChar);
                if (AcceptExpression(Text, LastChar, out exp, out LastChar))
                {
                    AcceptWhitespace(Text, LastChar, out LastChar);
                    if (AcceptString(Text, LastChar, ")", out LastChar))
                    {
                        Expression = exp;
                        return true;
                    }
                }
            }

            // Integer literal
            long val;
            if (AcceptIntegerLiteral(Text, Start, out val, out LastChar))
            {
                Expression = new IntegerLiteralExpression(val);
                return true;
            }

            // Alternate lambda syntax
            if (AcceptString(Text, Start, "function", out LastChar))
            {
                AcceptWhitespace(Text, LastChar, out LastChar);
                if (AcceptString(Text, LastChar, "(", out LastChar))
                {
                    AcceptWhitespace(Text, LastChar, out LastChar);
                    List<KeyValuePair<Expression, string>> arglist;
                    AcceptArgumentList(Text, LastChar, out arglist, out LastChar);
                    AcceptWhitespace(Text, LastChar, out LastChar);
                    if (AcceptString(Text, LastChar, ")", out LastChar))
                    {
                        AcceptWhitespace(Text, LastChar, out LastChar);
                        if (AcceptString(Text, LastChar, "{", out LastChar))
                        {
                            ProcedureExpression procedure;
                            AcceptWhitespace(Text, LastChar, out LastChar);
                            AcceptProcedure(Text, LastChar, out procedure, out LastChar);
                            AcceptWhitespace(Text, LastChar, out LastChar);
                            if (AcceptString(Text, LastChar, "}", out LastChar))
                            {
                                Expression = new FunctionDefineExpression(arglist, procedure);
                                return true;
                            }
                        }
                    }
                }
            }

            // Function type
            if (AcceptString(Text, Start, "<", out LastChar))
            {
                AcceptWhitespace(Text, LastChar, out LastChar);
                List<KeyValuePair<Expression, string>> argtypelist;
                AcceptArgumentList(Text, LastChar, out argtypelist, out LastChar);
                AcceptWhitespace(Text, LastChar, out LastChar);
                if (AcceptString(Text, LastChar, ">", out LastChar))
                {
                    AcceptWhitespace(Text, LastChar, out LastChar);
                    Expression returntype;
                    if (AcceptTightExpression(Text, LastChar, out returntype, out LastChar))
                    {
                        Expression = new FunctionTypeExpression(argtypelist, returntype);
                        return true;
                    }
                }
            }

            Expression = null;
            return false;
        }