示例#1
0
 public AssignStatement(SymbolReference target, Expression value,
     SourcePosition start, SourcePosition end)
     : base(ASTNodeType.AssignStatement, start, end)
 {
     Target = target;
     Value = value;
 }
示例#2
0
 public InOpReference(InOpDeclaration op, Expression lhs, Expression rhs, SourcePosition start, SourcePosition end)
     : base(ASTNodeType.InOpRef, start, end)
 {
     Operator = op;
     LeftOperand = lhs;
     RightOperand = rhs;
 }
示例#3
0
 public ConditionalExpression(Expression cond, Expression first, Expression second, SourcePosition start, SourcePosition end)
     : base(ASTNodeType.ConditionalExpression, start, end)
 {
     Condition = cond;
     TrueExpression = first;
     FalseExpression = second;
 }
示例#4
0
 public WhileLoop(Expression cond, CodeBody body,
     SourcePosition start, SourcePosition end)
     : base(ASTNodeType.WhileLoop, start, end)
 {
     Condition = cond;
     Body = body;
 }
示例#5
0
 public ArraySymbolRef(Expression array, Expression index, SourcePosition start, SourcePosition end)
     : base(array, start, end)
 {
     Index = index;
     Type = ASTNodeType.ArrayReference;
     Array = array;
 }
示例#6
0
 public SwitchStatement(Expression expr, CodeBody body,
     SourcePosition start, SourcePosition end)
     : base(ASTNodeType.SwitchStatement, start, end)
 {
     Expression = expr;
     Body = body;
 }
示例#7
0
 public CompositeSymbolRef(Expression outer, Expression inner, SourcePosition start, SourcePosition end)
     : base(inner, start, end)
 {
     InnerSymbol = inner;
     OuterSymbol = outer;
     Type = ASTNodeType.CompositeReference;
 }
示例#8
0
 public IfStatement(Expression cond, CodeBody then,
     SourcePosition start, SourcePosition end, CodeBody optelse = null)
     : base(ASTNodeType.IfStatement, start, end)
 {
     Condition = cond;
     Then = then;
     Else = optelse;
 }
示例#9
0
 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;
 }
示例#10
0
 public CastExpression(VariableType type, Expression expr, SourcePosition start, SourcePosition end)
     : base(ASTNodeType.CastExpression, start, end)
 {
     CastType = type;
     CastTarget = expr;
 }
示例#11
0
 public CaseStatement(Expression expr, SourcePosition start, SourcePosition end)
     : base(ASTNodeType.CaseStatement, start, end)
 {
     Value = expr;
 }
示例#12
0
        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);
        }
示例#13
0
        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);
        }
示例#14
0
 public Expression TryParseIfExpression(Expression expr)
 {
     Func<ASTNode> ifexprParser = () =>
     {
         return null; // TODO
     };
     return (Expression)Tokens.TryGetTree(ifexprParser);
 }
示例#15
0
        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);
        }
示例#16
0
 public PreOpReference(PreOpDeclaration op, Expression oper, SourcePosition start, SourcePosition end)
     : base(ASTNodeType.InOpRef, start, end)
 {
     Operator = op;
     Operand = oper;
 }
示例#17
0
 public ReturnStatement(SourcePosition start, SourcePosition end, Expression value = null)
     : base(ASTNodeType.ReturnStatement, start, end)
 {
     Value = value;
 }
示例#18
0
 public ForEachLoop(Expression iterator, CodeBody body, SourcePosition start, SourcePosition end)
     : base(ASTNodeType.ForEachLoop, start, end)
 {
     IteratorCall = iterator;
     Body = body;
 }