print method

void print(
  1. Grammar grammar,
  2. StringSink sink
)

Implementation

void print(Grammar grammar, StringSink sink) {
  _processed.clear();
  rules.clear();
  final start = grammar.start;
  rules.add(start);
  start.expression.accept(this);
  final nonterminals =
      rules.where((e) => e.kind == ProductionRuleKind.nonterminal);
  final terminals = rules.where((e) => e.kind == ProductionRuleKind.terminal);
  final subterminals =
      rules.where((e) => e.kind == ProductionRuleKind.subterminal);

  sink.writeln('# Nonterminals');
  for (final rule in nonterminals) {
    _printRule(rule, sink);
  }

  sink.writeln('# Terminals');
  for (final rule in terminals) {
    _printRule(rule, sink);
  }
  sink.writeln('# Subterminals');
  for (final rule in subterminals) {
    _printRule(rule, sink);
  }
}