コード例 #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
ファイル: Ast.cs プロジェクト: smartnose/LanguageCreator
 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;
 }
コード例 #9
0
        /// <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
ファイル: ClassAst.cs プロジェクト: smartnose/LanguageCreator
 public ClassAst(Token token, ScopeDeclr body)
     : base(token)
 {
     Body = body;
 }
コード例 #11
0
ファイル: Expr.cs プロジェクト: smartnose/LanguageCreator
 public Expr(Ast left, Token token, Ast right)
     : base(token)
 {
     Left = left;
     Right = right;
 }
コード例 #12
0
ファイル: Expr.cs プロジェクト: smartnose/LanguageCreator
 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)
 {
 }
コード例 #17
0
        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;
        }