示例#1
0
文件: Tdop.cs 项目: ZiCog/HomeSpun
        public override Expr Nud()
        {
            if (Tokenizer.Current.Text == "#")	// <id> # <id>
            {
                Tokenizer.Advance("#");
                IdToken id2 = Tokenizer.GetToken() as IdToken;
                if (id2 == null)
                    throw new ParseException("Expected constant name", id2);
                return new ConExpr(this, id2);
            }
            if (Tokenizer.Current.Text == "(")	// <id> ( <arglist> )   (method call)
            {
                ArrayList argList = ParseArgumentList(Tokenizer);
                return new CallExpr(null, this, null, argList);
            }
            if (Tokenizer.Current.Text == ".")	// <id> . <something>
            {
                Tokenizer.Advance(".");
                if (Tokenizer.Current is IdToken)	// <id> . <id>  (method call)
                {
                    IdToken method = Tokenizer.GetToken() as IdToken;
                    ArrayList argList = ParseArgumentList(Tokenizer);
                    return new CallExpr(this, method, null, argList);
                }
                else if (Tokenizer.Current is SizeToken)	// <id> . BYTE|WORD|LONG
                {
                    int size = SizeSpecifier(Tokenizer.GetToken().Text);
                    VariableExpr v = new VariableExpr(this, size);
                    if (Tokenizer.Current.Text == "[")	// <id> . BYTE|WORD|LONG [ <expr> ]
                    {
                        Tokenizer.Advance("[");
                        ArrayList indexExprList = new ArrayList();
                        indexExprList.Add(ParseExpression(Tokenizer, 13));
                        v.IndexExprList(indexExprList);
                        Tokenizer.Advance("]");
                    }
                    return v;
                }
            }

            if (Tokenizer.Current.Text == "[")	// <id> [ <expr> ( , <expr> )* ]
            {
                Tokenizer.Advance("[");

                ArrayList indexExprList = new ArrayList();
                VariableExpr v = new VariableExpr(this, 0);
                while (true)
                {
                    Expr e = ParseExpression(Tokenizer, 13);
                    indexExprList.Add(e);
                    if (Tokenizer.Current.Text != ",")
                        break;
                    Tokenizer.Advance(",");
                }
                Tokenizer.Advance("]");
                if (Tokenizer.Current.Text == ".")	// <id> [ <expr> ( , <expr> )* ] . <id> (method call)
                {
                    Tokenizer.Advance(".");

                    if (indexExprList.Count > 1)
                    {
                        throw new ParseException("multiple dimensions not allowed", ((Expr)indexExprList[1]).Token);
                    }
                    if (Tokenizer.Current is IdToken)
                    {
                        IdToken method = Tokenizer.GetToken() as IdToken;
                        ArrayList argList = ParseArgumentList(Tokenizer);
                        return new CallExpr(this, method, (Expr)indexExprList[0], argList);
                    }
                    else
                        throw new ParseException("Expected method name", Tokenizer.Current);
                }
                else	// <id> [ <expr> ( , <expr> )* ] -- i.e., variable with at least one subscript
                {
                    v.IndexExprList(indexExprList);
                }
                return v;
            }

            return new IdExpr(this);
        }
示例#2
0
文件: Exprs.cs 项目: ZiCog/HomeSpun
 public void Visit(VariableExpr e)
 {
     throw new ParseException("Variable not allowed in constant expression", e.Token);
 }