예제 #1
0
  public Start getStartSymbol(Nonterminal nt) {
    Start start = Start.from(nt);
    if (definitions.keySet().contains(start)) return start;

    Rule startRule;
    if (layout != null)
      startRule =
          Rule.withHead(start)
              .setLabel("Start")
              .addSymbol(layout)
              .addSymbol(nt)
              .addSymbol(layout)
              .setRecursion(Recursion.NON_REC)
              .setAssociativity(Associativity.UNDEFINED)
              .setPrecedence(-1)
              .setPrecedenceLevel(PrecedenceLevel.getFirstAndDone())
              .build();
    else
      startRule =
          Rule.withHead(start)
              .addSymbol(nt)
              .setRecursion(Recursion.NON_REC)
              .setAssociativity(Associativity.UNDEFINED)
              .setPrecedence(-1)
              .setPrecedenceLevel(PrecedenceLevel.getFirstAndDone())
              .build();

    definitions.put(start, CollectionsUtil.list(startRule));
    rules.add(startRule);

    return start;
  }
예제 #2
0
 public Builder addRule(Rule rule) {
   List<Rule> rules = definitions.get(rule.getHead());
   if (rules == null) {
     rules = new ArrayList<>();
     definitions.put(rule.getHead(), rules);
   }
   rules.add(rule);
   this.rules.add(rule);
   return this;
 }
예제 #3
0
 public Builder addExceptPattern(ExceptPattern pattern) {
   exceptPatterns.add(pattern);
   return this;
 }
예제 #4
0
 public Builder addPrecedencePattern(PrecedencePattern pattern) {
   precedencePatterns.add(pattern);
   return this;
 }