ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Ejemplo de descripcion de tokens - compiladores


Enviado por   •  25 de Mayo de 2016  •  Apuntes  •  399 Palabras (2 Páginas)  •  181 Visitas

Página 1 de 2

function Cedula(cedula) {

    this.cedula = cedula;

    this.isValid = function() {

        var digit1 = this.cedula.charAt(0);

        if(digit1 == 0 || digit1 == 1) { //cedula ecuador empieza 0 o 1 siempre

            if(parseInt(digit1) == this.getDigitVerif())

                return true;

        }

        return false;

    };

    this.getDigitVerif = function() {

        var suma = 0;

        for(var i = 0; i <= 9; i++) {

            var digit = parseInt(cedula.charAt(i));

            if(i%2 == 0) { //posicion par?

                digit *= 2;

                if(digit > 9)

                    digit -= 9;

            }

            suma += digit;

        }

        if(suma%10 == 0) //termina en 0? (digito verificador)

            return 0;

        return ((suma/10 + 1) * 10) - suma; //la cifra multiple de 10 superior

    }

}

entrada = prompt("ingrese la cedula")

cedula1 = new Cedula(entrada);

if(cedula1.isValid()) {

    console.log('Cedula Valida');

} else {

    console.log('Cedula [NO] Valida');

}

ID token

Token

Lexema

Patrón

1

palabras reservada

function, parseint, for, charAt, if, this, return, true, false, var, prompt, Console, log, else

if, else, while, function ….

2

identificador

Cedula, cedula, digit1, suma,i , getDigitVerif, isValid, entrada, cedula1

[A-Za-z][A-Za-z0-1]*

3

Operadores de asignación

=

[\=]

 

5

 Operadores aritméticos

+, -, ++, %, *

 [+-*/^]

6

Operadores relacionales

==, <=,

[<|<=|>=|>|!=]

7

cadenas

'Cedula Valida', 'Cedula [NO] Valida',

 [0-9]*

8

 constantes

0, 1,  2,  9, 10

 [0 - 9]* || {[0-9]+}

9

  símbolos

 : , ;, {}, (), “

 [$|(|)|”|;|:|{|}]

 

 

 

 

 

 

...

Descargar como (para miembros actualizados)  txt (1.8 Kb)   pdf (74.9 Kb)   docx (10 Kb)  
Leer 1 página más »
Disponible sólo en Clubensayos.com