| ");
println("Grammar " + grammar.getClassName() + " "); println("ANTLR-generated NBS file from " + antlrTool.grammarFile); println(" ");
println("Terence Parr, MageLang Institute");
println(" | ");
println("
");
*******************/
// RK: see no reason for printing include files and stuff...
// tabs++;
// printAction(behavior.getHeaderAction(""));
// tabs--;
}
/**Generate the lookahead set for an alternate. */
protected void genLookaheadSetForAlt(Alternative alt) {
if (doingLexRules && alt.cache[1].containsEpsilon()) {
println("MATCHES ALL");
return;
}
int depth = alt.lookaheadDepth;
if (depth == GrammarAnalyzer.NONDETERMINISTIC) {
// if the decision is nondeterministic, do the best we can: LL(k)
// any predicates that are around will be generated later.
depth = grammar.maxk;
}
for (int i = 1; i <= depth; i++) {
Lookahead lookahead = alt.cache[i];
printSet(depth, i, lookahead);
}
}
/** Generate a textual representation of the lookahead set
* for a block.
* @param blk The block of interest
*/
public void genLookaheadSetForBlock(AlternativeBlock blk) {
// Find the maximal lookahead depth over all alternatives
int depth = 0;
for (int i = 0; i < blk.alternatives.size(); i++) {
Alternative alt = blk.getAlternativeAt(i);
if (alt.lookaheadDepth == GrammarAnalyzer.NONDETERMINISTIC) {
depth = grammar.maxk;
break;
}
else if (depth < alt.lookaheadDepth) {
depth = alt.lookaheadDepth;
}
}
for (int i = 1; i <= depth; i++) {
Lookahead lookahead = grammar.theLLkAnalyzer.look(i, blk);
printSet(depth, i, lookahead);
}
}
/** 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);
}
/** 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("");
************/
if(doingLexRules) {
_print("TOKEN:");
_print(s.getId());
_print(": ( ");
}else {
_print(s.getId());
_print(" = ");
}
// Get rule return type and arguments
RuleBlock rblk = s.getBlock();
// RK: for NBS 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(" )");
tabs--;
}
/** Generate the syntactic predicate. This basically generates
* the alternative block, buts tracks if we are inside a synPred
* @param blk The syntactic predicate block
*/
protected void genSynPred(SynPredBlock blk) {
syntacticPredLevel++;
genGenericBlock(blk, " =>");
syntacticPredLevel--;
}
public void genTail() {
println("");
/****
println("");
println("");
println("