public Conditional(Token conditionalType, Ast predicate, ScopeDeclr body, Conditional alternate = null) : this(conditionalType) { Predicate = predicate; Body = body; Alternate = alternate; }
public FuncInvoke(Token token, List<Ast> args) : base(token) { FunctionName = new Expr(token); Arguments = args; }
public VarDeclrAst(Token declType, Token name) : base(name) { DeclarationType = new Expr(declType); VariableName = new Expr(name); }
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; }
public WhileLoop(Token token) : base(token) { }
/// <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; }
public Ast(Token token) { Token = token; Children = new List<Ast>(); }
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; }
public ClassAst(Token token, ScopeDeclr body) : base(token) { Body = body; }
public Expr(Ast left, Token token, Ast right) : base(token) { Left = left; Right = right; }
public Expr(Token token) : base(token) { }
protected ArrayDeclrAst(Token token) : base(token) { IsArray = true; }
public ArrayDeclrAst(Token declType, Token name, Ast value) : base(declType, name, value) { IsArray = true; }
public Conditional(Token token) : base(token) { }
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; }