Comments.
head:
CFGs!
error:
$$err
$$errgram
edit:
sample:
Sample output:
sampleitem:
- $$sample
endsample:
foot:
Instructions
In the textbox, enter a list of productions. A production looks like:
HotColor = Red | "royal" Blue | "purple"
The blue part on the left is the name of the production. The red part on the right is what the production should be replaced with. It consists of a list of alternatives separated by |. Alternatives are concatenations of terminals (literal strings in double-quotes, like "royal" and "purple") and nonterminals (production names, such as Red and Blue). Parentheses act as groups. The following production would have a 50% chance of choosing Nader and a 25% chance each of choosing Gore or Bush:
President = Nader | (Gore | Bush)
Productions can also take comma-separated formal parameter lists (in which case they are called functions), such as:
OneThird { param } = param | "" | ""
The green part in curly braces is the parameter list. During evaluation, each formal parameter is replaced by the corresponding value passed to the production in square braces. Example:
Purple = PickOne ["Your money", "Your life"]
In this case, the function PickOne is called with nonterminals "Your money" and "Your life" as parameters.
I don't think this adds any mathematical power, just convenience.
If you screw up, paste in one of the old grammars.
Source Code