Example #1
0
 public void AssignTo(Token t)
 {
     t.position = this.position;
     t.length = this.length;
     t.id = this.id;
     t.tokenClass = this.tokenClass;
 }
Example #2
0
 public BaseScanner(BaseParser parser)
 {
     this.token = new Token(this);
     this.history = new IntegerStack();
     this.def_stack = new IntegerStack();
     this.parser = parser;
     NumberFormatInfo currentInfo = NumberFormatInfo.CurrentInfo;
     this.DecimalSeparator = currentInfo.NumberDecimalSeparator;
 }
Example #3
0
        public virtual void Call_SCANNER()
        {
            int block;
            bool flag;
            this.curr_token = this.scanner.ReadToken();
            this.curr_token.atext = this.curr_token.Text;
            switch (this.curr_token.tokenClass)
            {
                case TokenClass.Identifier:
                    if (!this.IsKeyword(this.curr_token.Text))
                    {
                        if (this.REF_SWITCH)
                        {
                            this.curr_token.id = this.NewRef(this.curr_token.Text);
                            this.REF_SWITCH = false;
                            return;
                        }
                        if (!this.DECLARE_SWITCH)
                        {
                            this.curr_token.id = this.LookupID(this.curr_token.Text);
                            if (this.curr_token.id != 0)
                            {
                                int level = this.symbol_table[this.curr_token.id].Level;
                                if (this.symbol_table[level].Kind == MemberKind.Type)
                                {
                                    if (this.CurrLevel != 0)
                                    {
                                        this.curr_token.id = 0;
                                    }
                                }
                                else if (!this.IsDeclaredLocalVar(this.curr_token.id, this.CurrLevel))
                                {
                                    this.curr_token.id = 0;
                                }
                            }
                            if (this.curr_token.id == 0)
                            {
                                this.curr_token.id = this.symbol_table.AppVar();
                                SymbolRec rec2 = this.symbol_table[this.curr_token.id];
                                rec2.Name = this.curr_token.Text;
                                rec2.Level = this.CurrLevel;
                                rec2.Block = this.CurrBlock;
                                rec2.Kind = MemberKind.Var;
                                this.Gen(this.code.OP_EVAL, 0, 0, this.curr_token.id);
                            }
                            return;
                        }
                        if (!this.DECLARATION_CHECK_SWITCH)
                        {
                            goto Label_0234;
                        }
                        int iD = this.LookupID(this.curr_token.Text);
                        block = this.symbol_table[iD].Block;
                        if (((iD == 0) || (block == 0)) || (this.symbol_table[iD].Level != this.CurrLevel))
                        {
                            goto Label_0234;
                        }
                        flag = false;
                        for (int i = this.block_list.Count - 1; i >= 0; i--)
                        {
                            int num4 = this.block_list[i];
                            if ((num4 < block) && (num4 < this.CurrBlock))
                            {
                                flag = true;
                                break;
                            }
                            if (num4 == block)
                            {
                                break;
                            }
                        }
                        break;
                    }
                    if (!this.REF_SWITCH || !this.AllowKeywordsInMemberAccessExpressions)
                    {
                        this.curr_token.id = 0;
                        this.curr_token.tokenClass = TokenClass.Keyword;
                        return;
                    }
                    this.curr_token.id = this.NewRef(this.curr_token.Text);
                    this.REF_SWITCH = false;
                    return;

                case TokenClass.Keyword:
                case TokenClass.BooleanConst:
                    return;

                case TokenClass.IntegerConst:
                {
                    ulong num6;
                    string text = this.curr_token.Text;
                    if ((CSLite_System.PosCh('u', text) < 0) && (CSLite_System.PosCh('U', text) < 0))
                    {
                        if ((CSLite_System.PosCh('l', text) >= 0) || (CSLite_System.PosCh('L', text) >= 0))
                        {
                            if ((CSLite_System.PosCh('u', text) >= 0) || (CSLite_System.PosCh('U', text) >= 0))
                            {
                                ulong num8;
                                if ((CSLite_System.PosCh('x', text) >= 0) || (CSLite_System.PosCh('X', text) >= 0))
                                {
                                    text = text.Substring(2);
                                    num8 = ulong.Parse(text.Substring(0, text.Length - 2), NumberStyles.AllowHexSpecifier);
                                }
                                else
                                {
                                    num8 = ulong.Parse(text.Substring(0, text.Length - 2));
                                }
                                this.curr_token.id = this.symbol_table.AppConst(this.curr_token.Text, num8, StandardType.Ulong);
                            }
                            else
                            {
                                long num9;
                                if ((CSLite_System.PosCh('x', text) >= 0) || (CSLite_System.PosCh('X', text) >= 0))
                                {
                                    text = text.Substring(2);
                                    num9 = long.Parse(text.Substring(0, text.Length - 1), NumberStyles.AllowHexSpecifier);
                                }
                                else
                                {
                                    num9 = long.Parse(text.Substring(0, text.Length - 1));
                                }
                                this.curr_token.id = this.symbol_table.AppConst(this.curr_token.Text, num9, StandardType.Long);
                            }
                        }
                        else
                        {
                            ulong num10;
                            if ((CSLite_System.PosCh('x', text) >= 0) || (CSLite_System.PosCh('X', text) >= 0))
                            {
                                num10 = ulong.Parse(text.Substring(2), NumberStyles.AllowHexSpecifier);
                            }
                            else
                            {
                                num10 = ulong.Parse(text);
                            }
                            if (num10 <= 0x7fffffffL)
                            {
                                this.curr_token.id = this.symbol_table.AppConst(this.curr_token.Text, (int) num10, StandardType.Int);
                            }
                            else if (num10 <= 0xffffffffL)
                            {
                                this.curr_token.id = this.symbol_table.AppConst(this.curr_token.Text, (uint) num10, StandardType.Uint);
                            }
                            else if (num10 <= 0x7fffffffffffffffL)
                            {
                                this.curr_token.id = this.symbol_table.AppConst(this.curr_token.Text, (long) num10, StandardType.Long);
                            }
                            else
                            {
                                this.curr_token.id = this.symbol_table.AppConst(this.curr_token.Text, num10, StandardType.Ulong);
                            }
                        }
                        return;
                    }
                    if ((CSLite_System.PosCh('l', text) < 0) && (CSLite_System.PosCh('L', text) < 0))
                    {
                        uint num7;
                        if ((CSLite_System.PosCh('x', text) >= 0) || (CSLite_System.PosCh('X', text) >= 0))
                        {
                            text = text.Substring(2);
                            num7 = uint.Parse(text.Substring(0, text.Length - 1), NumberStyles.AllowHexSpecifier);
                        }
                        else
                        {
                            num7 = uint.Parse(text.Substring(0, text.Length - 1));
                        }
                        this.curr_token.id = this.symbol_table.AppConst(this.curr_token.Text, num7, StandardType.Uint);
                        return;
                    }
                    if ((CSLite_System.PosCh('x', text) < 0) && (CSLite_System.PosCh('X', text) < 0))
                    {
                        num6 = ulong.Parse(text.Substring(0, text.Length - 2));
                    }
                    else
                    {
                        text = text.Substring(2);
                        num6 = ulong.Parse(text.Substring(0, text.Length - 2), NumberStyles.AllowHexSpecifier);
                    }
                    this.curr_token.id = this.symbol_table.AppConst(this.curr_token.Text, num6, StandardType.Ulong);
                    return;
                }
                case TokenClass.StringConst:
                {
                    if ((CSLite_System.PosCh('@', this.curr_token.Text) == -1) || !(this.language != "VB"))
                    {
                        string str5 = this.scanner.ParseString(this.curr_token.Text);
                        this.curr_token.id = this.symbol_table.AppConst(this.curr_token.Text, str5.Substring(1, str5.Length - 2), StandardType.String);
                        return;
                    }
                    string str4 = this.scanner.ParseVerbatimString(this.curr_token.Text);
                    this.curr_token.id = this.symbol_table.AppConst(this.curr_token.Text, str4.Substring(1, str4.Length - 2), StandardType.String);
                    return;
                }
                case TokenClass.CharacterConst:
                {
                    char ch = this.scanner.ParseString(this.curr_token.Text)[1];
                    this.curr_token.id = this.symbol_table.AppCharacterConst(ch);
                    return;
                }
                case TokenClass.RealConst:
                {
                    string s = this.curr_token.Text;
                    if ((CSLite_System.PosCh(this.SingleCharacter, s) < 0) && (CSLite_System.PosCh(this.UpSingleCharacter, s) < 0))
                    {
                        if ((CSLite_System.PosCh(this.DoubleCharacter, s) >= 0) || (CSLite_System.PosCh(this.UpDoubleCharacter, s) >= 0))
                        {
                            s = s.Substring(0, s.Length - 1);
                            if (this.scanner.DecimalSeparator == ",")
                            {
                                s = s.Replace('.', ',');
                            }
                            double num12 = double.Parse(s, NumberStyles.Any);
                            this.curr_token.id = this.symbol_table.AppConst(this.curr_token.Text, num12, StandardType.Double);
                        }
                        else if ((CSLite_System.PosCh(this.DecimalCharacter, s) >= 0) || (CSLite_System.PosCh(this.UpDecimalCharacter, s) >= 0))
                        {
                            s = s.Substring(0, s.Length - 1);
                            if (this.scanner.DecimalSeparator == ",")
                            {
                                s = s.Replace('.', ',');
                            }
                            decimal num13 = decimal.Parse(s, NumberStyles.Any);
                            this.curr_token.id = this.symbol_table.AppConst(this.curr_token.Text, num13, StandardType.Decimal);
                        }
                        else
                        {
                            if (this.scanner.DecimalSeparator == ",")
                            {
                                s = s.Replace('.', ',');
                            }
                            double num14 = double.Parse(s);
                            this.curr_token.id = this.symbol_table.AppConst(this.curr_token.Text, num14, StandardType.Double);
                        }
                        return;
                    }
                    s = s.Substring(0, s.Length - 1);
                    if (this.scanner.DecimalSeparator == ",")
                    {
                        s = s.Replace('.', ',');
                    }
                    float num11 = float.Parse(s, NumberStyles.Any);
                    this.curr_token.id = this.symbol_table.AppConst(this.curr_token.Text, num11, StandardType.Float);
                    return;
                }
                default:
                    return;
            }
            if (!flag)
            {
                if (this.CurrBlock == block)
                {
                    this.RaiseErrorEx(false, "CS0128. A local variable named '{0}' is already defined in this scope.", new object[] { this.curr_token.Text });
                }
                else if (this.CurrBlock > block)
                {
                    this.RaiseErrorEx(false, "CS0136. A local variable named '{0}' cannot be declared in this scope because it would give a different meaning to '{0}', which is already used in a '{1}' scope to denote something else", new object[] { this.curr_token.Text, "parent or current" });
                }
                else
                {
                    this.RaiseErrorEx(false, "CS0136. A local variable named '{0}' cannot be declared in this scope because it would give a different meaning to '{0}', which is already used in a '{1}' scope to denote something else", new object[] { this.curr_token.Text, "child" });
                }
            }
            Label_0234:
            this.curr_token.id = this.symbol_table.AppVar();
            SymbolRec rec = this.symbol_table[this.curr_token.id];
            rec.Name = this.curr_token.Text;
            rec.Level = this.CurrLevel;
            rec.Block = this.CurrBlock;
        }
Example #4
0
 public int ReadToken()
 {
     int num = 0;
     do
     {
         num++;
         this.curr_token = this.scanner.ReadToken();
     }
     while (this.curr_token.tokenClass == TokenClass.Separator);
     this.curr_token.atext = this.curr_token.Text;
     return num;
 }