generate_code: Generate code from a BNF specification

View source: R/generate.R

generate_codeR Documentation

Generate code from a BNF specification

Description

Generate code from a BNF specification

Usage

generate_code(
  bnf_spec,
  bnf_rule = bnf_spec[[1]],
  lambda0p = 1,
  lambda1p = 1,
  zero_prob = 0.5,
  state = list(depth = 1L)
)

Arguments

bnf_spec

A full BNF grammar specification

bnf_rule

A single rule from the bnf_spec to be used as the starting node for code generation. By default this is the first element in the bnf_spec, but user may specify alternate starting node by name, or by passing in the rule from the full specification. See Examples

lambda0p

When an item is to be repeated "zero or more" times, the actual number of repetitions is drawn from a poisson distribution with mean = lambda0p. Setting this value above too high (depending on your grammer) can result in runaway recursion and stack overflow. Default: 1

lambda1p

When an item is to be repeated "one or more" times, the actual number of repetitions is drawn from a poisson distribution with mean = lambda1p. Setting this value above too high (depending on your grammer) can result in runaway recursion and stack overflow. Default: 1

zero_prob

When an item is to be repeated "zero or one" times, the actual number of repetitions is randomly selected. This value sets the probability of 0 repetitions. Default: 0.5

state

a list of state information. Should not be set by user (unless they really want to)

Value

Code generated from the given BNF

Examples

## Not run: 
generate_code(bnf_spec = bnf_spec)
generate_code(bnf_spec = bnf_spec, bnf_rule = bnf_spec[[1]])
generate_code(bnf_spec = bnf_spec, bnf_fule = 'Expr')

## End(Not run)

ropenscilabs/bnf documentation built on May 15, 2022, 2:20 a.m.