/** * Generate the nextToken rule. nextToken is a synthetic lexer rule that is the implicit OR of all * user-defined lexer rules. */ public void genNextToken() { println(""); println("/** Lexer nextToken rule:"); println(" * The lexer nextToken rule is synthesized from all of the user-defined"); println(" * lexer rules. It logically consists of one big alternative block with"); println(" * each user-defined rule being an alternative."); println(" */"); // Create the synthesized rule block for nextToken consisting // of an alternate block containing all the user-defined lexer rules. RuleBlock blk = MakeGrammar.createNextTokenRule(grammar, grammar.rules, "nextToken"); // Define the nextToken rule symbol RuleSymbol nextTokenRs = new RuleSymbol("mnextToken"); nextTokenRs.setDefined(); nextTokenRs.setBlock(blk); nextTokenRs.access = "private"; grammar.define(nextTokenRs); /* // Analyze the synthesized block if (!grammar.theLLkAnalyzer.deterministic(blk)) { println("The grammar analyzer has determined that the synthesized"); println("nextToken rule is non-deterministic (i.e., it has ambiguities)"); println("This means that there is some overlap of the character"); println("lookahead for two or more of your lexer rules."); } */ genCommonBlock(blk); }
/** Print out the grammar without actions */ public String toString() { StringBuffer buf = new StringBuffer(20000); Enumeration ids = rules.elements(); while (ids.hasMoreElements()) { RuleSymbol rs = (RuleSymbol) ids.nextElement(); if (!rs.id.equals("mnextToken")) { buf.append(rs.getBlock().toString()); buf.append("\n\n"); } } return buf.toString(); }
/** * Generate code for a named rule block * * @param s The RuleSymbol describing the rule to generate */ public void genRule(RuleSymbol s) { if (s == null || !s.isDefined()) return; // undefined rule println(""); if (s.comment != null) { _println(HTMLEncode(s.comment)); } if (s.access.length() != 0) { if (!s.access.equals("public")) { _print(s.access + " "); } } _print("<a name=\"" + s.getId() + "\">"); _print(s.getId()); _print("</a>"); // Get rule return type and arguments RuleBlock rblk = s.getBlock(); // RK: for HTML output not of much value... // Gen method return value(s) // if (rblk.returnAction != null) { // _print("["+rblk.returnAction+"]"); // } // Gen arguments // if (rblk.argAction != null) // { // _print(" returns [" + rblk.argAction+"]"); // } _println(""); tabs++; print(":\t"); // Dump any init-action // genBlockPreamble(rblk); // Dump the alternates of the rule genCommonBlock(rblk); _println(""); println(";"); tabs--; }
/** Define a rule */ public void define(RuleSymbol rs) { rules.appendElement(rs); // add the symbol to the rules hash table symbols.put(rs.getId(), rs); }