Exemplo n.º 1
0
        public Cases Cases()
        {
            if (this.currentToken.Tipo == Lexico.TipoToken.TK_CASE)
            {
                Cases cas = new Cases();
                this.currentToken = lex.NextToken();
                if (this.currentToken.Tipo != Lexico.TipoToken.TK_CHAR_LIT && this.currentToken.Tipo != Lexico.TipoToken.TK_FLOAT_LIT && this.currentToken.Tipo != Lexico.TipoToken.TK_INT_LIT)
                    throw new Exception("Se esperaba un numero o un char");

                cas.Valor = currentToken.Lexema;
                this.currentToken = lex.NextToken();
                if (this.currentToken.Tipo != Lexico.TipoToken.TK_DOSPUNTOS)
                    throw new Exception("Se esperaba el simbolo :");
                currentToken = lex.NextToken();
                cas.S= StatementList();
                cas.sig=Cases();
                return cas;
            }
            return null;
        }
Exemplo n.º 2
0
        public Cases Cases()
        {
            if (currentToken.Tipo == Lexico.TipoToken.TK_CASE)
            {
                currentToken = lex.NextToken();
                Cases C = new Cases();

                if (currentToken.Tipo != Lexico.TipoToken.TK_CHAR_LIT ||
                        currentToken.Tipo != Lexico.TipoToken.TK_FLOAT_LIT ||
                        currentToken.Tipo != Lexico.TipoToken.TK_INT_LIT)
                {
                    C.Valor = currentToken.Lexema;
                    currentToken = lex.NextToken();
                    if (currentToken.Tipo == TipoToken.TK_DOSPUNTOS)
                    {
                        currentToken = lex.NextToken();
                        C.S = StatementList();
                        C.sig = Cases();
                        return C;
                    }
                    else
                    {
                        throw new Exception("Error Sintactico - Se esperaba el simbolo :");
                    }
                }
                else
                {
                    throw new Exception("Error Sintactico - Se esperaba un numero o un char");
                }
            }
            else
            {
                return null;
            }
        }
Exemplo n.º 3
0
 Cases parseCase()
 {
     if (currentToken.Tipo != TipoToken.TK_INT_LIT)
         throw new Exception("Se esperaba una constante numérica.");
     else
     {
         Cases ret = new Cases();
         ret.Valor = new LiteralEntero(int.Parse(currentToken.Lexema));
         currentToken = lex.NextToken();
         if (currentToken.Tipo != TipoToken.TK_DOSPUNTOS)
             throw new Exception("se esperaba :");
         else
         {
             currentToken = lex.NextToken();
             try { ret.S = CodeBlock(); }
             catch (Exception ex) { throw ex; }
             return ret;
         }
     }
 }