apg-js-examples
Version:
Examples of using the suite of apg-js applications and libraries.
96 lines (87 loc) • 3.57 kB
JavaScript
// 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 = 20
// --- ABNF original opcodes
// ALT = 0
// CAT = 4
// REP = 3
// RNM = 6
// TLS = 6
// TBS = 0
// TRG = 0
// --- SABNF superset opcodes
// UDT = 0
// AND = 1
// NOT = 0
// BKA = 0
// BKN = 0
// BKR = 0
// ABG = 0
// AEN = 0
// characters = [97 - 99]
// ```
/* OBJECT IDENTIFIER (for internal parser use) */
this.grammarObject = 'grammarObject';
/* RULES */
this.rules = [];
this.rules[0] = { name: 'AnBnCn', lower: 'anbncn', index: 0, isBkr: false };
this.rules[1] = { name: 'Prefix', lower: 'prefix', index: 1, isBkr: false };
this.rules[2] = { name: 'ConsumeAs', lower: 'consumeas', index: 2, isBkr: false };
this.rules[3] = { name: 'AnBn', lower: 'anbn', index: 3, isBkr: false };
this.rules[4] = { name: 'BnCn', lower: 'bncn', index: 4, isBkr: false };
/* UDTS */
this.udts = [];
/* OPCODES */
/* AnBnCn */
this.rules[0].opcodes = [];
this.rules[0].opcodes[0] = { type: 2, children: [1,3,4] };// CAT
this.rules[0].opcodes[1] = { type: 12 };// AND
this.rules[0].opcodes[2] = { type: 4, index: 1 };// RNM(Prefix)
this.rules[0].opcodes[3] = { type: 4, index: 2 };// RNM(ConsumeAs)
this.rules[0].opcodes[4] = { type: 4, index: 4 };// RNM(BnCn)
/* Prefix */
this.rules[1].opcodes = [];
this.rules[1].opcodes[0] = { type: 2, children: [1,2] };// CAT
this.rules[1].opcodes[1] = { type: 4, index: 3 };// RNM(AnBn)
this.rules[1].opcodes[2] = { type: 7, string: [99] };// TLS
/* ConsumeAs */
this.rules[2].opcodes = [];
this.rules[2].opcodes[0] = { type: 3, min: 0, max: Infinity };// REP
this.rules[2].opcodes[1] = { type: 7, string: [97] };// TLS
/* AnBn */
this.rules[3].opcodes = [];
this.rules[3].opcodes[0] = { type: 2, children: [1,2,4] };// CAT
this.rules[3].opcodes[1] = { type: 7, string: [97] };// TLS
this.rules[3].opcodes[2] = { type: 3, min: 0, max: 1 };// REP
this.rules[3].opcodes[3] = { type: 4, index: 3 };// RNM(AnBn)
this.rules[3].opcodes[4] = { type: 7, string: [98] };// TLS
/* BnCn */
this.rules[4].opcodes = [];
this.rules[4].opcodes[0] = { type: 2, children: [1,2,4] };// CAT
this.rules[4].opcodes[1] = { type: 7, string: [98] };// TLS
this.rules[4].opcodes[2] = { type: 3, min: 0, max: 1 };// REP
this.rules[4].opcodes[3] = { type: 4, index: 4 };// RNM(BnCn)
this.rules[4].opcodes[4] = { type: 7, string: [99] };// TLS
// The `toString()` function will display the original grammar file(s) that produced these opcodes.
this.toString = function toString(){
let str = "";
str += ";\n";
str += "; text book example of a phrase which\n";
str += "; cannot be described with a context-free grammar\n";
str += "; but can be described using syntactic predicates\n";
str += ";\n";
str += "AnBnCn = &Prefix ConsumeAs BnCn\n";
str += "Prefix = AnBn \"c\"\n";
str += "ConsumeAs = *\"a\"\n";
str += "AnBn = \"a\" [AnBn] \"b\"\n";
str += "BnCn = \"b\" [BnCn] \"c\"\n";
return str;
}
}