User:Ian Clark/BackusNaurFormOfJterms
Jump to navigation
Jump to search
Backus-Naur Form (BNF) of J terminology
This is the BNF Grammar of a J phrase. I try to stretch it to cover all useful J terminology, but a purely syntactic description will not distinguish a J <Name> from a J <Word> (which I take to be a <Name> in-use) without some underlying notion of "in-use" (viz. as the result of creating a locale, or using =. or =:).
Also I've probably confounded a J phrase with the thing inside the J session that gets created when a phrase is executed with success.
Non-BNF conventions:
- <etc> : continue with alternatives in the same vein
- <text starting with lowercase> : an informal description outside BNF scope
- <CapitalisedWordOrCamelCase> : a BNF token expanded in the list below.
- We take <Thing> <Thing> to mean separation by one or more spaces, whereas <Thing><Thing> anyway means no spaces at all.
Notes:
- <Token> : any part of the partition of a phrase done by (;:).
- Ascii control chars have been omitted from the Grammar
- <Literal> deliberately has a more restricted meaning than: any atom of (a.). It's got to exclude LF, for instance. But should it also exclude NUL and TAB, maybe others?
- This grammar will have to restrict itself to maximally-parenthesized phrases in which all tokens are separated by a space. Else it gets unnecessarily elaborate.
<Nothing>::= <Space>::= <ascii space character> <Bar>::= <ascii vertical bar character> <Letter>::= A | a | B | b | <etc> <Digit>::= 0 | 1 | 2 | <etc> <SingleQuote>::= <ascii single-quote character> <TwoQuotes>::= <SingleQuote><SingleQuote> <Linend>:: <ascii linend character> <Symbol>::= <Bar> | ! | " | # | $ | % | & | * | + | , | - | . | / | : | ; | < | = | > | ? | @ | [ | \ | ] | ^ | _ | ` | { | } | ~ <HardLiteral>::= <Letter> | <Digit> | <Symbol> <StringLiteral>::= <HardLiteral> | <Space> | <TwoQuotes> <StringLiterals>::= <StringLiteral> | <StringLiterals><StringLiteral> <Literal>::= <Space> | <SingleQuote> | <HardLiteral> <Literals>::= <Nothing> | <Literal> | <Literals><Literal> <Inflection>::= <Nothing> | . | : <Punctuation>::= ( | ) <Comment>::= NB.<Literals> <NameLiteral>::= <Letter> | <Digit> | _ <BareName>::= <Letter> | <Letter><NameLiteral> | <BareName><NameLiteral> <Locative>::= _<BareName>_ <Name>::= <BareName> | <BareName><Locative> <NumberConstantAtom>::= <TOBEDEFINED> <LiteralAtom>::= <SingleQuote><StringLiteral><SingleQuote> <String>::= <SingleQuote><StringLiterals><SingleQuote> <NumberConstant>::= <NumberConstantAtom> | <NumberConstant> <NumberConstantAtom> <Constant>::= <String> | <NumberConstant> <Primitive>::= = | =. | =: | < | <. | <etc> <Token>::= <Punctuation> | <Comment> | <Name> | <Constant> | <Primitive> <With>::= <a system-pairing which the J interpreter recognises> <Noun>::= <TOBEDEFINED> <Adverb>::= <TOBEDEFINED> <Conjunction>::= <TOBEDEFINED> <Monad>::= <TOBEDEFINED> <Dyad>::= <TOBEDEFINED> <Train>::= <Hook> | <Fork> | <Train> <Train> <Verb>::= <Monad> | <Dyad> | <Train> | <ModArg> <Adverb> | <ModArg> <Conjunction> <Modarg> <ModArg>::= <Verb> | <Noun> <Value>::= <Noun> | <Adverb> | <Conjunction> | <Verb> <Word>::= <Name> <With> <Value> <Hook>::= <TOBEDEFINED> <Fork>::= <TOBEDEFINED> <Phrase>::= (<Phrase>) | <Name> | <Name> =. <Phrase> | <Name> =: <Phrase> | <Value>