Beispiel #1
0
 protected Token NextToken()
 {
     if (idx >= Tokens.Count || idx < 0)
         t = new Token(TokenType.NoToken, "", 0);
     else
         t = Tokens[idx++];
     return t;
 }
 bool EsVariable(Token token)
 {
     return !string.IsNullOrEmpty(token.Lexem) && token.Lexem[0] != token.LexemLower[0];
 }
Beispiel #3
0
 protected void AddError(string message, Token token)
 {
     Token tmp;
     if (idx > 0 && token.Type == TokenType.NoToken)
     {
         tmp = Tokens[idx - 1];
         AddError(message, tmp.Line, tmp.Column);
     }
     else
         AddError(message + " y llegó " + token.Lexem, token.Line, token.Column);
 }
Beispiel #4
0
        public Token nextToken(int line = 0)
        {
            int estado = 0, estAnt = 0;
            string lexema = "";
            TokenType token;
            while (idx < entrada.Length && estado != ERR && estado != ACP)
            {
                char c = entrada[idx++];
                while (estado == 0 && (c == ' ' || c == '\t')) c = entrada[idx++];
                int col = colCar(c);
                if (col >= 0)
                {
                    estado = matran[estado, col];
                    if (estado != ERR && estado != ACP)
                    {
                        estAnt = estado;
                        lexema += c;
                    }
                }
                else estado = ERR;

                if (estado == ERR)
                    AddError("Simbolo ilegal en el lenguaje " + c, line,idx);
            }
            if (estado == ACP) idx--;
            if (estado != ERR && estado != ACP) estAnt = estado;
            token = TokenType.NoToken;
            switch (estAnt)
            {
                case 1:
                case 4:
                case 6:
                case 7:
                    token = TokenType.OpLog; break;
                case 2:
                    token = TokenType.Cuantif; break;
                case 5:
                case 9:
                case 11:
                case 12:
                    token = TokenType.OpRela; break;
                case 8:
                    token = TokenType.Delimi; break;
                case 13:
                    token = TokenType.Identi; break;
            }
            var t = new Token(token, lexema);
            t.Line = line + 1;
            t.Column = idx;
            return t;
        }