build<E> method

Grammar<E> build<E>(
  1. Nonterminal<E> expression
)

Implementation

Grammar<E> build<E>(Nonterminal<E> expression) {
  _processed.clear();
  _rules.clear();
  expression.accept(this);
  final rule = _rules[expression] as NonterminalRule<E>;
  for (final rule in _callers.keys) {
    final expression = rule.expression;
    final callers = _callers[rule]!;
    for (final caller in callers) {
      caller.expression = expression;
    }
  }

  final grammar = Grammar(_rules.values.toList(), rule);
  final expressionInitializer = ExpressionInitializer();
  expressionInitializer.initialize(grammar);
  final grammarChecker = GrammarChecker();
  grammarChecker.check(grammar);
  final grammarInitializer = GrammarInitializer();
  grammarInitializer.initialize(grammar);
  final invocationsResolver = InvocationsResolver();
  invocationsResolver.resolve(grammar);
  return grammar;
}