From ec98c72dec67027559cffdd0d75257ef7c426fe1 Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Sun, 3 Jun 2018 22:05:29 -0300 Subject: Weighting part 2 Weighting now has a syntax. Include a {^} token to set the rule weight --- src/main/java/bjc/rgens/parser/RGrammarSet.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/main/java/bjc/rgens/parser/RGrammarSet.java') diff --git a/src/main/java/bjc/rgens/parser/RGrammarSet.java b/src/main/java/bjc/rgens/parser/RGrammarSet.java index ad9836f..d734074 100755 --- a/src/main/java/bjc/rgens/parser/RGrammarSet.java +++ b/src/main/java/bjc/rgens/parser/RGrammarSet.java @@ -30,14 +30,15 @@ public class RGrammarSet { private Map loadedFrom; public static final boolean PERF = true; + public static final boolean DEBUG = true; /** Create a new set of randomized grammars. */ public RGrammarSet() { grammars = new HashMap<>(); - exportedRules = new HashMap<>(); + exportedRules = new TreeMap<>(); - exportFrom = new TreeMap<>(); + exportFrom = new HashMap<>(); loadedFrom = new HashMap<>(); } @@ -67,9 +68,15 @@ public class RGrammarSet { /* Process exports from the grammar. */ for (Rule export : gram.getExportedRules()) { + if(exportedRules.containsKey(export.name)) + System.err.printf("WARN: Shadowing rule %s in %s from %s\n", export.name, exportFrom.get(export.name), grammarName); + exportedRules.put(export.name, gram); exportFrom.put(export.name, grammarName); + + if(DEBUG) + System.err.printf("\t\tDEBUG: %s exported from %s\n", export.name, grammarName); } /* Add exports to grammar. */ -- cgit v1.2.3