Definition – grammar of the NCX language
The grammar of the NCX language in Backus-Naur form: how NC programs are built from blocks and cells consisting of function, address and value.
The NCX language is defined as a formal grammar in Backus-Naur form (BNF). An NC program consists of blocks (lines) made up of cells of the form [KEYWORD:ADDRESS=VALUE].
Grammar
<program> ::= ( <block> <new-line> )+
<new-line> ::= "\n"
<block> ::= <cell>+
<cell> ::= "[" <content> "]"
<content> ::= <function> "=" <target>
<function> ::= <text> | <text> ":" <address>
<address> ::= <text>
<target> ::= <value> | <value> "," <target>
<value> ::= <text> | <decimal> | <integer>
<decimal> ::= <integer> "." <digits>
<integer> ::= <digits> | "-" <digits>
<digits> ::= <digit>+
<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
<text> ::= <character>+
<character> ::= "A" ... "Z" | <digit> | "_" | "+"
The productions in detail
<program>– A program consists of one or more blocks, each terminated by a new line.<block>– A block is a sequence of one or more cells and corresponds to one program line.<cell>– The cell is the basic unit of a program. Each cell consists of content enclosed in square brackets[…].<content>– The content of a cell is made up of a function and a target, separated by an equals sign=.<function>– The function specifies which action the cell performs. It consists either of text alone or of text followed by a colon:and an address.<address>– The address is optional and is only used when the function requires one. It consists of text.<target>– The target specifies what the function is applied to: a single value or a comma-separated list of values (e.g.INTERPO=ARC,CCW).<value>– A value can be text, a decimal number or an integer.<decimal>– A decimal number consists of an integer part and a fractional part, separated by a decimal point.(e.g.-22.543).<integer>– An integer is a positive or negative whole number without decimal places; negative numbers start with a minus sign-.<digits>– A sequence of one or more digits.<text>– Text is a sequence of one or more characters.<character>– A single character is an uppercase letterA–Z, a digit, the underscore_or the plus sign+(e.g. inWORKPLANE=XY+Z). Spaces are not permitted.
Example
A block – here a clockwise arc with a center point – consists of several cells:
[INTERPO=ARC,CW,CENTER][GOTO:X=20][GOTO:Y=20][CENTER:X=10][CENTER:Y=10]The Specification documents what the individual keywords mean; the Examples show more conversions.