Created
June 7, 2015 16:51
-
-
Save eariassoto/ac7f4f0b197fd52dccf2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| var Nodo = require("./main.js"); | |
| */ | |
| var method = Nodo.prototype; | |
| function Nodo(nombreGramatica, esTerminal, hileraTerminal) { | |
| this.nombreGramatica = nombreGramatica; | |
| this.esTerminal = esTerminal; | |
| if(this.esTerminal) | |
| this.hileraTerminal = hileraTerminal; | |
| else | |
| this.hileraTerminal = ""; | |
| this.hijos = []; | |
| this.nHijos = 0; | |
| }; | |
| method.agregarHijo = function(h) { | |
| this.hijos.push(h); | |
| this.nHijos++; | |
| }; | |
| method.imprimir = function(tab) { | |
| aux = this.esTerminal ? (": "+this.hileraTerminal) : ""; | |
| console.log(tab+this.nombreGramatica+aux); | |
| function llamadoRecursivoPorQueLosForAquiApestan(element) { | |
| element.imprimir(tab+"\t"); | |
| } | |
| this.hijos.forEach(llamadoRecursivoPorQueLosForAquiApestan); | |
| }; | |
| module.exports = Nodo; | |
| var nodo1 = new Nodo("A", false); | |
| var nodo2 = new Nodo("B", true, "val1"); | |
| var nodo3 = new Nodo("C", true, "val2"); | |
| nodo1.agregarHijo(nodo2); | |
| nodo1.agregarHijo(nodo3); | |
| nodo1.imprimir(""); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment