How to use token_1 method in wpt

Best JavaScript code snippet using wpt

Analizador_Sintactico.js

Source:Analizador_Sintactico.js Github

copy

Full Screen

1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3const Abstrac_Sintactic_Tree_1 = require("../AST/Abstrac_Sintactic_Tree");4const Asignation_1 = require("../AST/Declaration-Definition-Global/Asignation");5const Declaration_1 = require("../AST/Declaration-Definition-Global/Declaration");6const Identifier_1 = require("../AST/Declaration-Definition-Global/Identifier");7const Method_1 = require("../AST/Declaration-Definition-Global/Method");8const Parameter_1 = require("../AST/Declaration-Definition-Global/Parameter");9const Class_Interface_1 = require("../AST/Instructions/Class_Interface");10const Print_1 = require("../AST/Sentences/Print");11const Return_Continue_Break_1 = require("../AST/Sentences/Return_Continue_Break");12const While_1 = require("../AST/Sentences/While");13const Types_1 = require("../AST/Types");14const Token_1 = require("./Token");15const Token_Error_1 = require("./Token_Error");16class Analizador_Sintactico {17 constructor() {18 this.errorSintactico = false;19 /** RECOLECTOR DE EXPRESION **/20 this.expresion = "";21 this.lista_Instrucciones = [];22 this.lista_Decla_Asign = [];23 this.lista_Declaraciones_Global = [];24 this.lista_Parametros = [];25 this.lista_Sentencias = [];26 this.lista_Definition_F = [];27 this.lista_Bloque_Ciclo = [];28 }29 parsear(lista, listE) {30 this.listaTokens = lista;31 this.listaErrores = listE;32 this.preanalisis = this.listaTokens[0];33 this.numPreanalisis = 0;34 this.INICIO();35 /***********************************************************/36 let ast = new Abstrac_Sintactic_Tree_1.Abstrac_Sintactic_Tree(this.lista_Instrucciones);37 return ast;38 /***********************************************************/39 }40 INICIO() {41 this.LIST_INSTRUCTIONS();42 }43 LIST_INSTRUCTIONS() {44 this.INSTRUCTION();45 this.LIST_INSTRUCTIONS_P();46 }47 INSTRUCTION() {48 /*******************************/49 var instruccion;50 /*******************************/51 this.match(Token_1.Tipo.RESERVADA_PUBLIC);52 instruccion = this.INSTRUCTIONS_P();53 this.lista_Declaraciones_Global = [];54 this.lista_Definition_F = [];55 /****************************************/56 this.lista_Instrucciones.push(instruccion);57 /****************************************/58 }59 LIST_INSTRUCTIONS_P() {60 if (this.preanalisis.getTipo() != Token_1.Tipo.LLAVE_DER && this.preanalisis.getTipo() != Token_1.Tipo.ULTIMO) {61 this.INSTRUCTION();62 this.LIST_INSTRUCTIONS_P();63 }64 }65 INSTRUCTIONS_P() {66 /**************************/67 var cla_int = "";68 var id = "";69 var arrayDecla = [];70 var column = 0;71 /**************************/72 if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_CLASS) {73 cla_int = this.preanalisis.getLexema();74 column = this.preanalisis.getColumna() - 7;75 this.match(Token_1.Tipo.RESERVADA_CLASS);76 id = this.preanalisis.getLexema();77 this.match(Token_1.Tipo.IDENTIFICADOR);78 this.match(Token_1.Tipo.LLAVE_IZQ);79 this.LIST_DECLARATION_GLOBAL();80 arrayDecla = this.lista_Declaraciones_Global;81 this.match(Token_1.Tipo.LLAVE_DER);82 }83 else if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_INTERFACE) {84 cla_int = this.preanalisis.getLexema();85 column = this.preanalisis.getColumna() - 7;86 this.match(Token_1.Tipo.RESERVADA_INTERFACE);87 id = this.preanalisis.getLexema();88 this.match(Token_1.Tipo.IDENTIFICADOR);89 this.match(Token_1.Tipo.LLAVE_IZQ);90 this.DEFINITION_FUNCTIONS();91 arrayDecla = this.lista_Definition_F;92 this.match(Token_1.Tipo.LLAVE_DER);93 }94 else {95 /** ERROR **/96 if (this.errorSintactico == false) {97 //console.log(">> Error sintactico se esperaba [ class, interface ] en lugar de [" + this.preanalisis.getTipoEnString() + ", " + this.preanalisis.getLexema() + "]");98 this.addTokenError(this.preanalisis.getLexema(), "Se esperaba class, interface", this.preanalisis.getFila(), this.preanalisis.getColumna());99 this.errorSintactico = true;100 this.match(Token_1.Tipo.LLAVE_DER);101 }102 else {103 this.errorSintactico = true;104 this.match(Token_1.Tipo.LLAVE_DER);105 }106 }107 /***************************/108 return new Class_Interface_1.Class_Interface("public", cla_int, id, arrayDecla, column);109 /***************************/110 }111 /***********************************************************************************/112 LIST_DECLARATION_GLOBAL() {113 /*****************************/114 var declaracion_g;115 /*****************************/116 if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_INT || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_BOOLEAN117 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_DOUBLE || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_STRING118 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_CHAR || this.preanalisis.getTipo() == Token_1.Tipo.IDENTIFICADOR119 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_PUBLIC) {120 declaracion_g = this.DECLARATION_GLOBAL();121 /**********************************/122 this.lista_Declaraciones_Global.push(declaracion_g);123 /**********************************/124 this.LIST_DECLARATION_GLOBAL();125 }126 }127 DECLARATION_GLOBAL() {128 /*****************************/129 var declaracion_g;130 /*****************************/131 if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_INT || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_BOOLEAN132 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_DOUBLE || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_STRING133 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_CHAR) {134 declaracion_g = this.DECLARATION();135 this.lista_Decla_Asign = [];136 this.match(Token_1.Tipo.PUNTO_Y_COMA);137 }138 else if (this.preanalisis.getTipo() == Token_1.Tipo.IDENTIFICADOR) {139 declaracion_g = this.ASIGNATION();140 /******************/141 this.expresion = "";142 /******************/143 this.match(Token_1.Tipo.PUNTO_Y_COMA);144 }145 else if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_PUBLIC) {146 declaracion_g = this.METHOD();147 this.lista_Parametros = [];148 this.lista_Sentencias = [];149 }150 else {151 /** ERROR **/152 if (this.errorSintactico == false) {153 //console.log(">> Error sintactico se esperaba [ Declaracion global ] en lugar de [" + this.preanalisis.getTipoEnString() + ", " + this.preanalisis.getLexema() + "]");154 this.addTokenError(this.preanalisis.getLexema(), "Se esperaba Declaracion global", this.preanalisis.getFila(), this.preanalisis.getColumna());155 this.errorSintactico = true;156 this.match(Token_1.Tipo.PUNTO_Y_COMA);157 }158 else {159 this.errorSintactico = true;160 this.match(Token_1.Tipo.PUNTO_Y_COMA);161 }162 /*****************************************/163 declaracion_g = new Declaration_1.Declaration("", [], 0);164 /*****************************************/165 }166 return declaracion_g;167 }168 DEFINITION_FUNCTIONS() {169 /*********************************/170 let columnD = 0;171 let tipo = "";172 let idDefi = "";173 let defiFunt;174 /*********************************/175 columnD = this.preanalisis.getColumna();176 if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_PUBLIC) {177 this.match(Token_1.Tipo.RESERVADA_PUBLIC);178 tipo = this.preanalisis.getLexema();179 this.TYPE_METHOD();180 idDefi = this.preanalisis.getLexema();181 this.match(Token_1.Tipo.IDENTIFICADOR);182 this.match(Token_1.Tipo.PARENTESIS_IZQ);183 this.LIST_PARAMETROS();184 this.match(Token_1.Tipo.PARENTESIS_DER);185 this.match(Token_1.Tipo.PUNTO_Y_COMA);186 defiFunt = new Method_1.Method("public", tipo, idDefi, this.lista_Parametros, null, columnD);187 /****************/188 this.lista_Parametros = [];189 /****************/190 this.lista_Definition_F.push(defiFunt);191 this.DEFINITION_FUNCTIONS();192 }193 }194 /***********************************************************************************/195 DECLARATION() {196 /*****************************/197 let tipo = "";198 let columDeclaration = 0;199 /*****************************/200 tipo = this.preanalisis.getLexema();201 columDeclaration = this.preanalisis.getColumna();202 this.TYPE_DATA();203 this.LIST_DECLA_ASIGN();204 /*****************************/205 return new Declaration_1.Declaration(tipo, this.lista_Decla_Asign, columDeclaration);206 /*****************************/207 }208 TYPE_DATA() {209 if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_INT) {210 this.match(Token_1.Tipo.RESERVADA_INT);211 }212 else if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_BOOLEAN) {213 this.match(Token_1.Tipo.RESERVADA_BOOLEAN);214 }215 else if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_DOUBLE) {216 this.match(Token_1.Tipo.RESERVADA_DOUBLE);217 }218 else if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_STRING) {219 this.match(Token_1.Tipo.RESERVADA_STRING);220 }221 else if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_CHAR) {222 this.match(Token_1.Tipo.RESERVADA_CHAR);223 }224 else {225 /** ERROR **/226 if (this.errorSintactico == false) {227 //console.log(">> Error sintactico se esperaba [ Tipo de dato ] en lugar de [" + this.preanalisis.getTipoEnString() + ", " + this.preanalisis.getLexema() + "]");228 this.addTokenError(this.preanalisis.getLexema(), "Se esperaba Tipo de dato", this.preanalisis.getFila(), this.preanalisis.getColumna());229 this.errorSintactico = true;230 this.match(Token_1.Tipo.PUNTO_Y_COMA);231 }232 else {233 this.match(Token_1.Tipo.PUNTO_Y_COMA);234 }235 }236 }237 LIST_DECLA_ASIGN() {238 this.DECLA_ASIGN();239 this.LIST_DECLA_ASIGN_P();240 }241 LIST_DECLA_ASIGN_P() {242 if (this.preanalisis.getTipo() == Token_1.Tipo.COMA) {243 this.match(Token_1.Tipo.COMA);244 this.DECLA_ASIGN();245 this.LIST_DECLA_ASIGN_P();246 }247 }248 DECLA_ASIGN() {249 /******************************/250 let decla_asign;251 /******************************/252 this.match(Token_1.Tipo.IDENTIFICADOR);253 decla_asign = this.DECLA_ASIGN_P();254 this.expresion = "";255 /********************************/256 this.lista_Decla_Asign.push(decla_asign);257 /********************************/258 }259 DECLA_ASIGN_P() {260 /********************************/261 let idAsign = "";262 let columnAsign = 0;263 /********************************/264 idAsign = this.listaTokens[this.numPreanalisis - 1].getLexema();265 columnAsign = this.listaTokens[this.numPreanalisis - 1].getColumna();266 if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_IGUAL) {267 this.match(Token_1.Tipo.SIGNO_IGUAL);268 this.EXPRESSION();269 return new Asignation_1.Asignation(idAsign, this.expresion, false, columnAsign);270 }271 return new Identifier_1.Identifier(idAsign, null, Types_1.Type_Operation.IDENTIFICADOR, false, 1);272 }273 /***********************************************************************************/274 ASIGNATION() {275 this.match(Token_1.Tipo.IDENTIFICADOR);276 return this.ASIGNATION_P();277 }278 ASIGNATION_P() {279 /********************************/280 let idAsign = "";281 let columnAsign = 0;282 /********************************/283 idAsign = this.listaTokens[this.numPreanalisis - 1].getLexema();284 columnAsign = this.listaTokens[this.numPreanalisis - 1].getColumna();285 if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_IGUAL) {286 this.match(Token_1.Tipo.SIGNO_IGUAL);287 this.EXPRESSION();288 return new Asignation_1.Asignation(idAsign, this.expresion, true, columnAsign);289 }290 else if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_POS_INCREMENTO) {291 this.match(Token_1.Tipo.SIGNO_POS_INCREMENTO);292 return new Identifier_1.Identifier(idAsign, null, Types_1.Type_Operation.POS_INCREMENTO, false, columnAsign);293 }294 else if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_POS_DECREMENTO) {295 this.match(Token_1.Tipo.SIGNO_POS_DECREMENTO);296 return new Identifier_1.Identifier(idAsign, null, Types_1.Type_Operation.POS_DECREMENTO, false, columnAsign);297 }298 else {299 /** ERROR **/300 if (this.errorSintactico == false) {301 //console.log(">> Error sintactico se esperaba [ =, ++, -- ] en lugar de [" + this.preanalisis.getTipoEnString() + ", " + this.preanalisis.getLexema() + "]");302 this.addTokenError(this.preanalisis.getLexema(), "Se esperaba =, ++, --", this.preanalisis.getFila(), this.preanalisis.getColumna());303 this.errorSintactico = true;304 this.match(Token_1.Tipo.PUNTO_Y_COMA);305 }306 else {307 this.match(Token_1.Tipo.PUNTO_Y_COMA);308 }309 return new Declaration_1.Declaration("", [], 0);310 }311 }312 ASIGNATION_LOCAL() {313 this.match(Token_1.Tipo.IDENTIFICADOR);314 return this.ASIGNATION_LOCAL_P();315 }316 ASIGNATION_LOCAL_P() {317 /********************************/318 let idAsign = "";319 let columnAsign = 0;320 /********************************/321 idAsign = this.listaTokens[this.numPreanalisis - 1].getLexema();322 columnAsign = this.listaTokens[this.numPreanalisis - 1].getColumna();323 if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_IGUAL || this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_POS_INCREMENTO324 || this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_POS_DECREMENTO) {325 return this.ASIGNATION_P();326 }327 else if (this.preanalisis.getTipo() == Token_1.Tipo.PARENTESIS_IZQ) {328 this.match(Token_1.Tipo.PARENTESIS_IZQ);329 this.LIST_PARAMETROS_EXPRESSION();330 this.match(Token_1.Tipo.PARENTESIS_DER);331 return new Identifier_1.Identifier(idAsign, this.expresion, Types_1.Type_Operation.LLAMADA_METODO, true, columnAsign);332 }333 else {334 /** ERROR **/335 if (this.errorSintactico == false) {336 //console.log(">> Error sintactico se esperaba [ =, ++, --, ( ] en lugar de [" + this.preanalisis.getTipoEnString() + ", " + this.preanalisis.getLexema() + "]");337 this.addTokenError(this.preanalisis.getLexema(), "Se esperaba =, ++, --, (", this.preanalisis.getFila(), this.preanalisis.getColumna());338 this.errorSintactico = true;339 this.match(Token_1.Tipo.PUNTO_Y_COMA);340 }341 else {342 this.match(Token_1.Tipo.PUNTO_Y_COMA);343 }344 return new Declaration_1.Declaration("", [], 0);345 }346 }347 LIST_PARAMETROS_EXPRESSION() {348 if (this.preanalisis.getTipo() == Token_1.Tipo.NUMERO_ENTERO || this.preanalisis.getTipo() == Token_1.Tipo.NUMERO_DECIMAL349 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_FALSE || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_TRUE350 || this.preanalisis.getTipo() == Token_1.Tipo.CADENA_STRING || this.preanalisis.getTipo() == Token_1.Tipo.CADENA_CHAR351 || this.preanalisis.getTipo() == Token_1.Tipo.IDENTIFICADOR || this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_MENOS352 || this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_NOT || this.preanalisis.getTipo() == Token_1.Tipo.PARENTESIS_IZQ) {353 this.EXPRESSIONS();354 }355 }356 EXPRESSIONS() {357 this.EXPRESSION();358 this.EXPRESSIONS_P();359 }360 EXPRESSIONS_P() {361 if (this.preanalisis.getTipo() == Token_1.Tipo.COMA) {362 this.expresion += " " + this.preanalisis.getLexema();363 this.match(Token_1.Tipo.COMA);364 this.EXPRESSION();365 this.EXPRESSIONS_P();366 }367 }368 /***********************************************************************************/369 METHOD() {370 this.match(Token_1.Tipo.RESERVADA_PUBLIC);371 return this.METHOD_P();372 }373 METHOD_P() {374 /********************************/375 let columnMethod = 0;376 let tipo = "";377 let idMethod = "";378 /********************************/379 columnMethod = this.listaTokens[this.numPreanalisis - 1].getColumna();380 if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_STATIC) {381 this.match(Token_1.Tipo.RESERVADA_STATIC);382 this.match(Token_1.Tipo.RESERVADA_VOID);383 this.match(Token_1.Tipo.RESERVADA_MAIN);384 this.match(Token_1.Tipo.PARENTESIS_IZQ);385 this.match(Token_1.Tipo.RESERVADA_STRING);386 this.match(Token_1.Tipo.CORCHETE_IZQ);387 this.match(Token_1.Tipo.CORCHETE_DER);388 this.match(Token_1.Tipo.RESERVADA_ARGS);389 this.match(Token_1.Tipo.PARENTESIS_DER);390 this.BLOQUE_SENTENCIAS();391 return new Method_1.Method("public", "void", "main", null, this.lista_Sentencias, columnMethod);392 }393 else {394 tipo = this.preanalisis.getLexema();395 this.TYPE_METHOD();396 idMethod = this.preanalisis.getLexema();397 this.match(Token_1.Tipo.IDENTIFICADOR);398 this.match(Token_1.Tipo.PARENTESIS_IZQ);399 this.LIST_PARAMETROS();400 this.match(Token_1.Tipo.PARENTESIS_DER);401 this.BLOQUE_SENTENCIAS();402 return new Method_1.Method("public", tipo, idMethod, this.lista_Parametros, this.lista_Sentencias, columnMethod);403 }404 }405 TYPE_METHOD() {406 if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_VOID) {407 this.match(Token_1.Tipo.RESERVADA_VOID);408 }409 else {410 this.TYPE_DATA();411 }412 }413 LIST_PARAMETROS() {414 if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_INT || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_BOOLEAN415 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_DOUBLE || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_STRING416 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_CHAR) {417 this.PARAMETROS();418 }419 }420 PARAMETROS() {421 /*********************/422 let parametro;423 /*********************/424 parametro = this.PARAMETRO();425 this.lista_Parametros.push(parametro);426 this.PARAMETROS_P();427 }428 PARAMETROS_P() {429 /*********************/430 let parametro;431 /*********************/432 if (this.preanalisis.getTipo() == Token_1.Tipo.COMA) {433 this.match(Token_1.Tipo.COMA);434 parametro = this.PARAMETRO();435 this.lista_Parametros.push(parametro);436 this.PARAMETROS_P();437 }438 }439 PARAMETRO() {440 /***************************/441 let tipo = "";442 let idParameter = "";443 /***************************/444 tipo = this.preanalisis.getLexema();445 this.TYPE_DATA();446 idParameter = this.preanalisis.getLexema();447 this.match(Token_1.Tipo.IDENTIFICADOR);448 return new Parameter_1.Parameter(tipo, idParameter);449 }450 BLOQUE_SENTENCIAS() {451 if (this.preanalisis.getTipo() == Token_1.Tipo.LLAVE_IZQ) {452 this.match(Token_1.Tipo.LLAVE_IZQ);453 this.LIST_SENTENCIAS();454 this.match(Token_1.Tipo.LLAVE_DER);455 }456 else {457 /** ERROR **/458 if (this.errorSintactico == false) {459 //console.log(">> Error sintactico se esperaba [ { ] en lugar de [" + this.preanalisis.getTipoEnString() + ", " + this.preanalisis.getLexema() + "]");460 this.addTokenError(this.preanalisis.getLexema(), "Se esperaba {", this.preanalisis.getFila(), this.preanalisis.getColumna());461 this.errorSintactico = true;462 this.match(Token_1.Tipo.PUNTO_Y_COMA);463 }464 else {465 this.match(Token_1.Tipo.PUNTO_Y_COMA);466 }467 }468 }469 /***********************************************************************************/470 LIST_SENTENCIAS() {471 /*****************************/472 var sentencia_l;473 /*****************************/474 if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_INT || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_BOOLEAN475 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_DOUBLE || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_STRING476 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_CHAR || this.preanalisis.getTipo() == Token_1.Tipo.IDENTIFICADOR477 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_FOR || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_WHILE478 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_DO || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_IF479 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_RETURN || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_SYSTEM) {480 sentencia_l = this.SENTENCIAS();481 /*****************************/482 this.lista_Sentencias.push(sentencia_l);483 /*****************************/484 this.LIST_SENTENCIAS();485 }486 }487 SENTENCIAS() {488 /*****************************/489 var sentencia_l;490 /*****************************/491 if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_INT || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_BOOLEAN492 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_DOUBLE || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_STRING493 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_CHAR) {494 sentencia_l = this.DECLARATION();495 this.lista_Decla_Asign = [];496 this.match(Token_1.Tipo.PUNTO_Y_COMA);497 }498 else if (this.preanalisis.getTipo() == Token_1.Tipo.IDENTIFICADOR) {499 sentencia_l = this.ASIGNATION_LOCAL();500 /******************/501 this.expresion = "";502 /******************/503 this.match(Token_1.Tipo.PUNTO_Y_COMA);504 }505 else if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_FOR) {506 this.FOR();507 sentencia_l = new Return_Continue_Break_1.Return_Continue_Break("", null, false, 1);508 }509 else if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_WHILE) {510 sentencia_l = this.WHILE();511 this.lista_Bloque_Ciclo = [];512 this.expresion = "";513 }514 else if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_DO) {515 this.DO_WHILE();516 sentencia_l = new Return_Continue_Break_1.Return_Continue_Break("", null, false, 1);517 }518 else if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_IF) {519 this.IF();520 sentencia_l = new Return_Continue_Break_1.Return_Continue_Break("", null, false, 1);521 }522 else if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_RETURN) {523 sentencia_l = this.RETURN();524 this.expresion = "";525 }526 else if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_SYSTEM) {527 sentencia_l = this.PRINT();528 this.expresion = "";529 }530 return sentencia_l;531 }532 /***********************************************************************************/533 FOR() {534 this.match(Token_1.Tipo.RESERVADA_FOR);535 this.match(Token_1.Tipo.PARENTESIS_IZQ);536 this.DECLARATION();537 this.match(Token_1.Tipo.PUNTO_Y_COMA);538 this.EXPRESSION();539 this.match(Token_1.Tipo.PUNTO_Y_COMA);540 this.EXPRESSION();541 this.match(Token_1.Tipo.PARENTESIS_DER);542 this.BLOQUE_CICLO();543 }544 BLOQUE_CICLO() {545 this.match(Token_1.Tipo.LLAVE_IZQ);546 this.BLOQUE_CICLO_P();547 this.match(Token_1.Tipo.LLAVE_DER);548 }549 BLOQUE_CICLO_P() {550 if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_INT || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_BOOLEAN551 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_DOUBLE || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_STRING552 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_CHAR || this.preanalisis.getTipo() == Token_1.Tipo.IDENTIFICADOR553 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_FOR || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_WHILE554 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_DO || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_IF555 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_RETURN || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_SYSTEM556 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_BREAK || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_CONTINUE) {557 this.LIST_SENTENCIAS_CICLO();558 }559 }560 LIST_SENTENCIAS_CICLO() {561 /*****************************/562 var sentencia_c;563 /*****************************/564 sentencia_c = this.SENTENCIAS_CICLO();565 /*****************************/566 this.lista_Bloque_Ciclo.push(sentencia_c);567 /*****************************/568 this.LIST_SENTENCIAS_CICLO_P();569 }570 LIST_SENTENCIAS_CICLO_P() {571 /*****************************/572 var sentencia_c;573 /*****************************/574 if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_INT || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_BOOLEAN575 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_DOUBLE || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_STRING576 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_CHAR || this.preanalisis.getTipo() == Token_1.Tipo.IDENTIFICADOR577 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_FOR || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_WHILE578 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_DO || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_IF579 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_RETURN || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_SYSTEM580 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_BREAK || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_CONTINUE) {581 sentencia_c = this.SENTENCIAS_CICLO();582 /*****************************/583 this.lista_Bloque_Ciclo.push(sentencia_c);584 /*****************************/585 this.LIST_SENTENCIAS_CICLO_P();586 }587 }588 SENTENCIAS_CICLO() {589 /*********************/590 let columnS_C = 0;591 /*********************/592 columnS_C = this.preanalisis.getColumna();593 if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_INT || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_BOOLEAN594 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_DOUBLE || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_STRING595 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_CHAR || this.preanalisis.getTipo() == Token_1.Tipo.IDENTIFICADOR596 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_FOR || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_WHILE597 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_DO || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_IF598 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_RETURN || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_SYSTEM) {599 return this.SENTENCIAS();600 }601 else if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_BREAK) {602 this.match(Token_1.Tipo.RESERVADA_BREAK);603 this.match(Token_1.Tipo.PUNTO_Y_COMA);604 return new Return_Continue_Break_1.Return_Continue_Break("break", null, false, columnS_C);605 }606 else if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_CONTINUE) {607 this.match(Token_1.Tipo.RESERVADA_CONTINUE);608 this.match(Token_1.Tipo.PUNTO_Y_COMA);609 return new Return_Continue_Break_1.Return_Continue_Break("continue", null, false, columnS_C);610 }611 }612 /***********************************************************************************/613 WHILE() {614 /********************************/615 let columnWhile = 0;616 /********************************/617 columnWhile = this.preanalisis.getColumna();618 this.match(Token_1.Tipo.RESERVADA_WHILE);619 this.match(Token_1.Tipo.PARENTESIS_IZQ);620 this.EXPRESSION();621 this.match(Token_1.Tipo.PARENTESIS_DER);622 this.BLOQUE_CICLO();623 return new While_1.While(this.expresion, this.lista_Bloque_Ciclo, columnWhile);624 }625 /***********************************************************************************/626 DO_WHILE() {627 this.match(Token_1.Tipo.RESERVADA_DO);628 this.BLOQUE_CICLO();629 this.match(Token_1.Tipo.RESERVADA_WHILE);630 this.match(Token_1.Tipo.PARENTESIS_IZQ);631 this.EXPRESSION();632 this.match(Token_1.Tipo.PARENTESIS_DER);633 this.match(Token_1.Tipo.PUNTO_Y_COMA);634 }635 /***********************************************************************************/636 IF() {637 this.match(Token_1.Tipo.RESERVADA_IF);638 this.match(Token_1.Tipo.PARENTESIS_IZQ);639 this.EXPRESSION();640 this.match(Token_1.Tipo.PARENTESIS_DER);641 this.BLOQUE_CICLO();642 this.ELSE();643 }644 ELSE() {645 if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_ELSE) {646 this.match(Token_1.Tipo.RESERVADA_ELSE);647 this.ELSE_IF();648 }649 }650 ELSE_IF() {651 if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_IF) {652 this.IF();653 }654 else {655 this.BLOQUE_CICLO();656 }657 }658 /***********************************************************************************/659 RETURN() {660 /********************************/661 let columnReturn = 0;662 /********************************/663 this.match(Token_1.Tipo.RESERVADA_RETURN);664 this.RETURN_P();665 this.match(Token_1.Tipo.PUNTO_Y_COMA);666 return new Return_Continue_Break_1.Return_Continue_Break("return", this.expresion, true, columnReturn);667 }668 RETURN_P() {669 if (this.preanalisis.getTipo() == Token_1.Tipo.NUMERO_ENTERO || this.preanalisis.getTipo() == Token_1.Tipo.NUMERO_DECIMAL670 || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_FALSE || this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_TRUE671 || this.preanalisis.getTipo() == Token_1.Tipo.CADENA_STRING || this.preanalisis.getTipo() == Token_1.Tipo.CADENA_CHAR672 || this.preanalisis.getTipo() == Token_1.Tipo.IDENTIFICADOR || this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_MENOS673 || this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_NOT || this.preanalisis.getTipo() == Token_1.Tipo.PARENTESIS_IZQ) {674 this.EXPRESSION();675 }676 }677 /***********************************************************************************/678 PRINT() {679 /********************************/680 let columnPrint = 0;681 let tipoPrint = "";682 /********************************/683 columnPrint = this.preanalisis.getColumna();684 this.match(Token_1.Tipo.RESERVADA_SYSTEM);685 this.match(Token_1.Tipo.PUNTO);686 this.match(Token_1.Tipo.RESERVADA_OUT);687 this.match(Token_1.Tipo.PUNTO);688 tipoPrint = this.preanalisis.getLexema();689 this.PRINT_P();690 this.match(Token_1.Tipo.PARENTESIS_IZQ);691 this.EXPRESSION();692 this.match(Token_1.Tipo.PARENTESIS_DER);693 this.match(Token_1.Tipo.PUNTO_Y_COMA);694 return new Print_1.Print(tipoPrint, this.expresion, columnPrint);695 }696 PRINT_P() {697 if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_PRINTLN) {698 this.match(Token_1.Tipo.RESERVADA_PRINTLN);699 }700 else if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_PRINT) {701 this.match(Token_1.Tipo.RESERVADA_PRINT);702 }703 else {704 /** ERROR **/705 if (this.errorSintactico == false) {706 //console.log(">> Error sintactico se esperaba [ print, println ] en lugar de [" + this.preanalisis.getTipoEnString() + ", " + this.preanalisis.getLexema() + "]");707 this.addTokenError(this.preanalisis.getLexema(), "Se esperaba print, println", this.preanalisis.getFila(), this.preanalisis.getColumna());708 this.errorSintactico = true;709 this.match(Token_1.Tipo.PUNTO_Y_COMA);710 }711 else {712 this.match(Token_1.Tipo.PUNTO_Y_COMA);713 }714 }715 }716 /***********************************************************************************/717 EXPRESSION() {718 this.T();719 this.E_P();720 }721 E_P() {722 if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_MAS) {723 this.expresion += " " + this.preanalisis.getLexema();724 this.match(Token_1.Tipo.SIGNO_MAS);725 this.T();726 this.E_P();727 }728 else if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_MENOS) {729 this.expresion += " " + this.preanalisis.getLexema();730 this.match(Token_1.Tipo.SIGNO_MENOS);731 this.T();732 this.E_P();733 }734 }735 T() {736 this.L();737 this.T_P();738 }739 T_P() {740 if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_POR) {741 this.expresion += " " + this.preanalisis.getLexema();742 this.match(Token_1.Tipo.SIGNO_POR);743 this.L();744 this.T_P();745 }746 else if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_DIVISION) {747 this.expresion += " " + this.preanalisis.getLexema();748 this.match(Token_1.Tipo.SIGNO_DIVISION);749 this.L();750 this.T_P();751 }752 }753 L() {754 this.R();755 this.L_P();756 }757 L_P() {758 if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_AND) {759 this.expresion += " and";760 this.match(Token_1.Tipo.SIGNO_AND);761 this.R();762 this.L_P();763 }764 else if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_OR) {765 this.expresion += " or";766 this.match(Token_1.Tipo.SIGNO_OR);767 this.R();768 this.L_P();769 }770 else if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_XOR) {771 this.expresion += " xor";772 this.match(Token_1.Tipo.SIGNO_XOR);773 this.R();774 this.L_P();775 }776 }777 R() {778 this.F();779 this.R_P();780 }781 R_P() {782 if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_MENOR_QUE) {783 this.expresion += " " + this.preanalisis.getLexema();784 this.match(Token_1.Tipo.SIGNO_MENOR_QUE);785 this.F();786 this.R_P();787 }788 else if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_MAYOR_QUE) {789 this.expresion += " " + this.preanalisis.getLexema();790 this.match(Token_1.Tipo.SIGNO_MAYOR_QUE);791 this.F();792 this.R_P();793 }794 else if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_MENOR_IGUAL_QUE) {795 this.expresion += " " + this.preanalisis.getLexema();796 this.match(Token_1.Tipo.SIGNO_MENOR_IGUAL_QUE);797 this.F();798 this.R_P();799 }800 else if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_MAYOR_IGUAL_QUE) {801 this.expresion += " " + this.preanalisis.getLexema();802 this.match(Token_1.Tipo.SIGNO_MAYOR_IGUAL_QUE);803 this.F();804 this.R_P();805 }806 else if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_DOBLE_IGUAL) {807 this.expresion += " " + this.preanalisis.getLexema();808 this.match(Token_1.Tipo.SIGNO_DOBLE_IGUAL);809 this.F();810 this.R_P();811 }812 else if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_DIFERENTE_DE) {813 this.expresion += " " + this.preanalisis.getLexema();814 this.match(Token_1.Tipo.SIGNO_DIFERENTE_DE);815 this.F();816 this.R_P();817 }818 }819 F() {820 if (this.preanalisis.getTipo() == Token_1.Tipo.PARENTESIS_IZQ) {821 this.expresion += " " + this.preanalisis.getLexema();822 this.match(Token_1.Tipo.PARENTESIS_IZQ);823 this.EXPRESSION();824 this.expresion += " " + this.preanalisis.getLexema();825 this.match(Token_1.Tipo.PARENTESIS_DER);826 }827 else if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_NOT) {828 this.expresion += " not";829 this.match(Token_1.Tipo.SIGNO_NOT);830 this.EXPRESSION();831 }832 else if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_MENOS) {833 this.expresion += " " + this.preanalisis.getLexema();834 this.match(Token_1.Tipo.SIGNO_MENOS);835 this.EXPRESSION();836 }837 else {838 this.PRIMITIVO();839 }840 }841 PRIMITIVO() {842 if (this.preanalisis.getTipo() == Token_1.Tipo.NUMERO_ENTERO) {843 this.expresion += " " + this.preanalisis.getLexema();844 this.match(Token_1.Tipo.NUMERO_ENTERO);845 }846 else if (this.preanalisis.getTipo() == Token_1.Tipo.NUMERO_DECIMAL) {847 this.expresion += " " + this.preanalisis.getLexema();848 this.match(Token_1.Tipo.NUMERO_DECIMAL);849 }850 else if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_FALSE) {851 this.expresion += " False";852 this.match(Token_1.Tipo.RESERVADA_FALSE);853 }854 else if (this.preanalisis.getTipo() == Token_1.Tipo.RESERVADA_TRUE) {855 this.expresion += " True";856 this.match(Token_1.Tipo.RESERVADA_TRUE);857 }858 else if (this.preanalisis.getTipo() == Token_1.Tipo.CADENA_STRING) {859 this.expresion += " " + this.preanalisis.getLexema();860 this.match(Token_1.Tipo.CADENA_STRING);861 }862 else if (this.preanalisis.getTipo() == Token_1.Tipo.CADENA_CHAR) {863 this.expresion += " " + this.preanalisis.getLexema();864 this.match(Token_1.Tipo.CADENA_CHAR);865 }866 else if (this.preanalisis.getTipo() == Token_1.Tipo.IDENTIFICADOR) {867 this.expresion += " " + this.preanalisis.getLexema();868 this.match(Token_1.Tipo.IDENTIFICADOR);869 this.INC_DEC_CALL_METHOD();870 }871 else {872 /** ERROR **/873 if (this.errorSintactico == false) {874 //console.log(">> Error sintactico se esperaba [ Primitivo ] en lugar de [" + this.preanalisis.getTipoEnString() + ", " + this.preanalisis.getLexema() + "]");875 this.addTokenError(this.preanalisis.getLexema(), "Se esperaba Primitivo", this.preanalisis.getFila(), this.preanalisis.getColumna());876 this.errorSintactico = true;877 this.match(Token_1.Tipo.PUNTO_Y_COMA);878 }879 else {880 this.match(Token_1.Tipo.PUNTO_Y_COMA);881 }882 }883 }884 INC_DEC_CALL_METHOD() {885 if (this.preanalisis.getTipo() == Token_1.Tipo.PARENTESIS_IZQ) {886 this.expresion += " " + this.preanalisis.getLexema();887 this.match(Token_1.Tipo.PARENTESIS_IZQ);888 this.LIST_PARAMETROS_EXPRESSION();889 this.expresion += " " + this.preanalisis.getLexema();890 this.match(Token_1.Tipo.PARENTESIS_DER);891 }892 else if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_POS_INCREMENTO) {893 this.expresion += " += 1";894 this.match(Token_1.Tipo.SIGNO_POS_INCREMENTO);895 }896 else if (this.preanalisis.getTipo() == Token_1.Tipo.SIGNO_POS_DECREMENTO) {897 this.expresion += " -= 1";898 this.match(Token_1.Tipo.SIGNO_POS_DECREMENTO);899 }900 }901 /***********************************************************************************/902 match(p) {903 if (this.preanalisis.getTipo() == Token_1.Tipo.COMENTARIO_BLOQUE || this.preanalisis.getTipo() == Token_1.Tipo.COMENTARIO_LINEA) {904 while (this.preanalisis.getTipo() == Token_1.Tipo.COMENTARIO_BLOQUE || this.preanalisis.getTipo() == Token_1.Tipo.COMENTARIO_LINEA) {905 this.numPreanalisis += 1;906 this.preanalisis = this.listaTokens[this.numPreanalisis];907 }908 }909 if (this.errorSintactico) {910 if (this.numPreanalisis < this.listaTokens.length - 1) {911 if (this.preanalisis.getTipo() == Token_1.Tipo.PUNTO_Y_COMA || this.preanalisis.getTipo() == Token_1.Tipo.LLAVE_DER) {912 if (p == Token_1.Tipo.PUNTO_Y_COMA) {913 this.errorSintactico = false;914 this.numPreanalisis += 1;915 this.preanalisis = this.listaTokens[this.numPreanalisis];916 }917 else if (p == Token_1.Tipo.LLAVE_DER) {918 this.errorSintactico = false;919 this.numPreanalisis += 1;920 this.preanalisis = this.listaTokens[this.numPreanalisis];921 }922 while (this.preanalisis.getTipo() == Token_1.Tipo.COMENTARIO_BLOQUE || this.preanalisis.getTipo() == Token_1.Tipo.COMENTARIO_LINEA) {923 this.numPreanalisis += 1;924 this.preanalisis = this.listaTokens[this.numPreanalisis];925 }926 }927 else {928 while (this.preanalisis.getTipo() == Token_1.Tipo.COMENTARIO_BLOQUE || this.preanalisis.getTipo() == Token_1.Tipo.COMENTARIO_LINEA) {929 this.numPreanalisis += 1;930 this.preanalisis = this.listaTokens[this.numPreanalisis];931 }932 this.numPreanalisis += 1;933 this.preanalisis = this.listaTokens[this.numPreanalisis];934 }935 }936 else {937 //console.log("Ya no se pudo recuperar :(");938 this.addTokenError("", "Ya no se pudo recuperar :(", 0, 0);939 }940 }941 else {942 if (this.preanalisis.getTipo() == p) {943 if (this.numPreanalisis < this.listaTokens.length) //llevaba un -1944 {945 this.numPreanalisis += 1;946 this.preanalisis = this.listaTokens[this.numPreanalisis];947 while (this.preanalisis.getTipo() == Token_1.Tipo.COMENTARIO_BLOQUE || this.preanalisis.getTipo() == Token_1.Tipo.COMENTARIO_LINEA) {948 this.numPreanalisis += 1;949 this.preanalisis = this.listaTokens[this.numPreanalisis];950 }951 }952 }953 else {954 //console.log(">> Error sintactico se esperaba [" + this.getTipoParaError(p) + "] en lugar de [" + this.preanalisis.getTipoEnString() + ", " + this.preanalisis.getLexema() + "]");955 this.addTokenError(this.preanalisis.getLexema(), "Se esperaba " + this.getTipoParaError(p), this.preanalisis.getFila(), this.preanalisis.getColumna());956 this.errorSintactico = true;957 }958 }959 }960 getTipoParaError(p) {961 switch (p) {962 case Token_1.Tipo.RESERVADA_ARGS:963 return "Reservada_Args";964 case Token_1.Tipo.RESERVADA_BOOLEAN:965 return "Reservada_Boolean";966 case Token_1.Tipo.RESERVADA_BREAK:967 return "Reservada_Break";968 case Token_1.Tipo.RESERVADA_CHAR:969 return "Reservada_Char";970 case Token_1.Tipo.RESERVADA_CLASS:971 return "Reservada_Class";972 case Token_1.Tipo.RESERVADA_CONTINUE:973 return "Reservada_Continue";974 case Token_1.Tipo.RESERVADA_DO:975 return "Reservada_Do";976 case Token_1.Tipo.RESERVADA_DOUBLE:977 return "Reservada_Double";978 case Token_1.Tipo.RESERVADA_ELSE:979 return "Reservada_Else";980 case Token_1.Tipo.RESERVADA_FALSE:981 return "Reservada_False";982 case Token_1.Tipo.RESERVADA_FOR:983 return "Reservada_For";984 case Token_1.Tipo.RESERVADA_IF:985 return "Reservada_If";986 case Token_1.Tipo.RESERVADA_INT:987 return "Reservada_Int";988 case Token_1.Tipo.RESERVADA_INTERFACE:989 return "Reservada_Interface";990 case Token_1.Tipo.RESERVADA_MAIN:991 return "Reservada_Main";992 case Token_1.Tipo.RESERVADA_OUT:993 return "Reservada_Out";994 case Token_1.Tipo.RESERVADA_PRINT:995 return "Reservada_Print";996 case Token_1.Tipo.RESERVADA_PRINTLN:997 return "Reservada_PrintLn";998 case Token_1.Tipo.RESERVADA_PUBLIC:999 return "Reservada_Public";1000 case Token_1.Tipo.RESERVADA_RETURN:1001 return "Reservada_Return";1002 case Token_1.Tipo.RESERVADA_STATIC:1003 return "Reservada_Static";1004 case Token_1.Tipo.RESERVADA_STRING:1005 return "Reservada_String";1006 case Token_1.Tipo.RESERVADA_SYSTEM:1007 return "Reservada_System";1008 case Token_1.Tipo.RESERVADA_TRUE:1009 return "Reservada_True";1010 case Token_1.Tipo.RESERVADA_VOID:1011 return "Reservada_Void";1012 case Token_1.Tipo.RESERVADA_WHILE:1013 return "Reservada_While";1014 case Token_1.Tipo.IDENTIFICADOR:1015 return "Identificador";1016 case Token_1.Tipo.CADENA_STRING:1017 return "Cadena_String";1018 case Token_1.Tipo.CADENA_CHAR:1019 return "Cadena_Char";1020 case Token_1.Tipo.COMENTARIO_LINEA:1021 return "Comentario_Linea";1022 case Token_1.Tipo.COMENTARIO_BLOQUE:1023 return "Comentario_Bloque";1024 case Token_1.Tipo.NUMERO_ENTERO:1025 return "NumeroEntero";1026 case Token_1.Tipo.NUMERO_DECIMAL:1027 return "Numero_Decimal";1028 case Token_1.Tipo.LLAVE_IZQ:1029 return "Llave_Izquierda";1030 case Token_1.Tipo.LLAVE_DER:1031 return "Llave_Derecha";1032 case Token_1.Tipo.COMA:1033 return "Coma";1034 case Token_1.Tipo.PUNTO:1035 return "Punto";1036 case Token_1.Tipo.PUNTO_Y_COMA:1037 return "PuntoYcoma";1038 case Token_1.Tipo.CORCHETE_IZQ:1039 return "Corchete_Izquierdo";1040 case Token_1.Tipo.CORCHETE_DER:1041 return "Corchete_Derecho";1042 case Token_1.Tipo.PARENTESIS_IZQ:1043 return "Parentesis_Izquierdo";1044 case Token_1.Tipo.PARENTESIS_DER:1045 return "Parentesis_Derecho";1046 case Token_1.Tipo.SIGNO_MAS:1047 return "Signo_Mas";1048 case Token_1.Tipo.SIGNO_MENOS:1049 return "Signo_Menos";1050 case Token_1.Tipo.SIGNO_POR:1051 return "Signo_Por";1052 case Token_1.Tipo.SIGNO_DIVISION:1053 return "Signo_Division";1054 case Token_1.Tipo.SIGNO_MENOR_QUE:1055 return "Signo_MenorQue";1056 case Token_1.Tipo.SIGNO_MAYOR_QUE:1057 return "Signo_MayorQue";1058 case Token_1.Tipo.SIGNO_DIFERENTE_DE:1059 return "Signo_DiferenteDe";1060 case Token_1.Tipo.SIGNO_POS_INCREMENTO:1061 return "Signo_PosIncremento";1062 case Token_1.Tipo.SIGNO_POS_DECREMENTO:1063 return "Signo_PosDecremento";1064 case Token_1.Tipo.SIGNO_MAYOR_IGUAL_QUE:1065 return "Signo_MayorIgualQue";1066 case Token_1.Tipo.SIGNO_MENOR_IGUAL_QUE:1067 return "Signo_MenorIgualQue";1068 case Token_1.Tipo.SIGNO_IGUAL:1069 return "Signo_Igual";1070 case Token_1.Tipo.SIGNO_DOBLE_IGUAL:1071 return "Signo_DobleIgual";1072 case Token_1.Tipo.SIGNO_AND:1073 return "Signo_AND";1074 case Token_1.Tipo.SIGNO_OR:1075 return "Signo_OR";1076 case Token_1.Tipo.SIGNO_NOT:1077 return "Signo_NOT";1078 case Token_1.Tipo.SIGNO_XOR:1079 return "Signo_XOR";1080 case Token_1.Tipo.ULTIMO:1081 return "Ultimo";1082 default:1083 return "Desconocido";1084 }1085 }1086 getListaErrores() {1087 return this.listaErrores;1088 }1089 addTokenError(caracter, descripcion, fila, columna) {1090 this.listaErrores.push(new Token_Error_1.Token_Error(caracter, Token_Error_1.TipoError.SINTACTICO, descripcion, fila, columna));1091 }1092}...

Full Screen

Full Screen

Lexer.js

Source:Lexer.js Github

copy

Full Screen

1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3var Token_1 = require("./Token");4var Alert_1 = require("./Alert");5var Lexer = /** @class */ (function () {6 function Lexer() {7 this.lineNum = 1;8 }9 Lexer.prototype.lex = function (src) {10 //Break text into blobs to perform longest match on11 //filter out undefined blobs12 var tokenBlobs = src.split(Token_1.TokenRegex.Split).filter(function (defined) { return defined; });13 var tokens = [];14 var result = { t: null, e: null };15 for (var i = 0; i < tokenBlobs.length; i++) {16 var blob = tokenBlobs[i];17 //If a comment or whitespace just skip18 if (blob.match(Token_1.TokenRegex.Comment) || blob.match(Token_1.TokenRegex.WhiteSpace)) {19 //If newline is found increment lineNum but skip20 if (blob.match("\n")) {21 this.lineNum += 1;22 }23 continue;24 }25 result = this.longestMatch(blob, this.lineNum);26 if (result.t) {27 for (var _i = 0, _a = result.t; _i < _a.length; _i++) {28 var t = _a[_i];29 tokens.push(t);30 }31 }32 //It's possible to have valid tokens returned along with an error33 if (result.e) {34 //Keep the lineNum for future programs (in the same file..)35 for (var j = i; j < tokenBlobs.length; j++) {36 if (tokenBlobs[j].match("\n")) {37 this.lineNum += 1;38 }39 }40 break;41 }42 }43 //If we have no errors, check if EOP is missing. No need if there are other lex errors44 if (result.e === null) {45 if (tokens.length == 0 || tokens[tokens.length - 1].kind != Token_1.TokenType.EOP) {46 tokens.push(new Token_1.Token(Token_1.TokenType.EOP, "$", this.lineNum));47 result.e = Alert_1.warning("End of Program missing. Added $ symbol.");48 }49 }50 return { t: tokens, e: result.e };51 };52 Lexer.prototype.longestMatch = function (blob, lineNum) {53 if (Token_1.TokenRegex.Quote.test(blob)) {54 //Break "quoted" blob into characters after removing comments55 var noComment = blob.replace(/\/\*.*\*\//g, "");56 var splitQuote = noComment.split("");57 var tokenArray = [];58 for (var _i = 0, splitQuote_1 = splitQuote; _i < splitQuote_1.length; _i++) {59 var char = splitQuote_1[_i];60 //If it's a quote simply add that token61 if (char === "\"") {62 tokenArray.push(new Token_1.Token(Token_1.TokenType.Quote, char, lineNum));63 }64 else if (char.match(/[a-z]/) || char.match(/\s/)) {65 //If it's a new line, accurately report it66 if (char.match("\n")) {67 return { t: tokenArray, e: this.multiLineStringError(lineNum) };68 }69 //If it's a letter or space add that token70 tokenArray.push(new Token_1.Token(Token_1.TokenType.Char, char, lineNum));71 }72 else {73 //"quoted" may only contain valid lexemes (chars)74 return { t: tokenArray, e: this.unknownTokenError(char, lineNum) };75 }76 }77 return { t: tokenArray, e: null };78 }79 else if (Token_1.TokenRegex.While.test(blob)) {80 return { t: [new Token_1.Token(Token_1.TokenType.While, blob, lineNum)], e: null };81 }82 else if (Token_1.TokenRegex.Print.test(blob)) {83 return { t: [new Token_1.Token(Token_1.TokenType.Print, blob, lineNum)], e: null };84 }85 else if (Token_1.TokenRegex.EOP.test(blob)) {86 return { t: [new Token_1.Token(Token_1.TokenType.EOP, blob, lineNum)], e: null };87 }88 else if (Token_1.TokenRegex.VarType.test(blob)) {89 return { t: [new Token_1.Token(Token_1.TokenType.VarType, blob, lineNum)], e: null };90 }91 else if (Token_1.TokenRegex.If.test(blob)) {92 return { t: [new Token_1.Token(Token_1.TokenType.If, blob, lineNum)], e: null };93 }94 else if (Token_1.TokenRegex.BoolLiteral.test(blob)) {95 return { t: [new Token_1.Token(Token_1.TokenType.BoolLiteral, blob, lineNum)], e: null };96 }97 else if (Token_1.TokenRegex.Id.test(blob)) {98 return { t: [new Token_1.Token(Token_1.TokenType.Id, blob, lineNum)], e: null };99 }100 else if (Token_1.TokenRegex.Digit.test(blob)) {101 return { t: [new Token_1.Token(Token_1.TokenType.Digit, blob, lineNum)], e: null };102 }103 else if (Token_1.TokenRegex.Assign.test(blob)) {104 return { t: [new Token_1.Token(Token_1.TokenType.Assign, blob, lineNum)], e: null };105 }106 else if (Token_1.TokenRegex.IntOp.test(blob)) {107 return { t: [new Token_1.Token(Token_1.TokenType.IntOp, blob, lineNum)], e: null };108 }109 else if (Token_1.TokenRegex.BoolOp.test(blob)) {110 return { t: [new Token_1.Token(Token_1.TokenType.BoolOp, blob, lineNum)], e: null };111 }112 else if (Token_1.TokenRegex.LParen.test(blob)) {113 return { t: [new Token_1.Token(Token_1.TokenType.LParen, blob, lineNum)], e: null };114 }115 else if (Token_1.TokenRegex.RParen.test(blob)) {116 return { t: [new Token_1.Token(Token_1.TokenType.RParen, blob, lineNum)], e: null };117 }118 else if (Token_1.TokenRegex.LBracket.test(blob)) {119 return { t: [new Token_1.Token(Token_1.TokenType.LBracket, blob, lineNum)], e: null };120 }121 else if (Token_1.TokenRegex.RBracket.test(blob)) {122 return { t: [new Token_1.Token(Token_1.TokenType.RBracket, blob, lineNum)], e: null };123 }124 else {125 //Blob did not match any valid tokens, but may contain valid tokens126 //ex: intx -> [int, x]127 //Check match for keywords128 if (blob.match(Token_1.TokenRegex.Keywords)) {129 //If there are keywords, split string by them and longest match the result130 var splitBlob = blob.split(Token_1.TokenRegex.Keywords)131 .filter(function (def) { return def; });132 var tokenArray = [];133 var result = { t: null, e: null };134 for (var _a = 0, splitBlob_1 = splitBlob; _a < splitBlob_1.length; _a++) {135 var b = splitBlob_1[_a];136 //Longest match on new string137 var result_1 = this.longestMatch(b, lineNum);138 //If there is no error, keep this token and proceed139 if (result_1.t) {140 for (var _b = 0, _c = result_1.t; _b < _c.length; _b++) {141 var t = _c[_b];142 tokenArray.push(t);143 }144 }145 else {146 break;147 }148 }149 return { t: tokenArray, e: result.e };150 }151 else {152 //If the blob doesn't contain any keywords and reached here it must not be valid153 return { t: null, e: this.unknownTokenError(blob, lineNum) };154 }155 }156 };157 Lexer.prototype.unknownTokenError = function (blob, lineNum) {158 return Alert_1.error("Unknown token " + blob.trim(), lineNum);159 };160 Lexer.prototype.multiLineStringError = function (lineNum) {161 return Alert_1.error("Multiline strings not allowed, found", lineNum);162 };163 return Lexer;164}());...

Full Screen

Full Screen

update_logic.js

Source:update_logic.js Github

copy

Full Screen

1const { ONE, formatRate, parseRate } = require('@aragon/ppf.js')2const { assertRevert } = require('@aragon/test-helpers/assertThrow')3const priceData = require('./data/prices')4const PPF = artifacts.require('PPFNoSigMock')5contract('PPF, update logic', () => {6 const TOKEN_1 = '0x1234'7 const TOKEN_2 = '0x5678'8 const TOKEN_3 = '0xabcd'9 const SIG = '0x' + '00'.repeat(65) // sig full of 0s10 const assertBig = (x, c, s = 'formatRateber') => {11 assert.equal(parseRate(x), c.toFixed(4), `${s} should have matched`)12 }13 beforeEach(async () => {14 this.ppf = await PPF.new()15 })16 context('update:', () => {17 it('rate is 0 before an update', async () => {18 const [rate, when] = await this.ppf.get.call(TOKEN_1, TOKEN_2)19 assert.equal(rate, 0, 'rate should be 0')20 assert.equal(when, 0, 'when should be 0')21 })22 it('updates feed', async () => {23 const XRT = 224 await this.ppf.update(TOKEN_1, TOKEN_2, formatRate(XRT), 1, SIG)25 const [rate, when1] = await this.ppf.get.call(TOKEN_1, TOKEN_2)26 const [inverseRate, when2] = await this.ppf.get.call(TOKEN_2, TOKEN_1)27 assertBig(rate, XRT, 'rate')28 assertBig(inverseRate, 1/XRT, 'inverse rate')29 assert.equal(when1.toString(), when2.toString(), 'updates must match')30 assert.equal(when1, 1, 'update should be 1')31 })32 it('updates feed inversely', async () => {33 await this.ppf.update(TOKEN_2, TOKEN_1, formatRate(1/3), 1, SIG)34 const [rate, when1] = await this.ppf.get.call(TOKEN_1, TOKEN_2)35 const [inverseRate, when2] = await this.ppf.get.call(TOKEN_2, TOKEN_1)36 assertBig(rate, 3, 'rate')37 assertBig(inverseRate, 0.3333, 'inverse rate')38 })39 it('can update many pairs', async () => {40 await this.ppf.update(TOKEN_1, TOKEN_2, formatRate(1), 1, SIG)41 await this.ppf.update(TOKEN_2, TOKEN_3, formatRate(2), 2, SIG)42 await this.ppf.update(TOKEN_1, TOKEN_3, formatRate(3), 3, SIG)43 44 const [rate1, when1] = await this.ppf.get.call(TOKEN_2, TOKEN_1)45 const [rate2, when2] = await this.ppf.get.call(TOKEN_3, TOKEN_2)46 const [rate3, when3] = await this.ppf.get.call(TOKEN_3, TOKEN_1)47 assert.equal(when1, 1)48 assert.equal(when2, 2)49 assert.equal(when3, 3)50 assertBig(rate1, 1)51 assertBig(rate2, 1/2)52 assertBig(rate3, 1/3)53 })54 it('supports CMC price data', async () => {55 const USD = '0xff'56 const tokenAddress = i => `0xee${i}`57 for (const [i, {price}] of priceData.entries()) {58 await this.ppf.update(tokenAddress(i), USD, formatRate(price), 1, SIG)59 60 const [rate] = await this.ppf.get.call(tokenAddress(i), USD)61 assertBig(rate, price)62 const [inverseRate] = await this.ppf.get.call(USD, tokenAddress(i))63 assertBig(inverseRate, 1/price)64 }65 })66 it('supports inverse CMC price data', async () => {67 const USD = '0xff'68 const tokenAddress = i => `0xee${i}`69 for (const [i, {price}] of priceData.entries()) {70 await this.ppf.update(USD, tokenAddress(i), formatRate(1/price), 1, SIG)71 72 const [rate] = await this.ppf.get.call(tokenAddress(i), USD)73 assertBig(rate, price)74 const [inverseRate] = await this.ppf.get.call(USD, tokenAddress(i))75 assertBig(inverseRate, 1/price)76 }77 })78 })79 context('update-checks:', () => {80 it('fails if base equals quote', async () => {81 await assertRevert(() => {82 return this.ppf.update(TOKEN_1, TOKEN_1, formatRate(2), 1, SIG)83 })84 // Assert that the rate is 1 if quote == base even if update reverts85 const [ rate ] = await this.ppf.get.call(TOKEN_1, TOKEN_1)86 assertBig(rate, 1)87 })88 it('fails if updating with past value', async () => {89 await this.ppf.update(TOKEN_1, TOKEN_2, formatRate(2), 5, SIG)90 await this.ppf.update(TOKEN_1, TOKEN_3, formatRate(2), 4, SIG) // can update another pair91 92 await assertRevert(() => {93 return this.ppf.update(TOKEN_2, TOKEN_1, formatRate(3), 4, SIG) // fails with a present pair94 })95 })96 it('fails if updating to a time in the future', async () => {97 await assertRevert(() => {98 return this.ppf.update(TOKEN_1, TOKEN_2, formatRate(3), 100+parseInt(+new Date()/1000), SIG)99 })100 })101 it('fails if xrt is 0', async () => {102 await this.ppf.update(TOKEN_1, TOKEN_2, 1, 5, SIG) // can set very low value103 await assertRevert(() => {104 return this.ppf.update(TOKEN_1, TOKEN_2, 0, 6, SIG) // fails on 0105 })106 })107 })108 context('updateMany-checks', () => {109 const tests = [110 {111 title: 'updates 0 pairs',112 args: [[], [], [], [], '0x'],113 },114 {115 title: 'bases and quotes lengths missmatch',116 args: [[TOKEN_1, TOKEN_1], [TOKEN_2], [1, 1], [1, 1], SIG]117 },118 { 119 title: 'rates length missmatches',120 args: [[TOKEN_1, TOKEN_1], [TOKEN_2, TOKEN_3], [1], [1, 1], SIG],121 },122 {123 title: 'whens length missmatches',124 args: [[TOKEN_1, TOKEN_1], [TOKEN_2, TOKEN_3], [1, 1], [1], SIG],125 },126 {127 title: 'sigs length missmatches',128 args: [[TOKEN_1, TOKEN_1], [TOKEN_2, TOKEN_3], [1, 1], [1, 1], SIG],129 },130 {131 title: 'sigs length is incorrect',132 args: [[TOKEN_1, TOKEN_1], [TOKEN_2, TOKEN_3], [1, 1], [1, 1], SIG + SIG.slice(2) + '01']133 }134 ]135 tests.forEach(({ title, args }) => {136 it(`fails if ${title}`, async () => {137 await assertRevert(() => {138 return this.ppf.updateMany(...args)139 })140 })141 })142 })...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');3 console.log(data);4});5var wpt = require('webpagetest');6var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');7 console.log(data);8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');11 console.log(data);12});13### 3.3.5. Run test with custom script (multiple locations)14var wpt = require('webpagetest');15var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');16 console.log(data);17});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.runTest('www.yahoo.com', function(err, data) {4 if (err) return console.log(err);5 console.log(data);6});7### new WebPageTest(host, [options])8### .runTest(url, [options], callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');3 if (err) return console.error(err);4 console.log('Test status: ' + data.statusText);5 console.log('Test ID: ' + data.data.testId);6 console.log('Test URL: ' + data.data.summary);7});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdefghijklmnopqrstuvwx');3 if (err) return console.log(err);4 console.log(data);5});6var wpt = require('webpagetest');7var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdefghijklmnopqrstuvwx');8 if (err) return console.log(err);9 console.log(data);10});11var wpt = require('webpagetest');12var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdefghijklmnopqrstuvwx');13 if (err) return console.log(err);14 console.log(data);15});16var wpt = require('webpagetest');17var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdefghijklmnopqrstuvwx');18 if (err) return console.log(err);19 console.log(data);20});21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdefghijklmnopqrstuvwx');23 if (err) return console.log(err);24 console.log(data);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wiki = wptools('Albert Einstein');3wiki.get(function(err, resp) {4 console.log(resp);5});6var wptools = require('wptools');7var wiki = wptools('Albert Einstein');8wiki.get(function(err, resp) {9 console.log(resp);10});11var wptools = require('wptools');12var wiki = wptools('Albert Einstein');13wiki.get(function(err, resp) {14 console.log(resp);15});16var wptools = require('wptools');17var wiki = wptools('Albert Einstein');18wiki.get(function(err, resp) {19 console.log(resp);20});

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('wpt');2const wptClient = new wpt('your token here');3 if (err) {4 throw err;5 }6 console.log(data);7});8### `wptClient.test(url, [options], callback)`

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful