コード例 #1
0
ファイル: cParser.cs プロジェクト: DiegoTc/compiladoresI
        public Cases Cases()
        {
            try
            {
                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 = Expression();

                    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;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
ファイル: pascalParser.cs プロジェクト: DiegoTc/compiladoresI
 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;
         }
     }
 }
コード例 #3
0
ファイル: javaParser.cs プロジェクト: DiegoTc/compiladoresI
        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)
                {
                    try
                    {
                        C.Valor = Expr();
                    }
                    catch (Exception ex)
                    {

                        throw ex;
                    }
                    //currentToken = lex.NextToken();
                    if (currentToken.Tipo == TipoToken.TK_DOSPUNTOS)
                    {
                        currentToken = lex.NextToken();
                        try
                        {
                            C.S = StatementList();
                            C.Sig = Cases();
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }

                        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;
            }
        }