Table of Contents

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 (highest precedence last):

expr    := term (('+' | '-') term)*
term    := factor (('*' | '/' | 'MOD') factor)*
factor  := ('+' | '-')? primary
primary := number
        | '#' integer
        | '#' '[' expr ']'
        | '[' expr ']'
        | ident '[' arglist ']' ('/' '[' expr ']')?
arglist := expr (',' expr)*

Function names are case-insensitive (SIN = sin); 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.

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)

Parameters

source string
expr NcExpr
error string

Returns

bool