Class NcExpressionParser
- Namespace
- Hi.NcParsers.EvaluationSyntaxs.Evaluation
- Assembly
- HiMech.dll
Recursive-descent parser for Fanuc Custom Macro B value expressions. Pure: takes a string, produces an NcExpr AST. Performs no variable lookup and no evaluation.
Grammar (lowest precedence at top):
expr := or-expr
or-expr := and-expr (('OR' | 'XOR') and-expr)*
and-expr := cmp-expr ('AND' cmp-expr)*
cmp-expr := add-expr (('EQ' | 'NE' | 'GT' | 'GE' | 'LT' | 'LE') add-expr)*
add-expr := term (('+' | '-') term)*
term := factor (('*' | '/' | 'MOD') factor)*
factor := ('+' | '-')? primary
primary := number
| '#' integer
| '#' '[' expr ']'
| '[' expr ']'
| ident '[' arglist ']' ('/' '[' expr ']')?
arglist := expr (',' expr)*
Function names and keyword operators (MOD, EQ NE GT GE LT LE,
AND OR XOR) are case-insensitive (SIN = sin,
EQ = eq); each keyword requires a non-identifier character
on its right boundary so EQ1 is not the EQ operator
followed by 1. Whitespace is skipped between tokens. The
'/' '[' expr ']' tail captures the dual-bracket form Fanuc uses
for ATAN[a]/[b]; non-ATAN callers that happen to use it produce a
function with an extra arg, which the evaluator rejects with an arity
error.
Operator precedence intentionally puts boolean / logical layers below
arithmetic so #1 + 1 GT 0 parses as (#1 + 1) GT 0 and
#1 GT 0 AND #2 LT 10 parses as (#1 GT 0) AND (#2 LT 10),
matching the Fanuc Custom Macro B spec for IF [..] GOTO /
IF [..] THEN / WHILE [..] DO conditions.
public sealed class NcExpressionParser
- Inheritance
-
NcExpressionParser
- Inherited Members
- Extension Methods
Methods
TryParse(string, out NcExpr, out string)
Parses source. On success, expr is
the AST and error is null. On failure,
expr is null and error
describes the syntax problem.
public static bool TryParse(string source, out NcExpr expr, out string error)