UNPKG

apg-js-examples

Version:

Examples of using the suite of apg-js applications and libraries.

85 lines (76 loc) 2.9 kB
// copyright: Copyright (c) 2024 Lowell D. Thomas, all rights reserved<br> // license: BSD-2-Clause (https://opensource.org/licenses/BSD-2-Clause)<br> // // Generated by apg-js, Version 4.4.0 [apg-js](https://github.com/ldthomas/apg-js) module.exports = function grammar(){ // ``` // SUMMARY // rules = 5 // udts = 0 // opcodes = 14 // --- ABNF original opcodes // ALT = 1 // CAT = 3 // REP = 0 // RNM = 4 // TLS = 4 // TBS = 0 // TRG = 0 // --- SABNF superset opcodes // UDT = 0 // AND = 0 // NOT = 0 // BKA = 0 // BKN = 0 // BKR = 2 // ABG = 0 // AEN = 0 // characters = [97 - 121] // ``` /* OBJECT IDENTIFIER (for internal parser use) */ this.grammarObject = 'grammarObject'; /* RULES */ this.rules = []; this.rules[0] = { name: 'rule', lower: 'rule', index: 0, isBkr: false }; this.rules[1] = { name: 'A', lower: 'a', index: 1, isBkr: true }; this.rules[2] = { name: 'B', lower: 'b', index: 2, isBkr: false }; this.rules[3] = { name: 'X', lower: 'x', index: 3, isBkr: true }; this.rules[4] = { name: 'Y', lower: 'y', index: 4, isBkr: false }; /* UDTS */ this.udts = []; /* OPCODES */ /* rule */ this.rules[0].opcodes = []; this.rules[0].opcodes[0] = { type: 2, children: [1,8,9] };// CAT this.rules[0].opcodes[1] = { type: 1, children: [2,5] };// ALT this.rules[0].opcodes[2] = { type: 2, children: [3,4] };// CAT this.rules[0].opcodes[3] = { type: 4, index: 1 };// RNM(A) this.rules[0].opcodes[4] = { type: 4, index: 2 };// RNM(B) this.rules[0].opcodes[5] = { type: 2, children: [6,7] };// CAT this.rules[0].opcodes[6] = { type: 4, index: 3 };// RNM(X) this.rules[0].opcodes[7] = { type: 4, index: 4 };// RNM(Y) this.rules[0].opcodes[8] = { type: 14, index: 3, lower: 'x', bkrCase: 604, bkrMode: 601 };// BKR(\%i%uX) this.rules[0].opcodes[9] = { type: 14, index: 1, lower: 'a', bkrCase: 604, bkrMode: 601 };// BKR(\%i%uA) /* A */ this.rules[1].opcodes = []; this.rules[1].opcodes[0] = { type: 7, string: [97] };// TLS /* B */ this.rules[2].opcodes = []; this.rules[2].opcodes[0] = { type: 7, string: [98] };// TLS /* X */ this.rules[3].opcodes = []; this.rules[3].opcodes[0] = { type: 7, string: [97] };// TLS /* Y */ this.rules[4].opcodes = []; this.rules[4].opcodes[0] = { type: 7, string: [121] };// TLS // The `toString()` function will display the original grammar file(s) that produced these opcodes. this.toString = function toString(){ let str = ""; str += "rule = ( (A B) / (X Y) ) \\X \\A\n"; str += "A = \"a\"\n"; str += "B = \"b\"\n"; str += "X = \"a\"\n"; str += "Y = \"y\"\n"; return str; } }