Class: Model

Practice~ Model

Model of the practice page. The following global variables and global modules will exist once the model has been constructed. Pre-existing global variables newOutput, prompt, and puts will not be overwritten.

name type content
actions string Defines the class and action methods to be called by a parser.
g Grammar Represents grammar.
grammar string Rules of a grammar, argument for the construction of g.
newOutput function Displays it's arguments, blank-separated and marked as a new section.
program string Should be a sentence conforming to grammar, argument for recognition.
prompt function Displays a prompt string, returns input or a default string, else error.
puts function Displays it's arguments, blank-separated.
run function null or an executable compiled from program by the actions.
A stack machine has two arguments, other executables have none.
tokens string Defines an object with pattern properties defining the tokens used in grammar.
module purpose
Base Base classes shared by the parser generators
EBNF LL(1) parser generator
BNF SLR(1) parser generator
Six Classes for the examples in chapter six
Seven Classes for the examples in chapter seven
Eight Classes for the examples in chapter eight
Ten Classes for the examples in chapter ten
Eleven Classes for the examples in chapter eleven

new Model(global)

Create a model.

Parameters:
Name Type Description
global object

either windows or globalThis.

Properties:
Name Type Argument Description
grammar string

global grammar; setter clears global g and global run.

tokens string

global tokens; setter clears global g and global run.

skip RegExp

set by doNew from an empty key in tokens; overwrites default for scanner and parser.

actions string

global actions; setter clears global run.

program string

global program; setter clears global run.

mode string

ebnf|stack|bnf; setter clears global g and global run.

greedy boolean

use expect() rather than check().

error boolean

insert $error when translating EBNF.

tShallow boolean

trace algorithm and display sets.

tDeep boolean

trace algorithm and display sets.

tFollow boolean

trace algorithm and display sets.

dSets boolean

display sets.

dStates boolean

display states.

tLookahead boolean

trace lookahead during parse.

tParser boolean

trace parse.

tActions boolean

trace actions.

tNoargs boolean

do not check argument count for actions.

build boolean

build lists.

memory Array <nullable>

for stepping a stack machine.

Source:
Examples
// Use in scripting in a Windows environment
new Model(windows);
// Use in scripting in a node.js environment
new Model(globalThis);

Methods


doNew()

Event: eval?.(tokens), if any, and represent and check the grammar; modifies g, clears run, and removes memory.

Source:

doParse()

Event: eval?.(this.actions), if any, create a parser, and parse the program; modifies run and removes memory.

Source:

doRun()

Event: run the executable, if any.

Source:

doScan()

Event: create a scanner and apply it to this.program.

Source:

doStep(n)

Event: step the stack machine, if any.

Parameters:
Name Type Description
n number

number of steps to execute.

Source: