Exemple #1
0
        public void compile()
        {
            currentToken = lex.nextToken();
            Sentence programa = program();

            Console.WriteLine(programa.genCode() + "\n\n");
            programa.validarSemantica();
            programa.interpretar();
            int x = 0;
        }
Exemple #2
0
 void match(TokenType tokentype)
 {
     if (currentToken.Tipo == tokentype)
         currentToken = lex.nextToken();
     else
         throw new Exception("En la linea: " + Lexer.line + " columna: " + Lexer.column + " se esperaba \'" + tokentype + "\' token actual -> " + currentToken.Tipo);
 }
Exemple #3
0
        void match(string token)
        {
            try
            {
                TokenType type = lex.getTokenType(token);

                if (currentToken.Tipo == type)
                    currentToken = lex.nextToken();
                else
                    throw new Exception("En la linea: " + Lexer.line + " columna: " + Lexer.column + " se esperaba \'" + token + "\' con id \'" + type + "\' token actual -> " + currentToken.Lexema);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }
Exemple #4
0
        Expr primary_expr()
        {
            switch (currentToken.Tipo)
            {
                case TokenType.TRUE:
                    BooleanoLiteral booleanoTrue = new BooleanoLiteral(true);
                    match(TokenType.TRUE);
                    return booleanoTrue;

                case TokenType.FALSE:
                    BooleanoLiteral booleanoFalse = new BooleanoLiteral(false);
                    match(TokenType.FALSE);
                    return booleanoFalse;

                case TokenType.CHARACTER_LITERAL:
                    CaracterLiteral caracter = new CaracterLiteral(char.Parse(currentToken.Lexema));
                    currentToken = lex.nextToken();
                    return caracter;

                case TokenType.STRING_LITERAL:
                    CadenaLiteral cadena = new CadenaLiteral(currentToken.Lexema);
                    currentToken = lex.nextToken();
                    return cadena;

                case TokenType.INTEGER_LITERAL:
                    EnteroLiteral entero = new EnteroLiteral(int.Parse(currentToken.Lexema));
                    match(TokenType.INTEGER_LITERAL);
                    return entero;

                case TokenType.REAL_LITERAL:
                    RealLiteral real = new RealLiteral(float.Parse(currentToken.Lexema));
                    match(TokenType.INTEGER_LITERAL);
                    return real;

                case TokenType.LEFT_PARENTHESIS:
                    match("("); Expr expresion = expr(); match(")");
                    return expresion;

                default:
                    throw new Exception("Error en la expresion linea: " + Lexer.line + " columna: " + Lexer.column + " currenttoken -> " + currentToken.Lexema);
            }
        }