예제 #1
0
 public Conditional(Token conditionalType, Ast predicate, ScopeDeclr body, Conditional alternate = null)
     : this(conditionalType)
 {
     Predicate = predicate;
     Body = body;
     Alternate = alternate;
 }
예제 #2
0
        public FuncInvoke(Token token, List<Ast> args)
            : base(token)
        {
            FunctionName = new Expr(token);

            Arguments = args;
        }
예제 #3
0
        public VarDeclrAst(Token declType, Token name)
            : base(name)
        {
            DeclarationType = new Expr(declType);

            VariableName = new Expr(name);
        }
예제 #4
0
        public MethodDeclr(Token returnType, Token funcName, List<Ast> arguments, ScopeDeclr body, bool isAnon = false)
            : base(funcName)
        {
            MethodReturnType = new Expr(returnType);

            MethodName = new Expr(funcName);

            Arguments = arguments;

            Body = body;

            IsAnonymous = isAnon;
        }
예제 #5
0
 public WhileLoop(Token token)
     : base(token)
 {
 }
예제 #6
0
        /// <summary>
        /// Determines user type
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static IType GetExpressionType(Ast left, Ast right, Token token)
        {
            switch (token.TokenType)
            {
                case TokenType.Ampersand:
                case TokenType.Or:
                case TokenType.GreaterThan:
                case TokenType.LessThan:
                    return new BuiltInType(ExpressionTypes.Boolean);

                case TokenType.Infer:
                    return right.AstSymbolType;
            }

            if (left.AstSymbolType.ExpressionType != right.AstSymbolType.ExpressionType)
            {
                throw new Exception("Mismatched types");
            }

            return left.AstSymbolType;
        }
예제 #7
0
 public Ast(Token token)
 {
     Token = token;
     Children = new List<Ast>();
 }
예제 #8
0
 private bool IsValidVariableName(Token item)
 {
     switch (item.TokenType)
     {
         case TokenType.Word:
             return true;
     }
     return false;
 }
        /// <summary>
        /// Determines user type
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        private IType GetExpressionType(Ast left, Ast right, Token token)
        {
            switch (token.TokenType)
            {
                case TokenType.Ampersand:
                case TokenType.Or:
                case TokenType.GreaterThan:
                case TokenType.Compare:
                case TokenType.LessThan:
                case TokenType.NotCompare:
                    return new BuiltInType(ExpressionTypes.Boolean);

                case TokenType.Method:
                case TokenType.Infer:
                    if (right is MethodDeclr)
                    {
                        return new BuiltInType(ExpressionTypes.Method, right);
                    }

                    return right.AstSymbolType;
            }

            if (!ResolvingTypes && (left.AstSymbolType == null || right.AstSymbolType == null))
            {
                return null;
            }

            if (!TokenUtil.EqualOrPromotable(left.AstSymbolType.ExpressionType, right.AstSymbolType.ExpressionType))
            {
                throw new Exception("Mismatched types");
            }

            return left.AstSymbolType;
        }
예제 #10
0
 public ClassAst(Token token, ScopeDeclr body)
     : base(token)
 {
     Body = body;
 }
예제 #11
0
 public Expr(Ast left, Token token, Ast right)
     : base(token)
 {
     Left = left;
     Right = right;
 }
예제 #12
0
 public Expr(Token token)
     : base(token)
 {
 }
예제 #13
0
 protected ArrayDeclrAst(Token token)
     : base(token)
 {
     IsArray = true;
 }
예제 #14
0
 public ArrayDeclrAst(Token declType, Token name, Ast value)
     : base(declType, name, value)
 {
     IsArray = true;
 }
예제 #15
0
 public Conditional(Token token)
     : base(token)
 {
 }
예제 #16
0
 protected VarDeclrAst(Token token)
     : base(token)
 {
 }
        private LambdaDeclr CreateCurriedMethod(FuncInvoke ast, MethodSymbol functionType)
        {
            var srcMethod = functionType.MethodDeclr;

            var fixedAssignments = new List<VarDeclrAst>();

            var count = 0;
            foreach (var argValue in ast.Arguments)
            {
                var srcArg = srcMethod.Arguments[count] as VarDeclrAst;

                var token = new Token(srcArg.DeclarationType.Token.TokenType, argValue.Token.TokenValue);

                var declr = new VarDeclrAst(token, srcArg.Token, new Expr(argValue.Token));

                // if we're creating a curry using a variable then we need to resolve the variable type
                // otherwise we can make a symbol for the literal
                var newArgType = argValue.Token.TokenType == TokenType.Word ?
                                        ast.CurrentScope.Resolve(argValue).Type
                                    :   ScopeUtil.CreateSymbolType(argValue);

                // create a symbol type for the target we're invoking on so we can do type checking
                var targetArgType = ScopeUtil.CreateSymbolType(srcArg.DeclarationType);

                if (!TokenUtil.EqualOrPromotable(newArgType, targetArgType))
                {
                    throw new InvalidSyntax(String.Format("Cannot pass argument {0} of type {1} to partial function {2} as argument {3} of type {4}",
                        argValue.Token.TokenValue,
                        newArgType.TypeName,
                        srcMethod.MethodName.Token.TokenValue,
                        srcArg.VariableName.Token.TokenValue,
                        targetArgType.TypeName));
                }

                fixedAssignments.Add(declr);

                count++;
            }

            var newBody = fixedAssignments.Concat(srcMethod.Body.ScopedStatements).ToList();

            var curriedMethod = new LambdaDeclr(srcMethod.Arguments.Skip(ast.Arguments.Count).ToList(), new ScopeDeclr(newBody));

            SetScope(curriedMethod);

            return curriedMethod;
        }