This repository has been archived on 2026-10-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
HiNC-2025-win-desktop-Deploy/App/wwwroot/HiAPI-docsite/api/Hi.NcParsers.EvaluationSyntaxs.Siemens.SiemensExpressionParser.html
T

345 lines
18 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Class SiemensExpressionParser | HiAPI-C# 2025 </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="title" content="Class SiemensExpressionParser | HiAPI-C# 2025 ">
<meta name="description" content="Recursive-descent parser for Sinumerik value expressions. Produces the same AST as the Fanuc so is reused unchanged. Pure: no variable lookup, no evaluation. Grammar (lowest precedence at top): expr := or-expr or-expr := and-expr ((&#39;OR&#39; | &#39;XOR&#39;) and-expr)* and-expr := cmp-expr (&#39;AND&#39; cmp-expr)* cmp-expr := add-expr ((&#39;==&#39; | &#39;&amp;lt;&amp;gt;&#39; | &#39;&amp;gt;=&#39; | &#39;&amp;lt;=&#39; | &#39;&amp;gt;&#39; | &#39;&amp;lt;&#39;) add-expr)* add-expr := term ((&#39;+&#39; | &#39;-&#39;) term)* term := factor ((&#39;*&#39; | &#39;/&#39; | &#39;MOD&#39;) factor)* factor := (&#39;+&#39; | &#39;-&#39;)? primary primary := number | &#39;(&#39; expr &#39;)&#39; | &#39;R&#39; digits → variable &quot;R63&quot; (canonical uppercase) | &#39;$&#39; name (&#39;[&#39; indexlist &#39;]&#39;)? → variable &quot;$P_UIFR[1,X,TR]&quot; (canonical) | name &#39;(&#39; arglist &#39;)&#39; → function call | name &#39;[&#39; indexlist &#39;]&#39; → variable &quot;_RENC[35]&quot; (canonical) | name → variable &quot;_X_HOME&quot; (case preserved) indexlist := (integer | name) (&#39;,&#39; (integer | name))* arglist := expr (&#39;,&#39; expr)* Dialect differences from the Fanuc parser: parentheses group and call (Fanuc uses brackets); comparisons are spelled == &amp;lt;&amp;gt; &amp;gt;= &amp;lt;= &amp;gt; &amp;lt; (Fanuc uses EQ NE .. words); bare identifiers are named-variable references (Fanuc rejects an identifier without [); R63 is canonicalised to uppercase so table lookups and Parsing.Assignments keys agree. Indexed accesses ($P_UIFR[1,X,TR], _RENC[35]) require literal index elements (integers, bare letters, or keywords like TR) and are emitted as a single whose key is the canonical uppercase-indexed token — the whole token routes through , keeping the AST brand-agnostic. Function-name aliases are normalised where Sinumerik and the shared evaluator spell the same math differently: ATAN2 → ATAN (both are two-arg atan2 in degrees), TRUNC → FIX (truncate toward zero). Unknown functions (e.g. the rotary positioning form DC(...)) parse fine and fail later in the evaluator, which callers treat as fail-soft.">
<link rel="icon" href="../img/HiAPI.favicon.ico">
<link rel="stylesheet" href="../public/docfx.min.css">
<link rel="stylesheet" href="../public/main.css">
<meta name="docfx:navrel" content="../toc.html">
<meta name="docfx:tocrel" content="toc.html">
<meta name="docfx:rel" content="../">
<meta name="loc:inThisArticle" content="In this article">
<meta name="loc:searchResultsCount" content="{count} results for &quot;{query}&quot;">
<meta name="loc:searchNoResults" content="No results for &quot;{query}&quot;">
<meta name="loc:tocFilter" content="Filter by title">
<meta name="loc:nextArticle" content="Next">
<meta name="loc:prevArticle" content="Previous">
<meta name="loc:themeLight" content="Light">
<meta name="loc:themeDark" content="Dark">
<meta name="loc:themeAuto" content="Auto">
<meta name="loc:changeTheme" content="Change theme">
<meta name="loc:copy" content="Copy">
<meta name="loc:downloadPdf" content="Download PDF">
<script type="module" src="./../public/docfx.min.js"></script>
<script>
const theme = localStorage.getItem('theme') || 'auto'
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
</script>
</head>
<body class="tex2jax_ignore" data-layout="" data-yaml-mime="ManagedReference">
<header class="bg-body border-bottom">
<nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
<div class="container-xxl flex-nowrap">
<a class="navbar-brand" href="../index.html">
<img id="logo" class="svg" src="../img/HiAPI.logo.png" alt="">
</a>
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
<i class="bi bi-three-dots"></i>
</button>
<div class="collapse navbar-collapse" id="navpanel">
<div id="navbar">
<form class="search" role="search" id="search">
<i class="bi bi-search"></i>
<input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
</form>
</div>
</div>
</div>
</nav>
</header>
<main class="container-xxl">
<div class="toc-offcanvas">
<div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<nav class="toc" id="toc"></nav>
</div>
</div>
</div>
<div class="content">
<div class="actionbar">
<button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
<i class="bi bi-list"></i>
</button>
<nav id="breadcrumb"></nav>
</div>
<article data-uid="Hi.NcParsers.EvaluationSyntaxs.Siemens.SiemensExpressionParser">
<h1 id="Hi_NcParsers_EvaluationSyntaxs_Siemens_SiemensExpressionParser" data-uid="Hi.NcParsers.EvaluationSyntaxs.Siemens.SiemensExpressionParser" class="text-break">
Class SiemensExpressionParser
</h1>
<div class="facts text-secondary">
<dl><dt>Namespace</dt><dd><a class="xref" href="Hi.html">Hi</a>.<a class="xref" href="Hi.NcParsers.html">NcParsers</a>.<a class="xref" href="Hi.NcParsers.EvaluationSyntaxs.html">EvaluationSyntaxs</a>.<a class="xref" href="Hi.NcParsers.EvaluationSyntaxs.Siemens.html">Siemens</a></dd></dl>
<dl><dt>Assembly</dt><dd>HiMech.dll</dd></dl>
</div>
<div class="markdown summary"><p>Recursive-descent parser for Sinumerik value expressions. Produces the
same <a class="xref" href="Hi.NcParsers.EvaluationSyntaxs.Evaluation.NcExpr.html">NcExpr</a> AST as the Fanuc
<a class="xref" href="Hi.NcParsers.EvaluationSyntaxs.Evaluation.NcExpressionParser.html">NcExpressionParser</a> so <a class="xref" href="Hi.NcParsers.EvaluationSyntaxs.Evaluation.NcExpressionEvaluator.html">NcExpressionEvaluator</a>
is reused unchanged. Pure: no variable lookup, no evaluation.</p>
<p>Grammar (lowest precedence at top):</p>
<pre><code class="lang-csharp">expr := or-expr
or-expr := and-expr (('OR' | 'XOR') and-expr)*
and-expr := cmp-expr ('AND' cmp-expr)*
cmp-expr := add-expr (('==' | '&lt;&gt;' | '&gt;=' | '&lt;=' | '&gt;' | '&lt;') add-expr)*
add-expr := term (('+' | '-') term)*
term := factor (('*' | '/' | 'MOD') factor)*
factor := ('+' | '-')? primary
primary := number
| '(' expr ')'
| 'R' digits → variable "R63" (canonical uppercase)
| '$' name ('[' indexlist ']')? → variable "$P_UIFR[1,X,TR]" (canonical)
| name '(' arglist ')' → function call
| name '[' indexlist ']' → variable "_RENC[35]" (canonical)
| name → variable "_X_HOME" (case preserved)
indexlist := (integer | name) (',' (integer | name))*
arglist := expr (',' expr)*</code></pre>
<p>
Dialect differences from the Fanuc parser: parentheses group and call
(Fanuc uses brackets); comparisons are spelled <code>==</code> <code>&lt;&gt;</code>
<code>&gt;=</code> <code>&lt;=</code> <code>&gt;</code> <code>&lt;</code> (Fanuc uses
<code>EQ NE ..</code> words); bare identifiers are named-variable references
(Fanuc rejects an identifier without <code>[</code>); <code>R63</code> is
canonicalised to uppercase so table lookups and
<code>Parsing.Assignments</code> keys agree. Indexed accesses
(<code>$P_UIFR[1,X,TR]</code>, <code>_RENC[35]</code>) require literal index
elements (integers, bare letters, or keywords like <code>TR</code>) and are
emitted as a single <a class="xref" href="Hi.NcParsers.EvaluationSyntaxs.Evaluation.NcVariableExpr.html">NcVariableExpr</a> whose key is the
canonical uppercase-indexed token — the whole token routes through
<a class="xref" href="Hi.NcParsers.EvaluationSyntaxs.Evaluation.IVariableLookup.html#Hi_NcParsers_EvaluationSyntaxs_Evaluation_IVariableLookup_Get_System_String_">Get(string)</a>, keeping the AST brand-agnostic.
Function-name aliases are normalised where Sinumerik and the shared
evaluator spell the same math differently: <code>ATAN2</code> → <code>ATAN</code>
(both are two-arg atan2 in degrees), <code>TRUNC</code> → <code>FIX</code>
(truncate toward zero). Unknown functions (e.g. the rotary positioning
form <code>DC(...)</code>) parse fine and fail later in the evaluator, which
callers treat as fail-soft.
</p>
</div>
<div class="markdown conceptual"></div>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public sealed class SiemensExpressionParser</code></pre>
</div>
<dl class="typelist inheritance">
<dt>Inheritance</dt>
<dd>
<div><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></div>
<div><span class="xref">SiemensExpressionParser</span></div>
</dd>
</dl>
<dl class="typelist inheritedMembers">
<dt>Inherited Members</dt>
<dd>
<div>
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object)</a>
</div>
<div>
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object, object)</a>
</div>
<div>
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a>
</div>
<div>
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>
</div>
<div>
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object, object)</a>
</div>
<div>
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>
</div>
</dd></dl>
<dl class="typelist extensionMethods">
<dt>Extension Methods</dt>
<dd>
<div>
<a class="xref" href="Hi.Common.DuplicateUtil.html#Hi_Common_DuplicateUtil_TryDuplicate__1___0_System_Object___">DuplicateUtil.TryDuplicate&lt;TSelf&gt;(TSelf, params object[])</a>
</div>
<div>
<a class="xref" href="Hi.Common.InvokeUtil.html#Hi_Common_InvokeUtil_SelfInvoke__1___0_System_Action___0__">InvokeUtil.SelfInvoke&lt;TSrc&gt;(TSrc, Action&lt;TSrc&gt;)</a>
</div>
<div>
<a class="xref" href="Hi.Common.InvokeUtil.html#Hi_Common_InvokeUtil_SelfInvoke__2___0_System_Func___0___1__">InvokeUtil.SelfInvoke&lt;TSrc, TDst&gt;(TSrc, Func&lt;TSrc, TDst&gt;)</a>
</div>
<div>
<a class="xref" href="Hi.Coloring.ColorUtil.html#Hi_Coloring_ColorUtil_GetGloomyColor_System_Object_System_Double_System_Double_">ColorUtil.GetGloomyColor(object, double, double)</a>
</div>
<div>
<a class="xref" href="Hi.Common.NameUtil.html#Hi_Common_NameUtil_GetSelectionName_System_Object_">NameUtil.GetSelectionName(object)</a>
</div>
<div>
<a class="xref" href="Hi.Common.StringUtil.html#Hi_Common_StringUtil_GetPropertyStringIfToStringNotOverloaded_System_Object_System_Boolean_System_Boolean_">StringUtil.GetPropertyStringIfToStringNotOverloaded(object, bool, bool)</a>
</div>
<div>
<a class="xref" href="Hi.Parallels.LockUtil.html#Hi_Parallels_LockUtil_Lock_System_Object_">LockUtil.Lock(object)</a>
</div>
</dd></dl>
<h2 class="section" id="methods">Methods
</h2>
<a id="Hi_NcParsers_EvaluationSyntaxs_Siemens_SiemensExpressionParser_TryParse_" data-uid="Hi.NcParsers.EvaluationSyntaxs.Siemens.SiemensExpressionParser.TryParse*"></a>
<h3 id="Hi_NcParsers_EvaluationSyntaxs_Siemens_SiemensExpressionParser_TryParse_System_String_Hi_NcParsers_EvaluationSyntaxs_Evaluation_NcExpr__System_String__" data-uid="Hi.NcParsers.EvaluationSyntaxs.Siemens.SiemensExpressionParser.TryParse(System.String,Hi.NcParsers.EvaluationSyntaxs.Evaluation.NcExpr@,System.String@)">
TryParse(string, out NcExpr, out string)
</h3>
<div class="markdown level1 summary"><p>Parses <code class="paramref">source</code> requiring the whole string to be
consumed. On success, <code class="paramref">expr</code> is the AST and
<code class="paramref">error</code> is <code>null</code>. On failure,
<code class="paramref">expr</code> is <code>null</code> and <code class="paramref">error</code>
describes the syntax problem.</p>
</div>
<div class="markdown level1 conceptual"></div>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public static bool TryParse(string source, out NcExpr expr, out string error)</code></pre>
</div>
<h4 class="section">Parameters</h4>
<dl class="parameters">
<dt><code>source</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
<dd></dd>
<dt><code>expr</code> <a class="xref" href="Hi.NcParsers.EvaluationSyntaxs.Evaluation.NcExpr.html">NcExpr</a></dt>
<dd></dd>
<dt><code>error</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
<dd></dd>
</dl>
<h4 class="section">Returns</h4>
<dl class="parameters">
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a></dt>
<dd></dd>
</dl>
<a id="Hi_NcParsers_EvaluationSyntaxs_Siemens_SiemensExpressionParser_TryParsePrefix_" data-uid="Hi.NcParsers.EvaluationSyntaxs.Siemens.SiemensExpressionParser.TryParsePrefix*"></a>
<h3 id="Hi_NcParsers_EvaluationSyntaxs_Siemens_SiemensExpressionParser_TryParsePrefix_System_String_Hi_NcParsers_EvaluationSyntaxs_Evaluation_NcExpr__System_Int32__System_String__" data-uid="Hi.NcParsers.EvaluationSyntaxs.Siemens.SiemensExpressionParser.TryParsePrefix(System.String,Hi.NcParsers.EvaluationSyntaxs.Evaluation.NcExpr@,System.Int32@,System.String@)">
TryParsePrefix(string, out NcExpr, out int, out string)
</h3>
<div class="markdown level1 summary"><p>Parses the longest valid expression prefix of <code class="paramref">source</code>.
On success, <code class="paramref">consumedLength</code> is the number of leading
characters that form the expression (trailing text from that offset on
is the caller's to keep, e.g. as remaining <code>UnparsedText</code>).
Fails only when not even a prefix parses (e.g. the text starts with a
quote or an operator dangles at end-of-input) — callers fall back to
their legacy lexical capture in that case.</p>
<p>
This is the parser-delimited RHS boundary: the expression grammar
itself decides where the right-hand side ends, so whitespace inside
expressions (<code>R64 - 14/2</code>), balanced call parentheses
(<code>DC(47.296)</code>) and a following non-expression word
(<code>R24=14 R26=...</code> / <code>F=R103 X-204.</code>) all resolve without
lexical boundary regexes or <code>TerminateWords</code>.
</p>
</div>
<div class="markdown level1 conceptual"></div>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public static bool TryParsePrefix(string source, out NcExpr expr, out int consumedLength, out string error)</code></pre>
</div>
<h4 class="section">Parameters</h4>
<dl class="parameters">
<dt><code>source</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
<dd></dd>
<dt><code>expr</code> <a class="xref" href="Hi.NcParsers.EvaluationSyntaxs.Evaluation.NcExpr.html">NcExpr</a></dt>
<dd></dd>
<dt><code>consumedLength</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></dt>
<dd></dd>
<dt><code>error</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
<dd></dd>
</dl>
<h4 class="section">Returns</h4>
<dl class="parameters">
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a></dt>
<dd></dd>
</dl>
</article>
<div class="contribution d-print-none">
</div>
</div>
<div class="affix">
<nav id="affix"></nav>
</div>
</main>
<div class="container-xxl search-results" id="search-results"></div>
<footer class="border-top text-secondary">
<div class="container-xxl">
<div class="flex-fill">
<span> Copyright © 2025 <a href='https://superhightech.com.tw'>Tech Coordinate</a>. All rights reserved. <a href='https://superhightech.com.tw'>超級高科技股份有限公司</a> © 2025 版權所有 </span>
</div>
</div>
</footer>
</body>
</html>