Beispiel #1
0
 public static void main(String[] args) throws IOException {
   for (String filename : args) {
     GrammarReader gr = new GrammarReader(true);
     gr.read(Paths.get(filename).toFile().toURI().toURL());
     Grammar grammar = gr.getGrammar();
     grammar.addRule("Goal", "CompilationUnit");
     grammar.validateRules();
     for (Rule r : grammar.getRules()) System.out.println(r);
   }
 }
Beispiel #2
0
 // TODO: rewrite it in parjac :-)
 private void parseLine(String line) {
   line = line.trim();
   if (line.isEmpty()) return;
   if (line.startsWith("#")) return;
   if (line.endsWith(":")) {
     currentRule = line.substring(0, line.length() - 1);
   } else {
     StringTokenizer st = new StringTokenizer(line, "'?*() ", true);
     grammar.addRule(currentRule, parseRecursive(st));
   }
 }