public AssignStatement(SymbolReference target, Expression value, SourcePosition start, SourcePosition end) : base(ASTNodeType.AssignStatement, start, end) { Target = target; Value = value; }
public InOpReference(InOpDeclaration op, Expression lhs, Expression rhs, SourcePosition start, SourcePosition end) : base(ASTNodeType.InOpRef, start, end) { Operator = op; LeftOperand = lhs; RightOperand = rhs; }
public ConditionalExpression(Expression cond, Expression first, Expression second, SourcePosition start, SourcePosition end) : base(ASTNodeType.ConditionalExpression, start, end) { Condition = cond; TrueExpression = first; FalseExpression = second; }
public WhileLoop(Expression cond, CodeBody body, SourcePosition start, SourcePosition end) : base(ASTNodeType.WhileLoop, start, end) { Condition = cond; Body = body; }
public ArraySymbolRef(Expression array, Expression index, SourcePosition start, SourcePosition end) : base(array, start, end) { Index = index; Type = ASTNodeType.ArrayReference; Array = array; }
public SwitchStatement(Expression expr, CodeBody body, SourcePosition start, SourcePosition end) : base(ASTNodeType.SwitchStatement, start, end) { Expression = expr; Body = body; }
public CompositeSymbolRef(Expression outer, Expression inner, SourcePosition start, SourcePosition end) : base(inner, start, end) { InnerSymbol = inner; OuterSymbol = outer; Type = ASTNodeType.CompositeReference; }
public IfStatement(Expression cond, CodeBody then, SourcePosition start, SourcePosition end, CodeBody optelse = null) : base(ASTNodeType.IfStatement, start, end) { Condition = cond; Then = then; Else = optelse; }
public ForLoop(Expression cond, CodeBody body, Statement init, Statement update, SourcePosition start, SourcePosition end) : base(ASTNodeType.WhileLoop, start, end) { Condition = cond; Body = body; Init = init; Update = update; }
public CastExpression(VariableType type, Expression expr, SourcePosition start, SourcePosition end) : base(ASTNodeType.CastExpression, start, end) { CastType = type; CastTarget = expr; }
public CaseStatement(Expression expr, SourcePosition start, SourcePosition end) : base(ASTNodeType.CaseStatement, start, end) { Value = expr; }
public Expression TryParseInOperator(Expression expr) { Func<ASTNode> inopParser = () => { Expression lhs, rhs, rhs2; VariableType lhsType, rhsType, rhs2Type; InOpDeclaration opA, opB; lhs = expr; lhsType = lhs.ResolveType(); var opA_tok = Tokens.ConsumeToken(CurrentTokenType); rhs = TryParseAtomicExpression(); if (rhs == null) return null; // error? rhsType = rhs.ResolveType(); if (!Symbols.GetInOperator(out opA, opA_tok.Value, lhsType, rhsType)) return Error("No operator '" + opA_tok + "' with operands of types '" + lhsType.Name + "' and '" + rhsType.Name + "' was found!", opA_tok.StartPosition, opA_tok.EndPosition); while (GlobalLists.ValidOperatorSymbols.Contains(CurrentTokenType)) { Tokens.PushSnapshot(); var opB_tok = Tokens.ConsumeToken(CurrentTokenType); rhs2 = TryParseAtomicExpression(); if (rhs == null) return Error("Expected a valid expression as the right hand side of the operator!", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)); rhs2Type = rhs2.ResolveType(); Tokens.PopSnapshot(); if (!Symbols.GetInOperator(out opB, opB_tok.Value, rhsType, rhs2Type)) return Error("No operator '" + opB_tok + "' with operands of types '" + rhsType.Name + "' and '" + rhs2Type.Name + "' was found!", opB_tok.StartPosition, opB_tok.EndPosition); if (opA.Precedence <= opB.Precedence) break; rhs = TryParseInOperator(rhs); } return new InOpReference(opA, lhs, rhs, lhs.StartPos, rhs.EndPos); }; return (Expression)Tokens.TryGetTree(inopParser); }
private CompositeSymbolRef TryParseCompositeRecursive(Expression expr) { Func<ASTNode> compositeParser = () => { Expression lhs, rhs; VariableType lhsType; lhs = expr; lhsType = lhs.ResolveType(); var token = Tokens.ConsumeToken(TokenType.Dot); if (token == null) return null; rhs = TryParseBasicRef(lhs) ?? TryParseFunctionCall() ?? (Expression)null; if (rhs == null) return Error("Expected a valid member name to follow the dot!", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)); if (!CompositeTypes.Contains(lhsType.NodeType)) return Error("Left side symbol is not of a composite type!", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)); while (CurrentTokenType == TokenType.Dot) { return TryParseCompositeRecursive(new CompositeSymbolRef(lhs, rhs, lhs.StartPos, rhs.EndPos)); } return new CompositeSymbolRef(lhs, rhs, lhs.StartPos, rhs.EndPos); }; return (CompositeSymbolRef)Tokens.TryGetTree(compositeParser); }
public Expression TryParseIfExpression(Expression expr) { Func<ASTNode> ifexprParser = () => { return null; // TODO }; return (Expression)Tokens.TryGetTree(ifexprParser); }
public SymbolReference TryParseBasicRef(Expression compositeOuter = null) { Func<ASTNode> refParser = () => { var token = Tokens.ConsumeToken(TokenType.Word); if (token == null) return null; ASTNode symbol = null; FunctionCall func = compositeOuter as FunctionCall; SymbolReference outer = compositeOuter as SymbolReference; if (func != null) { var containingClass = NodeUtils.GetContainingClass(func.ResolveType().Declaration); if (!Symbols.TryGetSymbolFromSpecificScope(token.Value, out symbol, containingClass.GetInheritanceString() + "." + func.Function.Name)) return Error("Left side has no member named '" + func.Function.Name + "'!", token.StartPosition, token.EndPosition); } else if (outer != null) { var containingClass = NodeUtils.GetContainingClass(outer.ResolveType().Declaration); if (!Symbols.TryGetSymbolFromSpecificScope(token.Value, out symbol, containingClass.GetInheritanceString() + "." + outer.ResolveType().Name)) return Error("Left side has no member named '" + outer.Name + "'!", token.StartPosition, token.EndPosition); } else { if (!Symbols.TryGetSymbol(token.Value, out symbol, NodeUtils.GetOuterClassScope(Node))) return Error("No symbol named '" + token.Value + "' exists in the current scope!", token.StartPosition, token.EndPosition); } return new SymbolReference(symbol, token.StartPosition, token.EndPosition, token.Value); }; return (SymbolReference)Tokens.TryGetTree(refParser); }
public PreOpReference(PreOpDeclaration op, Expression oper, SourcePosition start, SourcePosition end) : base(ASTNodeType.InOpRef, start, end) { Operator = op; Operand = oper; }
public ReturnStatement(SourcePosition start, SourcePosition end, Expression value = null) : base(ASTNodeType.ReturnStatement, start, end) { Value = value; }
public ForEachLoop(Expression iterator, CodeBody body, SourcePosition start, SourcePosition end) : base(ASTNodeType.ForEachLoop, start, end) { IteratorCall = iterator; Body = body; }