1 | import Rule from './rule';
|
2 | import GrammarToBNF from './grammartobnf';
|
3 |
|
4 | export default class Grammar {
|
5 |
|
6 | constructor(rules) {
|
7 | if(arguments.length == 0) {
|
8 | rules = [];
|
9 | } else if (rules.constructor !== Array) {
|
10 | rules = arguments;
|
11 | }
|
12 | this.rules = rules;
|
13 | }
|
14 |
|
15 | |
16 |
|
17 |
|
18 | getRules() {
|
19 | return this.rules;
|
20 | }
|
21 |
|
22 | |
23 |
|
24 |
|
25 |
|
26 | toBNF(grammarToBNF) {
|
27 | const sb = [];
|
28 | for (let i = 0; i < this.rules.length; i++) {
|
29 | if (i > 0) {
|
30 | sb.push("\n");
|
31 | }
|
32 | sb.push(this.rules[i].toBNF(grammarToBNF));
|
33 | }
|
34 | return sb.join("");
|
35 | }
|
36 |
|
37 | }
|