示例#1
0
        /// <summary>
        /// 读取函数参数
        /// </summary>
        /// <returns></returns>
        Expression[] ReadArguments()
        {
            List<Expression> exps = new List<Expression>();
            Continue(Token.TokenKind.LParen);
            int index=0;
            while(true)
            {
                if (currentToken.Kind == Token.TokenKind.RParen)
                {
                    Continue();
                    break;
                }
                if (index > 0)
                    Continue(Token.TokenKind.Comma);
                if(currentToken.Kind==Token.TokenKind.Integer)
                {
                    Token arg = Continue(Token.TokenKind.Integer);
                    IntegerExpression integer = new IntegerExpression(arg.Line, arg.Col, int.Parse(arg.Text));
                    exps.Add(integer);
                }
                if(currentToken.Kind==Token.TokenKind.Double)
                {
                    Token arg = Continue(Token.TokenKind.Double);
                    DoubleExpression d = new DoubleExpression(arg.Line, arg.Col, double.Parse(arg.Text));
                    exps.Add(d);
                }
                if (currentToken.Kind == Token.TokenKind.ExpStart)
                    exps.Add(ReadExpression());
                if (currentToken.Kind == Token.TokenKind.StringStart)
                    exps.Add(ReadString());

                index++;
            }
            return exps.ToArray();
        }
示例#2
0
 /// <summary>
 /// 读取双引号中间的元素
 /// </summary>
 /// <returns></returns>
 Expression ReadString()
 {
     Continue(Token.TokenKind.StringStart);
     CellectionExpression Exp = new CellectionExpression(currentToken.Line, currentToken.Col);
     while (true)
     {
         if (currentToken.Kind == Token.TokenKind.ExpStart)
         {
             Exp.Add(ReadExpression());
         }
         else if (currentToken.Kind == Token.TokenKind.StringText)
         {
             Token value = Continue(Token.TokenKind.StringText);
             StringExpression se = new StringExpression(currentToken.Line, currentToken.Col, value.Text);
             Exp.Add(se);
         }
         else if (currentToken.Kind == Token.TokenKind.Integer)
         {
             Token token = Continue(Token.TokenKind.Integer);
             IntegerExpression integer = new IntegerExpression(token.Line, token.Col, int.Parse(token.Text));
             Exp.Add(integer);
         }
         else if (currentToken.Kind == Token.TokenKind.Double)
         {
             Token d = Continue(Token.TokenKind.Double);
             DoubleExpression dexp = new DoubleExpression(d.Line, d.Col, double.Parse(d.Text));
             Exp.Add(dexp);
         }
         else if (currentToken.Kind == Token.TokenKind.StringEnd)
         {
             Continue();
             break;
         }
         else if (currentToken.Kind == Token.TokenKind.EOF)
         {
             throw new ParserException("不是期望的Token", currentToken);
         }
         else
             throw new ParserException("不是期望的Token", currentToken);
     }
     if (Exp.Expressions.Count == 1)
         return Exp.Expressions[0];
     else
         return Exp;
 }