Example #1
0
        //Проверка ожидаемой лексемы
        public static void Check(tLex ExpLex, string sWord)
        {
            if (DScan.Lex == tLex.lexInt && ExpLex == tLex.lexNum)
            {
                dCurNum = DScan.Num;
                DScan.NextLex();
                return;
            }

            if (DScan.Lex != ExpLex)
            {
                DError.Expected(sWord);
            }

            else
            {
                DText.PrevLexPos = DText.CodePos;

                if (DScan.Lex == tLex.lexName || DScan.Lex == tLex.lexdxdt)
                    sCurName = DScan.Name + '\n';

                if (DScan.Lex == tLex.lexInt)
                    iCurIndex = (int)DScan.Num;

                if (DScan.Lex == tLex.lexNum)
                    dCurNum = DScan.Num;

                DScan.NextLex();
            }
        }
Example #2
0
 static void Check(tLex L, string M)
 {
     if (Scan.Lex != L)
     {
         Error.Expected(M);
     }
     else
     {
         Scan.NextLex();
     }
 }
Example #3
0
 //Добавление численного метода в список и проверка на повторное добавлене
 public static bool CheckMethod(tLex tMethod, string sMethod)
 {
     if (DScan.Lex == tMethod && !Methods.Contains(sMethod))
     {
         Methods.Add(sMethod);
         DScan.NextLex();
         return true;
     }
     else if (DScan.Lex == tMethod && Methods.Contains(sMethod))
         DError.Errors(" данный метод уже есть в списке ");
     return false;
 }
Example #4
0
 private static void Number()
 {
     Lex = tLex.lexNum;
     Num = 0;
     do
     {
         int d = Text.Ch - '0';
         if ((int.MaxValue - d) / 10 >= Num)
         {
             Num = 10 * Num + d;
         }
         else
         {
             Error.Message("Слишком большое число");
         }
         Text.NextCh();
     } while(char.IsDigit((char)Text.Ch));
 }
Example #5
0
    public static void Comp(tLex Lex)
    {
        Cmd(0); // Адрес перехода вперед
        switch (Lex)
        {
        case tLex.lexEQ: Cmd(OVM.cmIfNE); break;

        case tLex.lexNE: Cmd(OVM.cmIfEQ); break;

        case tLex.lexLE: Cmd(OVM.cmIfGT); break;

        case tLex.lexLT: Cmd(OVM.cmIfGE); break;

        case tLex.lexGE: Cmd(OVM.cmIfLT); break;

        case tLex.lexGT: Cmd(OVM.cmIfLE); break;
        }
    }
Example #6
0
    private static void Ident()
    {
        int i = 0;

        Buf.Length = NAMELEN;
        do
        {
            if (i < NAMELEN)
            {
                Buf[i++] = (char)Text.Ch;
            }
            else
            {
                Error.Message("Слишком длинное имя");
            }
            Text.NextCh();
        } while(char.IsLetterOrDigit((char)Text.Ch));
        Buf.Length = i;
        Name       = Buf.ToString();
        Lex        = TestKW(); // Проверка на ключевое слово
    }
Example #7
0
 private static void EnterKW(string Name, tLex Lex)
 {
     KWTable[nkw].Word  = String.Copy(Name);
     KWTable[nkw++].Lex = Lex;
 }
Example #8
0
    public static void NextLex()
    {
        while (
            Text.Ch == Text.chSPACE ||
            Text.Ch == Text.chTAB ||
            Text.Ch == Text.chEOL
            )
        {
            Text.NextCh();
        }
        Location.LexPos = Location.Pos;
        if (char.IsLetter((char)Text.Ch))
        {
            Ident();
        }
        else if (char.IsDigit((char)Text.Ch))
        {
            Number();
        }
        else
        {
            switch (Text.Ch)
            {
            case ';':
                Text.NextCh(); Lex = tLex.lexSemi;
                break;

            case ':':
                Text.NextCh();
                if (Text.Ch == '=')
                {
                    Text.NextCh(); Lex = tLex.lexAss;
                }
                else
                {
                    Lex = tLex.lexColon;
                }
                break;

            case '.':
                Text.NextCh(); Lex = tLex.lexDot;
                break;

            case ',':
                Text.NextCh(); Lex = tLex.lexComma;
                break;

            case '=':
                Text.NextCh(); Lex = tLex.lexEQ;
                break;

            case '#':
                Text.NextCh(); Lex = tLex.lexNE;
                break;

            case '<':
                Text.NextCh();
                if (Text.Ch == '=')
                {
                    Text.NextCh(); Lex = tLex.lexLE;
                }
                else
                {
                    Lex = tLex.lexLT;
                }
                break;

            case '>':
                Text.NextCh();
                if (Text.Ch == '=')
                {
                    Text.NextCh(); Lex = tLex.lexGE;
                }
                else
                {
                    Lex = tLex.lexGT;
                }
                break;

            case '(':
                Text.NextCh();
                if (Text.Ch == '*')
                {
                    Comment();   NextLex();
                }
                else
                {
                    Lex = tLex.lexLPar;
                }
                break;

            case ')':
                Text.NextCh(); Lex = tLex.lexRPar;
                break;

            case '+':
                Text.NextCh(); Lex = tLex.lexPlus;
                break;

            case '-':
                Text.NextCh(); Lex = tLex.lexMinus;
                break;

            case '*':
                Text.NextCh(); Lex = tLex.lexMult;
                break;

            case Text.chEOT:
                Lex = tLex.lexEOT;
                break;

            default:
                Error.Message("Недопустимый символ");
                break;
            }
        }
    }
Example #9
0
 private static void EnterKW(string nName, tLex nLex)
 {
     KWTable[nkw].Word = nName;
     KWTable[nkw].Lex = nLex;
     nkw++;
 }