示例#1
0
        private Expression ParseFactor()
        {
            Expression factor;

            if (CurrentToken.Type == TokenType.Identifier)
            {
                factor = ParseCallOrVarExpr();
            }
            else if (Accept(TokenType.IntLiteral))
            {
                factor = new IntLiteralExpr(AcceptedToken);
            }
            else if (Accept(TokenType.StringLiteral))
            {
                factor = new StringLiteralExpr(AcceptedToken);
            }
            else if (Accept(TokenType.RealLiteral))
            {
                factor = new RealLiteralExpr(AcceptedToken);
            }
            else if (Accept(TokenType.LParen))
            {
                Expression expr = ParseExpression();
                Match(TokenType.RParen);
                factor = expr;
            }
            else if (Accept(TokenType.OpNot))
            {
                UnaryExpr expr = new UnaryExpr(AcceptedToken);
                expr.Op   = Operator.Not;
                expr.Expr = ParseFactor();
                factor    = expr;
            }
            else
            {
                throw new Exception(string.Format("Expected a factor, {0} found", CurrentToken.Type));
            }

            if (Accept(TokenType.OpDot))
            {
                MemberAccessExpr expr = new MemberAccessExpr(AcceptedToken);
                expr.AccessedExpr = factor;
                expr.MemberId     = ParseIdentifier();
                return(expr);
            }
            return(factor);
        }
示例#2
0
 private void Visit(IntLiteralExpr intLiteral)
 {
     CurrentMethodIL.Emit(OpCodes.Ldc_I4, intLiteral.Value);
     ApplyExprSign(intLiteral);
 }
示例#3
0
 private void Visit(IntLiteralExpr intLiteralExpr)
 {
     TypeStack.Push(TypeInfo.BasicInt);
 }