UNPKG

jscc-parser

Version:

A LALR(1) Parser Generator for JavaScript written in JavaScript.

376 lines (318 loc) 19.4 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: debug.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: debug.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>/* * Universal module definition for debug. */ (function(root, factory) { /* istanbul ignore next */ if (typeof define === 'function' &amp;&amp; define.amd) { define(['require', './global', './io/io', './enums/MODE_GEN', './enums/SYM', './enums/ASSOC'], factory); } else if (typeof module === 'object' &amp;&amp; module.exports) { module.exports = factory(require); } else { root.jsccdebug = factory(function(mod) { return root["jscc" + mod.split("/").pop()]; }); } }(this, /** * @param {reqParameter} require * @param {...*} others * @returns {jscc.debug} */ function(require, others) { //>>excludeStart("closure", pragmas.closure); var jscc = {}; var has = /** @type {hasObject} */ (require("./localHas")); //>>excludeEnd("closure"); var io, global = /** @type {jscc.global} */ (require("./global")), MODE_GEN = require("./enums/MODE_GEN"), SYM = require("./enums/SYM"), ASSOC = require("./enums/ASSOC"); /** * @suppress {uselessCode} */ (function() { if (has("node")) { io = /** @type {jscc.io} */ (require("./io/ioNode")); } else { io = /** @type {jscc.io} */ (require("./io/io")); } })(); /** * Debugging-output functions. * @namespace jscc.debug */ /** * Debugging-output functions. * @module {jscc.debug} jscc/debug * @requires module:jscc/global * @requires module:jscc/io/io * @constructor */ jscc.debug = function() { }; jscc.debug.prototype = { /** * Prints debugging output related to the current value of the * {@link jscc.global.symbols} array. * @param {jscc.enums.MODE_GEN} mode - The current output mode. * @memberof jscc.debug */ print_symbols: function(mode) { if (mode == MODE_GEN.HTML) { io.write_debug("&lt;table class=\"debug\" cellpadding=\"0\" cellspacing=\"0\">"); io.write_debug("&lt;tr>"); io.write_debug("&lt;td class=\"tabtitle\" colspan=\"3\">Symbols Overview&lt;/td>"); io.write_debug("&lt;/tr>"); io.write_debug("&lt;tr>"); io.write_debug("&lt;td class=\"coltitle\">Symbol&lt;/td>"); io.write_debug("&lt;td class=\"coltitle\">Type&lt;/td>"); io.write_debug("&lt;/tr>"); } else if (mode == MODE_GEN.TEXT) { io.write_debug("--- Symbol Dump ---"); } for (var i = 0; i &lt; global.symbols.length; i++) { if (mode == MODE_GEN.HTML) { io.write_debug("&lt;tr>"); io.write_debug("&lt;td>"); io.write_debug(global.symbols[i].label); io.write_debug("&lt;/td>"); io.write_debug("&lt;td>"); io.write_debug(((global.symbols[i].kind == SYM.NONTERM) ? "Non-terminal" : "Terminal")); io.write_debug("&lt;/td>"); } else if (mode == MODE_GEN.TEXT) { var output = ""; output = global.symbols[i].label; for (var j = output.length; j &lt; 20; j++) { output += " "; } output += ((global.symbols[i].kind == SYM.NONTERM) ? "Non-terminal" : "Terminal"); if (global.symbols[i].kind == SYM.TERM) { for (var j = output.length; j &lt; 40; j++) { output += " "; } output += global.symbols[i].level + "/"; switch (global.symbols[i].associativity) { case ASSOC.NONE: output += "^"; break; case ASSOC.LEFT: output += "&lt;"; break; case ASSOC.RIGHT: output += ">"; break; } } io.write_debug(output); } } if (mode == MODE_GEN.HTML) { io.write_debug("&lt;/table>"); } else if (mode == MODE_GEN.TEXT) { io.write_debug(""); } }, /** * Prints debugging output related to the grammar being processed, * using information from the {@link jscc.global.symbols} and * {@link jscc.global.productions} arrays. * @param {jscc.enums.MODE_GEN} mode - The current output mode. * @memberof jscc.debug */ print_grammar: function(mode) { if (mode == MODE_GEN.HTML) { io.write_debug("&lt;table class=\"debug\" cellpadding=\"0\" cellspacing=\"0\">"); io.write_debug("&lt;tr>"); io.write_debug("&lt;td class=\"tabtitle\" colspan=\"3\">Grammar Overview&lt;/td>"); io.write_debug("&lt;/tr>"); io.write_debug("&lt;tr>"); io.write_debug("&lt;td class=\"coltitle\">Left-hand side&lt;/td>"); io.write_debug("&lt;td class=\"coltitle\">FIRST-set&lt;/td>"); io.write_debug("&lt;td class=\"coltitle\">Right-hand side&lt;/td>"); io.write_debug("&lt;/tr>"); for (var i = 0; i &lt; global.symbols.length; i++) { io.write_debug("&lt;tr>"); if (global.symbols[i].kind == SYM.NONTERM) { io.write_debug("&lt;td>"); io.write_debug(global.symbols[i].label); io.write_debug("&lt;/td>"); io.write_debug("&lt;td>"); for (var j = 0; j &lt; global.symbols[i].first.length; j++) { io.write_debug("&lt;b>" + global.symbols[global.symbols[i].first[j]].label + "&lt;/b>"); } io.write_debug("&lt;/td>"); io.write_debug("&lt;td>"); for (var j = 0; j &lt; global.symbols[i].prods.length; j++) { for (var k = 0; k &lt; global.productions[global.symbols[i].prods[j]].rhs.length; k++) { if (global.symbols[global.productions[global.symbols[i].prods[j]].rhs[k]].kind == SYM.TERM) { io.write_debug("&lt;b>" + global.symbols[global.productions[global.symbols[i].prods[j]].rhs[k]].label + "&lt;/b>"); } else { io.write_debug(" " + global.symbols[global.productions[global.symbols[i].prods[j]].rhs[k]].label + " "); } } io.write_debug("&lt;br />"); } io.write_debug("&lt;/td>"); } io.write_debug("&lt;/tr>"); } io.write_debug("&lt;/table>"); } else if (mode == MODE_GEN.TEXT) { var output = ""; for (var i = 0; i &lt; global.symbols.length; i++) { if (global.symbols[i].kind == SYM.NONTERM) { output += global.symbols[i].label + " {"; for (var j = 0; j &lt; global.symbols[i].first.length; j++) { output += " " + global.symbols[global.symbols[i].first[j]].label + " "; } output += "}\n"; for (var j = 0; j &lt; global.symbols[i].prods.length; j++) { output += "\t"; for (var k = 0; k &lt; global.productions[global.symbols[i].prods[j]].rhs.length; k++) { if (global.symbols[global.productions[global.symbols[i].prods[j]].rhs[k]].kind == SYM.TERM) { output += "#" + global.symbols[global.productions[global.symbols[i].prods[j]].rhs[k]].label + " "; } else { output += global.symbols[global.productions[global.symbols[i].prods[j]].rhs[k]].label + " "; } } output += "\n"; } } } io.write_debug(output); } }, /** * Prints debugging information relating to the provided array * of Item objects. * @param {jscc.enums.MODE_GEN} mode - The current output mode. * @param {string} label - A label for the debugging output. * @param {Array&lt;!jscc.classes.Item>} item_set - The items for which to print information. * @memberof jscc.debug */ print_item_set: function(mode, label, item_set) { var i, j; if (item_set.length == 0) { return; } if (mode == MODE_GEN.HTML) { io.write_debug("&lt;table class=\"debug\" cellpadding=\"0\" cellspacing=\"0\">"); io.write_debug("&lt;tr>"); io.write_debug("&lt;td class=\"tabtitle\" colspan=\"2\">" + label + "&lt;/td>"); io.write_debug("&lt;/tr>"); io.write_debug("&lt;tr>"); io.write_debug("&lt;td class=\"coltitle\" width=\"35%\">Lookahead&lt;/td>"); io.write_debug("&lt;td class=\"coltitle\" width=\"65%\">Production&lt;/td>"); io.write_debug("&lt;/tr>"); } else if (mode == MODE_GEN.TEXT) { io.write_debug("--- " + label + " ---"); } for (i = 0; i &lt; item_set.length; i++) { if (mode == MODE_GEN.HTML) { io.write_debug("&lt;tr>"); io.write_debug("&lt;td>"); for (j = 0; j &lt; item_set[i].lookahead.length; j++) { io.write_debug("&lt;b>" + global.symbols[item_set[i].lookahead[j]].label + "&lt;/b> "); } io.write_debug("&lt;/td>"); io.write_debug("&lt;td>"); io.write_debug(global.symbols[global.productions[item_set[i].prod].lhs].label + " -&amp;gt; "); for (j = 0; j &lt; global.productions[item_set[i].prod].rhs.length; j++) { if (j == item_set[i].dot_offset) { io.write_debug("."); } if (global.symbols[global.productions[item_set[i].prod].rhs[j]].kind == SYM.TERM) { io.write_debug("&lt;b>" + global.symbols[global.productions[item_set[i].prod].rhs[j]].label + "&lt;/b>"); } else { io.write_debug( " " + global.symbols[global.productions[item_set[i].prod].rhs[j]].label + " "); } } if (j == item_set[i].dot_offset) { io.write_debug("."); } io.write_debug("&lt;/td>"); io.write_debug("&lt;/tr>"); } else if (mode == MODE_GEN.TEXT) { var out = ""; out += global.symbols[global.productions[item_set[i].prod].lhs].label; for (j = out.length; j &lt; 20; j++) { out += " "; } out += " -> "; for (j = 0; j &lt; global.productions[item_set[i].prod].rhs.length; j++) { if (j == item_set[i].dot_offset) { out += "."; } if (global.symbols[global.productions[item_set[i].prod].rhs[j]].kind == SYM.TERM) { out += " #" + global.symbols[global.productions[item_set[i].prod].rhs[j]].label + " "; } else { out += " " + global.symbols[global.productions[item_set[i].prod].rhs[j]].label + " "; } } if (j == item_set[i].dot_offset) { out += "."; } for (j = out.length; j &lt; 60; j++) { out += " "; } out += "{ "; for (j = 0; j &lt; item_set[i].lookahead.length; j++) { out += "#" + global.symbols[item_set[i].lookahead[j]].label + " "; } out += "}"; io.write_debug(out); } } if (mode == MODE_GEN.HTML) { io.write_debug("&lt;/table>"); } } }; return new jscc.debug(); })); </code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-jscc.html">jscc</a></li><li><a href="module-jscc_bitset_BitSet32.html">jscc/bitset/BitSet32</a></li><li><a href="module-jscc_bitset_BitSetBool.html">jscc/bitset/BitSetBool</a></li><li><a href="module-jscc_bitset_BitSetJava.html">jscc/bitset/BitSetJava</a></li><li><a href="module-jscc_classes_Dfa.html">jscc/classes/Dfa</a></li><li><a href="module-jscc_classes_Item.html">jscc/classes/Item</a></li><li><a href="module-jscc_classes_Nfa.html">jscc/classes/Nfa</a></li><li><a href="module-jscc_classes_Param.html">jscc/classes/Param</a></li><li><a href="module-jscc_classes_Production.html">jscc/classes/Production</a></li><li><a href="module-jscc_classes_State.html">jscc/classes/State</a></li><li><a href="module-jscc_classes_Symbol.html">jscc/classes/Symbol</a></li><li><a href="module-jscc_classes_TableEntry.html">jscc/classes/TableEntry</a></li><li><a href="module-jscc_enums_ASSOC.html">jscc/enums/ASSOC</a></li><li><a href="module-jscc_enums_EDGE.html">jscc/enums/EDGE</a></li><li><a href="module-jscc_enums_EXEC.html">jscc/enums/EXEC</a></li><li><a href="module-jscc_enums_LOG_LEVEL.html">jscc/enums/LOG_LEVEL</a></li><li><a href="module-jscc_enums_MODE_GEN.html">jscc/enums/MODE_GEN</a></li><li><a href="module-jscc_enums_SPECIAL.html">jscc/enums/SPECIAL</a></li><li><a href="module-jscc_enums_SYM.html">jscc/enums/SYM</a></li><li><a href="module-jscc_first.html">jscc/first</a></li><li><a href="module-jscc_global.html">jscc/global</a></li><li><a href="module-jscc_integrity.html">jscc/integrity</a></li><li><a href="module-jscc_io_io.html">jscc/io/io</a></li><li><a href="module-jscc_lexdbg.html">jscc/lexdbg</a></li><li><a href="module-jscc_lexdfa.html">jscc/lexdfa</a></li><li><a href="module-jscc_log_log.html">jscc/log/log</a></li><li><a href="module-jscc_parse.html">jscc/parse</a></li><li><a href="module-jscc_printtab.html">jscc/printtab</a></li><li><a href="module-jscc_regex.html">jscc/regex</a></li><li><a href="module-jscc_util.html">jscc/util</a></li></ul><h3>Classes</h3><ul><li><a href="-_anonymous_-jscc.BitSet32.html">BitSet32</a></li><li><a href="-_anonymous_-jscc.BitSetBool.html">BitSetBool</a></li><li><a href="-_anonymous_-jscc.BitSetJava.html">BitSetJava</a></li><li><a href="-_anonymous_-jscc.classes.Dfa.html">classes.Dfa</a></li><li><a href="-_anonymous_-jscc.first.html">first</a></li><li><a href="-_anonymous_-jscc.global.html">global</a></li><li><a href="-_anonymous_-jscc.integrity.html">integrity</a></li><li><a href="-_anonymous_-jscc.ioBrowser.html">ioBrowser</a></li><li><a href="-_anonymous_-jscc.ioNashorn.html">ioNashorn</a></li><li><a href="-_anonymous_-jscc.ioNode.html">ioNode</a></li><li><a href="-_anonymous_-jscc.ioRhino.html">ioRhino</a></li><li><a href="-_anonymous_-jscc.lexdbg.html">lexdbg</a></li><li><a href="-_anonymous_-jscc.lexdfa.html">lexdfa</a></li><li><a href="-_anonymous_-jscc.logBrowser.html">logBrowser</a></li><li><a href="-_anonymous_-jscc.logJava.html">logJava</a></li><li><a href="-_anonymous_-jscc.logNode.html">logNode</a></li><li><a href="-_anonymous_-jscc.printtab.html">printtab</a></li><li><a href="-_anonymous_-jscc.util.html">util</a></li><li><a href="jscc_debug.html">jscc/debug</a></li><li><a href="jscc_nfaStates.html">jscc/nfaStates</a></li><li><a href="jscc_tabgen.html">jscc/tabgen</a></li><li><a href="%257Bjscc.classes%257D.jscc.classes.State.html">jscc.classes.State</a></li></ul><h3>Namespaces</h3><ul><li><a href="jscc.debug.html">debug</a></li></ul><h3>Interfaces</h3><ul><li><a href="jscc.bitset.html">bitset</a></li><li><a href="jscc.io.html">io</a></li><li><a href="jscc.log.html">log</a></li></ul><h3><a href="global.html">Global</a></h3> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Aug 01 2016 13:35:55 GMT-0500 (Central Daylight Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>