Syntax
Comments
- Single line comments
- Supported types:
-
// -
;
-
- Multi-line comments
- Supported types:
-
( )
-
- If not closed at end of file:
- An error will be generated
- The comment must be properly closed with
)before EOF
Parameters
- #<NC.aaa.bbb> = xx.x
- #<NC.Rapid.MaxRapid> = 30000.0
- #<NC.Axes.XAxis.MaxSpeed> = 1000
Variables
- #yyyy= xx.x
- #1003 = 100
- #1005 = [#1003 + #1004]
- #1006 = PLC.LREALS[45]
- PLC.LREALS[46] = #1005
Loops
- IF statement
- IF [condition]
- .....
- END
- IF [#10000 == 0]
- G53 X#5010 Y#5011 F30000 // Move above the transfer station
- M202 // Open the shroud
- G53 Z[#5012 + #5015] F10000 // Move Z down to the approach position
- END
- IF [condition]
- .....
- ELSE
- .....
- END
- WHILE statement
- WHILE [condition] DO
- .....
- END
- #1001 = 0
- WHILE[#1001 <= 100] DO
- N11 G1 X#1001 F3000
- N11 G1 Y#1001 F3000
- G4 P500
- #1001 = #1001 + 10
- END
- FOR statement
- FOR [condition, x, y] DO
- .....
- END
- FOR [#1 = 1, 10, 1] DO
- G1 X[#1]
- G4 P500
- END
- See also:
Whitespace
- Spaces
- Spaces are generally ignored
-
G01 X10==G 01 X 10==G01X10 -
G01 X#100==G01 X #100==G01 X# 100==G01 X #100
-
- Spaces are not allowed within a number:
-
G01 X100≠G0 1 X100 -
G01 X#100≠G0 1 X#1 00 -
G01 X123.45≠G01 X123. 45
-
Line endings
- Allowed types:
-
\norLF -
\r\norCRLF -
\rorCR
-
- Allowed to mix and match in a file, though not recommended
Case Sensitivity
- Not case sensitive
-
G01 X100 g01 X100g01 x100
Values
-
87.123 -
+87.123 -
-87.123 -
123. 123123.0-
12345.999 -
00012345.999 -
0 -
1 - Thousands separator:
-
12,345.000 -
12.345,000 - Comma for decimal
-
12345,999 - Scientific notation
-
1.23e3
Valid
Invalid
G-Code Grammar
- General behavior is that each discrete command or operator (e.g., G01) and arguments are grouped together, then these groupings are ordered by priority.
-
G90 G01 X1 Y2 G20 M03 S1000 G54
- See G-Code Command Priority
- Consider the parallels to English writing structure:
- Letter:
- A-Z registers
- Number:
- 0-9, 1.523, 100, 134.5
- Word
- A combination of Letter and Number, e.g.,
G01
- A combination of Letter and Number, e.g.,
- Sentence:
- Single, standalone command, like
G01 X1 Y2orG91orG28 XYZ - Sentences/Commands are separated by either a new line or G/M
- Single, standalone command, like
- Paragraph:
- A single line may contain multiple commands.
- For example:
G90 G01 X1 Y2 G20 M03 S1000 G64 G54 G49is equal to: ```G-Code G49 G20 G64 G90 G54 G01 X1 Y2 M03 S1000
- Data needed for a full grammar check:
- A-Z parameters allowed (optional, required, not allowed)
- Allowed to be on the same line as other commands
- Allowed or not in certain modal modes
- Allowed with M-codes
Examples
-
G00 X10 Y10 M100 P5- M-codes have priority over motion blocks
- M100 is executed first and is given parameter P5
- Once the M100 is acknowledged, the G00 G-code is processed
- G00 moves to X100 Y100
- Motion buffer may begin as soon M100 acknowledges it is complete
-
G01 X10 Y10 S1000 M3- M3 is executed first and is given parameter S1000
- Once the M3 is acknowledged, the G01 G-code is processed
- G01 moves to X10 Y10
- M3 is executed first and is given parameter S1000
-
1| N1 G00 X100 Y100 2| N2 X50 Y50 G01 X10 Y10 - Multiline carry over motion modal state is invalid. The above is not a valid command at
N2. When a motion command occurs on a line, the motion axes must always follow the G command for motion.