Math Engine Reference: Expression
문서 탐색
개요
Reentrant UTF-8 expression lexer, Pratt parser and pointer-free AST wire format.
Parsing never evaluates source text. Tokens, nodes, diagnostics and serialization buffers are caller-owned. AST nodes contain only indices and source spans; no GUI, Python, registry or numeric-backend pointer crosses the C ABI.
- 실행 원본:
include/math_engine/math_engine_expression.h - 분류: 식·CAS·계산기·plot
관련 public header
공개 API
Header 사용 시작
이 module의 public declaration을 사용하려면 installed SDK의 다음 header를 include한다.
#include <math_engine/math_engine_expression.h>
Type과 callback
math_engine_expression_grammar_profile_t
Compact grammar는 embedded-safe이고 desktop은 call, assignment, unit, Unicode name을 더한다.
typedef enum math_engine_expression_grammar_profile {
/** ASCII identifier와 literal, prefix/binary operator, grouping만 허용하는 embedded-safe grammar다. */
MATH_ENGINE_EXPRESSION_GRAMMAR_COMPACT = 1,
/** Assignment, call, unit suffix와 Unicode identifier를 선택적으로 허용하는 desktop grammar다. */
MATH_ENGINE_EXPRESSION_GRAMMAR_DESKTOP = 2
} math_engine_expression_grammar_profile_t;
math_engine_expression_grammar_profile_t.MATH_ENGINE_EXPRESSION_GRAMMAR_COMPACT
ASCII identifier와 literal, prefix/binary operator, grouping만 허용하는 embedded-safe grammar다.
/** ASCII identifier와 literal, prefix/binary operator, grouping만 허용하는 embedded-safe grammar다. */ MATH_ENGINE_EXPRESSION_GRAMMAR_COMPACT = 1,math_engine_expression_grammar_profile_t.MATH_ENGINE_EXPRESSION_GRAMMAR_DESKTOP
Assignment, call, unit suffix와 Unicode identifier를 선택적으로 허용하는 desktop grammar다.
/** Assignment, call, unit suffix와 Unicode identifier를 선택적으로 허용하는 desktop grammar다. */ MATH_ENGINE_EXPRESSION_GRAMMAR_DESKTOP = 2,
math_engine_expression_token_kind_t
모든 grammar profile이 공유하며 append-only인 token 식별자다.
typedef enum math_engine_expression_token_kind {
/** Input 끝의 zero-length terminal token이며 token stream에 정확히 한 번 포함된다. */
MATH_ENGINE_EXPRESSION_TOKEN_END = 0,
/** Integer, decimal 또는 scientific ASCII numeric literal token이다. */
MATH_ENGINE_EXPRESSION_TOKEN_NUMBER = 1,
/** ASCII 또는 허용된 UTF-8 Unicode identifier token이다. */
MATH_ENGINE_EXPRESSION_TOKEN_IDENTIFIER = 2,
/** 단일 ASCII =+= token이다. */
MATH_ENGINE_EXPRESSION_TOKEN_PLUS = 3,
/** 단일 ASCII =-= token이다. */
MATH_ENGINE_EXPRESSION_TOKEN_MINUS = 4,
/** 단일 ASCII =*= token이다. */
MATH_ENGINE_EXPRESSION_TOKEN_STAR = 5,
/** 단일 ASCII =/= token이다. */
MATH_ENGINE_EXPRESSION_TOKEN_SLASH = 6,
/** 단일 ASCII =%= token이다. */
MATH_ENGINE_EXPRESSION_TOKEN_PERCENT = 7,
/** Exponent/unit power에 사용하는 단일 ASCII =^= token이다. */
MATH_ENGINE_EXPRESSION_TOKEN_CARET = 8,
/** 단일 ASCII =(= token이다. */
MATH_ENGINE_EXPRESSION_TOKEN_LEFT_PAREN = 9,
/** 단일 ASCII =)= token이다. */
MATH_ENGINE_EXPRESSION_TOKEN_RIGHT_PAREN = 10,
/** Call argument를 구분하는 단일 ASCII comma token이다. */
MATH_ENGINE_EXPRESSION_TOKEN_COMMA = 11,
/** Assignment에 사용하는 단일 ASCII === token이다. */
MATH_ENGINE_EXPRESSION_TOKEN_EQUAL = 12,
/** Lexer가 허용하지 않는 byte/code point를 만났음을 나타내는 token kind다. */
MATH_ENGINE_EXPRESSION_TOKEN_INVALID = 13
} math_engine_expression_token_kind_t;
math_engine_expression_token_kind_t.MATH_ENGINE_EXPRESSION_TOKEN_END
Input 끝의 zero-length terminal token이며 token stream에 정확히 한 번 포함된다.
/** Input 끝의 zero-length terminal token이며 token stream에 정확히 한 번 포함된다. */ MATH_ENGINE_EXPRESSION_TOKEN_END = 0,math_engine_expression_token_kind_t.MATH_ENGINE_EXPRESSION_TOKEN_NUMBER
Integer, decimal 또는 scientific ASCII numeric literal token이다.
/** Integer, decimal 또는 scientific ASCII numeric literal token이다. */ MATH_ENGINE_EXPRESSION_TOKEN_NUMBER = 1,math_engine_expression_token_kind_t.MATH_ENGINE_EXPRESSION_TOKEN_IDENTIFIER
ASCII 또는 허용된 UTF-8 Unicode identifier token이다.
/** ASCII 또는 허용된 UTF-8 Unicode identifier token이다. */ MATH_ENGINE_EXPRESSION_TOKEN_IDENTIFIER = 2,math_engine_expression_token_kind_t.MATH_ENGINE_EXPRESSION_TOKEN_PLUS
단일 ASCII
+token이다./** 단일 ASCII =+= token이다. */ MATH_ENGINE_EXPRESSION_TOKEN_PLUS = 3,math_engine_expression_token_kind_t.MATH_ENGINE_EXPRESSION_TOKEN_MINUS
단일 ASCII
-token이다./** 단일 ASCII =-= token이다. */ MATH_ENGINE_EXPRESSION_TOKEN_MINUS = 4,math_engine_expression_token_kind_t.MATH_ENGINE_EXPRESSION_TOKEN_STAR
단일 ASCII
*token이다./** 단일 ASCII =*= token이다. */ MATH_ENGINE_EXPRESSION_TOKEN_STAR = 5,math_engine_expression_token_kind_t.MATH_ENGINE_EXPRESSION_TOKEN_SLASH
단일 ASCII
/token이다./** 단일 ASCII =/= token이다. */ MATH_ENGINE_EXPRESSION_TOKEN_SLASH = 6,math_engine_expression_token_kind_t.MATH_ENGINE_EXPRESSION_TOKEN_PERCENT
단일 ASCII
%token이다./** 단일 ASCII =%= token이다. */ MATH_ENGINE_EXPRESSION_TOKEN_PERCENT = 7,math_engine_expression_token_kind_t.MATH_ENGINE_EXPRESSION_TOKEN_CARET
Exponent/unit power에 사용하는 단일 ASCII
^token이다./** Exponent/unit power에 사용하는 단일 ASCII =^= token이다. */ MATH_ENGINE_EXPRESSION_TOKEN_CARET = 8,math_engine_expression_token_kind_t.MATH_ENGINE_EXPRESSION_TOKEN_LEFT_PAREN
단일 ASCII
(token이다./** 단일 ASCII =(= token이다. */ MATH_ENGINE_EXPRESSION_TOKEN_LEFT_PAREN = 9,math_engine_expression_token_kind_t.MATH_ENGINE_EXPRESSION_TOKEN_RIGHT_PAREN
단일 ASCII
)token이다./** 단일 ASCII =)= token이다. */ MATH_ENGINE_EXPRESSION_TOKEN_RIGHT_PAREN = 10,math_engine_expression_token_kind_t.MATH_ENGINE_EXPRESSION_TOKEN_COMMA
Call argument를 구분하는 단일 ASCII comma token이다.
/** Call argument를 구분하는 단일 ASCII comma token이다. */ MATH_ENGINE_EXPRESSION_TOKEN_COMMA = 11,math_engine_expression_token_kind_t.MATH_ENGINE_EXPRESSION_TOKEN_EQUAL
Assignment에 사용하는 단일 ASCII
=token이다./** Assignment에 사용하는 단일 ASCII === token이다. */ MATH_ENGINE_EXPRESSION_TOKEN_EQUAL = 12,math_engine_expression_token_kind_t.MATH_ENGINE_EXPRESSION_TOKEN_INVALID
Lexer가 허용하지 않는 byte/code point를 만났음을 나타내는 token kind다.
/** Lexer가 허용하지 않는 byte/code point를 만났음을 나타내는 token kind다. */ MATH_ENGINE_EXPRESSION_TOKEN_INVALID = 13,
math_engine_expression_node_kind_t
Pointer-free immutable AST node 식별자다.
typedef enum math_engine_expression_node_kind {
/** =value_span=의 NUMBER token을 나타내는 leaf node다. */
MATH_ENGINE_EXPRESSION_NODE_LITERAL = 1,
/** =value_span=의 IDENTIFIER token을 나타내는 leaf node다. */
MATH_ENGINE_EXPRESSION_NODE_SYMBOL = 2,
/** =left= operand에 unary plus/minus를 적용하는 node다. */
MATH_ENGINE_EXPRESSION_NODE_PREFIX = 3,
/** =left=와 =right= operand에 binary operator를 적용하는 node다. */
MATH_ENGINE_EXPRESSION_NODE_BINARY = 4,
/** =left= callee와 =first_child=/=next_sibling= argument chain을 갖는 call node다. */
MATH_ENGINE_EXPRESSION_NODE_CALL = 5,
/** =left= symbol target에 =right= expression을 할당하는 desktop node다. */
MATH_ENGINE_EXPRESSION_NODE_ASSIGNMENT = 6,
/** =left= numeric expression에 =value_span=의 unit expression을 붙이는 desktop node다. */
MATH_ENGINE_EXPRESSION_NODE_UNIT_SUFFIX = 7
} math_engine_expression_node_kind_t;
math_engine_expression_node_kind_t.MATH_ENGINE_EXPRESSION_NODE_LITERAL
value_span의 NUMBER token을 나타내는 leaf node다./** =value_span=의 NUMBER token을 나타내는 leaf node다. */ MATH_ENGINE_EXPRESSION_NODE_LITERAL = 1,math_engine_expression_node_kind_t.MATH_ENGINE_EXPRESSION_NODE_SYMBOL
value_span의 IDENTIFIER token을 나타내는 leaf node다./** =value_span=의 IDENTIFIER token을 나타내는 leaf node다. */ MATH_ENGINE_EXPRESSION_NODE_SYMBOL = 2,math_engine_expression_node_kind_t.MATH_ENGINE_EXPRESSION_NODE_PREFIX
leftoperand에 unary plus/minus를 적용하는 node다./** =left= operand에 unary plus/minus를 적용하는 node다. */ MATH_ENGINE_EXPRESSION_NODE_PREFIX = 3,math_engine_expression_node_kind_t.MATH_ENGINE_EXPRESSION_NODE_BINARY
left와rightoperand에 binary operator를 적용하는 node다./** =left=와 =right= operand에 binary operator를 적용하는 node다. */ MATH_ENGINE_EXPRESSION_NODE_BINARY = 4,math_engine_expression_node_kind_t.MATH_ENGINE_EXPRESSION_NODE_CALL
leftcallee와first_child=/=next_siblingargument chain을 갖는 call node다./** =left= callee와 =first_child=/=next_sibling= argument chain을 갖는 call node다. */ MATH_ENGINE_EXPRESSION_NODE_CALL = 5,math_engine_expression_node_kind_t.MATH_ENGINE_EXPRESSION_NODE_ASSIGNMENT
leftsymbol target에rightexpression을 할당하는 desktop node다./** =left= symbol target에 =right= expression을 할당하는 desktop node다. */ MATH_ENGINE_EXPRESSION_NODE_ASSIGNMENT = 6,math_engine_expression_node_kind_t.MATH_ENGINE_EXPRESSION_NODE_UNIT_SUFFIX
leftnumeric expression에value_span의 unit expression을 붙이는 desktop node다./** =left= numeric expression에 =value_span=의 unit expression을 붙이는 desktop node다. */ MATH_ENGINE_EXPRESSION_NODE_UNIT_SUFFIX = 7,
math_engine_expression_diagnostic_severity_t
Parser-independent diagnostic 심각도다.
typedef enum math_engine_expression_diagnostic_severity {
/** 요청을 성공시키지 못하는 syntax/encoding/budget 오류다. */
MATH_ENGINE_EXPRESSION_DIAGNOSTIC_ERROR = 1,
/** 결과는 사용할 수 있지만 caller 주의가 필요한 비치명 문제다. */
MATH_ENGINE_EXPRESSION_DIAGNOSTIC_WARNING = 2,
/** 오류가 아닌 추가 source 위치 또는 해석 정보다. */
MATH_ENGINE_EXPRESSION_DIAGNOSTIC_NOTE = 3
} math_engine_expression_diagnostic_severity_t;
math_engine_expression_diagnostic_severity_t.MATH_ENGINE_EXPRESSION_DIAGNOSTIC_ERROR
요청을 성공시키지 못하는 syntax/encoding/budget 오류다.
/** 요청을 성공시키지 못하는 syntax/encoding/budget 오류다. */ MATH_ENGINE_EXPRESSION_DIAGNOSTIC_ERROR = 1,math_engine_expression_diagnostic_severity_t.MATH_ENGINE_EXPRESSION_DIAGNOSTIC_WARNING
결과는 사용할 수 있지만 caller 주의가 필요한 비치명 문제다.
/** 결과는 사용할 수 있지만 caller 주의가 필요한 비치명 문제다. */ MATH_ENGINE_EXPRESSION_DIAGNOSTIC_WARNING = 2,math_engine_expression_diagnostic_severity_t.MATH_ENGINE_EXPRESSION_DIAGNOSTIC_NOTE
오류가 아닌 추가 source 위치 또는 해석 정보다.
/** 오류가 아닌 추가 source 위치 또는 해석 정보다. */ MATH_ENGINE_EXPRESSION_DIAGNOSTIC_NOTE = 3,
math_engine_expression_diagnostic_code_t
안정된 parser-independent diagnostic 식별자다.
typedef enum math_engine_expression_diagnostic_code {
/** Source에 well-formed UTF-8이 아닌 byte sequence가 있다. */
MATH_ENGINE_EXPRESSION_DIAGNOSTIC_INVALID_UTF8 = 1,
/** 명시적 =source_size= 안에 NUL byte가 있다. */
MATH_ENGINE_EXPRESSION_DIAGNOSTIC_EMBEDDED_NUL = 2,
/** 어떤 public token kind에도 속하지 않는 character가 있다. */
MATH_ENGINE_EXPRESSION_DIAGNOSTIC_INVALID_CHARACTER = 3,
/** Numeric literal의 decimal/exponent 문법이 완전하지 않다. */
MATH_ENGINE_EXPRESSION_DIAGNOSTIC_INVALID_NUMBER = 4,
/** Option 또는 context evaluation budget의 token ceiling에 도달했다. */
MATH_ENGINE_EXPRESSION_DIAGNOSTIC_TOKEN_LIMIT = 5,
/** Option 또는 caller workspace의 AST node ceiling에 도달했다. */
MATH_ENGINE_EXPRESSION_DIAGNOSTIC_NODE_LIMIT = 6,
/** Pratt recursion이 =maximum_depth=를 초과했다. */
MATH_ENGINE_EXPRESSION_DIAGNOSTIC_DEPTH_LIMIT = 7,
/** 현재 위치에서 literal, symbol, prefix 또는 parenthesized expression이 필요하다. */
MATH_ENGINE_EXPRESSION_DIAGNOSTIC_EXPECTED_EXPRESSION = 8,
/** 현재 grammar 위치에서 허용되지 않은 token을 만났다. */
MATH_ENGINE_EXPRESSION_DIAGNOSTIC_UNEXPECTED_TOKEN = 9,
/** Group 또는 call을 닫는 RIGHT_PAREN token이 필요하다. */
MATH_ENGINE_EXPRESSION_DIAGNOSTIC_EXPECTED_RIGHT_PAREN = 10,
/** Assignment의 왼쪽 node가 assignable symbol이 아니다. */
MATH_ENGINE_EXPRESSION_DIAGNOSTIC_INVALID_ASSIGNMENT_TARGET = 11,
/** 선택 profile/flag/build에서 해당 syntax를 지원하지 않는다. */
MATH_ENGINE_EXPRESSION_DIAGNOSTIC_UNSUPPORTED_GRAMMAR = 12,
/** Unit identifier, 곱/나눗셈 또는 signed integer exponent sequence가 잘못되었다. */
MATH_ENGINE_EXPRESSION_DIAGNOSTIC_INVALID_UNIT_SUFFIX = 13,
/** 완전한 expression 뒤에 END 이외 token이 남았다. */
MATH_ENGINE_EXPRESSION_DIAGNOSTIC_TRAILING_INPUT = 14
} math_engine_expression_diagnostic_code_t;
math_engine_expression_diagnostic_code_t.MATH_ENGINE_EXPRESSION_DIAGNOSTIC_INVALID_UTF8
Source에 well-formed UTF-8이 아닌 byte sequence가 있다.
/** Source에 well-formed UTF-8이 아닌 byte sequence가 있다. */ MATH_ENGINE_EXPRESSION_DIAGNOSTIC_INVALID_UTF8 = 1,math_engine_expression_diagnostic_code_t.MATH_ENGINE_EXPRESSION_DIAGNOSTIC_EMBEDDED_NUL
명시적
source_size안에 NUL byte가 있다./** 명시적 =source_size= 안에 NUL byte가 있다. */ MATH_ENGINE_EXPRESSION_DIAGNOSTIC_EMBEDDED_NUL = 2,math_engine_expression_diagnostic_code_t.MATH_ENGINE_EXPRESSION_DIAGNOSTIC_INVALID_CHARACTER
어떤 public token kind에도 속하지 않는 character가 있다.
/** 어떤 public token kind에도 속하지 않는 character가 있다. */ MATH_ENGINE_EXPRESSION_DIAGNOSTIC_INVALID_CHARACTER = 3,math_engine_expression_diagnostic_code_t.MATH_ENGINE_EXPRESSION_DIAGNOSTIC_INVALID_NUMBER
Numeric literal의 decimal/exponent 문법이 완전하지 않다.
/** Numeric literal의 decimal/exponent 문법이 완전하지 않다. */ MATH_ENGINE_EXPRESSION_DIAGNOSTIC_INVALID_NUMBER = 4,math_engine_expression_diagnostic_code_t.MATH_ENGINE_EXPRESSION_DIAGNOSTIC_TOKEN_LIMIT
Option 또는 context evaluation budget의 token ceiling에 도달했다.
/** Option 또는 context evaluation budget의 token ceiling에 도달했다. */ MATH_ENGINE_EXPRESSION_DIAGNOSTIC_TOKEN_LIMIT = 5,math_engine_expression_diagnostic_code_t.MATH_ENGINE_EXPRESSION_DIAGNOSTIC_NODE_LIMIT
Option 또는 caller workspace의 AST node ceiling에 도달했다.
/** Option 또는 caller workspace의 AST node ceiling에 도달했다. */ MATH_ENGINE_EXPRESSION_DIAGNOSTIC_NODE_LIMIT = 6,math_engine_expression_diagnostic_code_t.MATH_ENGINE_EXPRESSION_DIAGNOSTIC_DEPTH_LIMIT
Pratt recursion이
maximum_depth를 초과했다./** Pratt recursion이 =maximum_depth=를 초과했다. */ MATH_ENGINE_EXPRESSION_DIAGNOSTIC_DEPTH_LIMIT = 7,math_engine_expression_diagnostic_code_t.MATH_ENGINE_EXPRESSION_DIAGNOSTIC_EXPECTED_EXPRESSION
현재 위치에서 literal, symbol, prefix 또는 parenthesized expression이 필요하다.
/** 현재 위치에서 literal, symbol, prefix 또는 parenthesized expression이 필요하다. */ MATH_ENGINE_EXPRESSION_DIAGNOSTIC_EXPECTED_EXPRESSION = 8,math_engine_expression_diagnostic_code_t.MATH_ENGINE_EXPRESSION_DIAGNOSTIC_UNEXPECTED_TOKEN
현재 grammar 위치에서 허용되지 않은 token을 만났다.
/** 현재 grammar 위치에서 허용되지 않은 token을 만났다. */ MATH_ENGINE_EXPRESSION_DIAGNOSTIC_UNEXPECTED_TOKEN = 9,math_engine_expression_diagnostic_code_t.MATH_ENGINE_EXPRESSION_DIAGNOSTIC_EXPECTED_RIGHT_PAREN
Group 또는 call을 닫는 RIGHT_PAREN token이 필요하다.
/** Group 또는 call을 닫는 RIGHT_PAREN token이 필요하다. */ MATH_ENGINE_EXPRESSION_DIAGNOSTIC_EXPECTED_RIGHT_PAREN = 10,math_engine_expression_diagnostic_code_t.MATH_ENGINE_EXPRESSION_DIAGNOSTIC_INVALID_ASSIGNMENT_TARGET
Assignment의 왼쪽 node가 assignable symbol이 아니다.
/** Assignment의 왼쪽 node가 assignable symbol이 아니다. */ MATH_ENGINE_EXPRESSION_DIAGNOSTIC_INVALID_ASSIGNMENT_TARGET = 11,math_engine_expression_diagnostic_code_t.MATH_ENGINE_EXPRESSION_DIAGNOSTIC_UNSUPPORTED_GRAMMAR
선택 profile/flag/build에서 해당 syntax를 지원하지 않는다.
/** 선택 profile/flag/build에서 해당 syntax를 지원하지 않는다. */ MATH_ENGINE_EXPRESSION_DIAGNOSTIC_UNSUPPORTED_GRAMMAR = 12,math_engine_expression_diagnostic_code_t.MATH_ENGINE_EXPRESSION_DIAGNOSTIC_INVALID_UNIT_SUFFIX
Unit identifier, 곱/나눗셈 또는 signed integer exponent sequence가 잘못되었다.
/** Unit identifier, 곱/나눗셈 또는 signed integer exponent sequence가 잘못되었다. */ MATH_ENGINE_EXPRESSION_DIAGNOSTIC_INVALID_UNIT_SUFFIX = 13,math_engine_expression_diagnostic_code_t.MATH_ENGINE_EXPRESSION_DIAGNOSTIC_TRAILING_INPUT
완전한 expression 뒤에 END 이외 token이 남았다.
/** 완전한 expression 뒤에 END 이외 token이 남았다. */ MATH_ENGINE_EXPRESSION_DIAGNOSTIC_TRAILING_INPUT = 14,
math_engine_expression_span_t
Byte offset는 half-open이고 line/column은 1-based Unicode code-point 위치인 source span이다.
typedef struct math_engine_expression_span {
/** Source 시작에서 span 첫 byte까지의 zero-based offset. 범위는 =[0,source_size]=이다. */
uint32_t byte_begin;
/** Span 직후 byte의 exclusive offset이며 =byte_begin <= byte_end <= source_size=다. */
uint32_t byte_end;
/** Span 시작 cursor의 1-based line 번호다. */
uint32_t line_begin;
/** Span 시작 cursor의 1-based Unicode code-point column 번호다. */
uint32_t column_begin;
/** Span 끝 exclusive cursor의 1-based line 번호다. */
uint32_t line_end;
/** Span 끝 exclusive cursor의 1-based Unicode code-point column 번호다. */
uint32_t column_end;
} math_engine_expression_span_t;
math_engine_expression_span_t.byte_begin
Source 시작에서 span 첫 byte까지의 zero-based offset. 범위는 =[0,source_size]=이다.
/** Source 시작에서 span 첫 byte까지의 zero-based offset. 범위는 =[0,source_size]=이다. */ uint32_t byte_begin;math_engine_expression_span_t.byte_end
Span 직후 byte의 exclusive offset이며
byte_begin <byte_end <= source_size=다./** Span 직후 byte의 exclusive offset이며 =byte_begin <= byte_end <= source_size=다. */ uint32_t byte_end;math_engine_expression_span_t.line_begin
Span 시작 cursor의 1-based line 번호다.
/** Span 시작 cursor의 1-based line 번호다. */ uint32_t line_begin;math_engine_expression_span_t.column_begin
Span 시작 cursor의 1-based Unicode code-point column 번호다.
/** Span 시작 cursor의 1-based Unicode code-point column 번호다. */ uint32_t column_begin;math_engine_expression_span_t.line_end
Span 끝 exclusive cursor의 1-based line 번호다.
/** Span 끝 exclusive cursor의 1-based line 번호다. */ uint32_t line_end;math_engine_expression_span_t.column_end
Span 끝 exclusive cursor의 1-based Unicode code-point column 번호다.
/** Span 끝 exclusive cursor의 1-based Unicode code-point column 번호다. */ uint32_t column_end;
math_engine_expression_token_t
Source storage를 참조하지 않는 token kind, span과 lexeme fingerprint다.
typedef struct math_engine_expression_token {
/** Lexer가 쓰는 exact ABI byte size인 =sizeof(math_engine_expression_token_t)=이다. */
uint32_t struct_size;
/** =MATH_ENGINE_EXPRESSION_TOKEN_VERSION_1=인 ABI version이다. */
uint32_t version;
/** 이 lexeme의 =math_engine_expression_token_kind_t= 값이다. */
uint32_t kind;
/** Token kind에 적용되는 =MATH_ENGINE_EXPRESSION_TOKEN_FLAG_*= bitset이다. */
uint32_t flags;
/** 원본 source에서 lexeme가 차지하는 half-open byte/code-point 범위다. */
math_engine_expression_span_t span;
/** =source[byte_begin:byte_end]=의 byte-exact FNV-1a64 값이다. Empty END는 offset basis다. */
uint64_t lexeme_fingerprint;
} math_engine_expression_token_t;
math_engine_expression_token_t.struct_size
Lexer가 쓰는 exact ABI byte size인
sizeof(math_engine_expression_token_t)이다./** Lexer가 쓰는 exact ABI byte size인 =sizeof(math_engine_expression_token_t)=이다. */ uint32_t struct_size;math_engine_expression_token_t.version
MATH_ENGINE_EXPRESSION_TOKEN_VERSION_1인 ABI version이다./** =MATH_ENGINE_EXPRESSION_TOKEN_VERSION_1=인 ABI version이다. */ uint32_t version;math_engine_expression_token_t.kind
이 lexeme의
math_engine_expression_token_kind_t값이다./** 이 lexeme의 =math_engine_expression_token_kind_t= 값이다. */ uint32_t kind;math_engine_expression_token_t.flags
Token kind에 적용되는
MATH_ENGINE_EXPRESSION_TOKEN_FLAG_*bitset이다./** Token kind에 적용되는 =MATH_ENGINE_EXPRESSION_TOKEN_FLAG_*= bitset이다. */ uint32_t flags;math_engine_expression_token_t.span
원본 source에서 lexeme가 차지하는 half-open byte/code-point 범위다.
/** 원본 source에서 lexeme가 차지하는 half-open byte/code-point 범위다. */ math_engine_expression_span_t span;math_engine_expression_token_t.lexeme_fingerprint
source[byte_begin:byte_end]의 byte-exact FNV-1a64 값이다. Empty END는 offset basis다./** =source[byte_begin:byte_end]=의 byte-exact FNV-1a64 값이다. Empty END는 offset basis다. */ uint64_t lexeme_fingerprint;
math_engine_expression_diagnostic_t
Stable code, severity, 관련 source span과 expected-token bitset을 담는 diagnostic이다.
typedef struct math_engine_expression_diagnostic {
/** Producer가 쓰는 exact ABI byte size인 =sizeof(math_engine_expression_diagnostic_t)=이다. */
uint32_t struct_size;
/** =MATH_ENGINE_EXPRESSION_DIAGNOSTIC_VERSION_1=인 ABI version이다. */
uint32_t version;
/** Stable =math_engine_expression_diagnostic_code_t= 값이다. */
uint32_t code;
/** =math_engine_expression_diagnostic_severity_t= 값이다. */
uint32_t severity;
/** 문제의 주 source 범위이며 byte offset는 half-open이다. */
math_engine_expression_span_t primary_span;
/** 추가 관련 source 범위. 별도 관련 위치가 없으면 =primary_span=과 같다. */
math_engine_expression_span_t related_span;
/** Expected token kind =k=를 bit =1ULL<<k=로 표시하며 expectation이 없으면 0이다. */
uint64_t expected_token_bits;
/** 실제 발견한 =math_engine_expression_token_kind_t= 값이다. */
uint32_t found_token_kind;
/** Version 1에서는 0이어야 하는 future-use field다. */
uint32_t reserved;
} math_engine_expression_diagnostic_t;
math_engine_expression_diagnostic_t.struct_size
Producer가 쓰는 exact ABI byte size인
sizeof(math_engine_expression_diagnostic_t)이다./** Producer가 쓰는 exact ABI byte size인 =sizeof(math_engine_expression_diagnostic_t)=이다. */ uint32_t struct_size;math_engine_expression_diagnostic_t.version
MATH_ENGINE_EXPRESSION_DIAGNOSTIC_VERSION_1인 ABI version이다./** =MATH_ENGINE_EXPRESSION_DIAGNOSTIC_VERSION_1=인 ABI version이다. */ uint32_t version;math_engine_expression_diagnostic_t.code
Stable
math_engine_expression_diagnostic_code_t값이다./** Stable =math_engine_expression_diagnostic_code_t= 값이다. */ uint32_t code;math_engine_expression_diagnostic_t.severity
math_engine_expression_diagnostic_severity_t값이다./** =math_engine_expression_diagnostic_severity_t= 값이다. */ uint32_t severity;math_engine_expression_diagnostic_t.primary_span
문제의 주 source 범위이며 byte offset는 half-open이다.
/** 문제의 주 source 범위이며 byte offset는 half-open이다. */ math_engine_expression_span_t primary_span;math_engine_expression_diagnostic_t.related_span
math_engine_expression_diagnostic_t.expected_token_bits
Expected token kind
k를 bit =1ULL<<k=로 표시하며 expectation이 없으면 0이다./** Expected token kind =k=를 bit =1ULL<<k=로 표시하며 expectation이 없으면 0이다. */ uint64_t expected_token_bits;math_engine_expression_diagnostic_t.found_token_kind
실제 발견한
math_engine_expression_token_kind_t값이다./** 실제 발견한 =math_engine_expression_token_kind_t= 값이다. */ uint32_t found_token_kind;math_engine_expression_diagnostic_t.reserved
Version 1에서는 0이어야 하는 future-use field다.
/** Version 1에서는 0이어야 하는 future-use field다. */ uint32_t reserved;
math_engine_expression_node_t
Child/sibling index만 사용하는 pointer-free AST node다.
typedef struct math_engine_expression_node {
/** Exact ABI byte size인 =sizeof(math_engine_expression_node_t)=이다. */
uint32_t struct_size;
/** =MATH_ENGINE_EXPRESSION_NODE_VERSION_1=인 ABI version이다. */
uint32_t version;
/** 이 node의 =math_engine_expression_node_kind_t= 값이다. */
uint32_t kind;
/** Literal spelling 또는 Unicode symbol을 나타내는 token-flag subset; 그 밖 bit는 0이다. */
uint32_t flags;
/** 이 node와 모든 descendant를 덮는 원본 source half-open span이다. */
math_engine_expression_span_t span;
/** Prefix operand, binary/assignment lhs, call callee/unit value index; 미사용은 NONE, 사용 시 현재 index 미만이다. */
uint32_t left;
/** Binary/assignment rhs index; 미사용은 NONE, 사용 시 현재 node index 미만이다. */
uint32_t right;
/** CALL 첫 argument index; 없으면 NONE, 있으면 현재 CALL node index 미만이다. */
uint32_t first_child;
/** 다음 argument index; 마지막이면 NONE, 있으면 현재 index보다 크고 =node_count=보다 작다. */
uint32_t next_sibling;
/** Literal/symbol의 source kind 또는 prefix/binary/call/unit의 대표 operator token kind다. */
uint32_t token_kind;
/** Version 1에서는 0이어야 하는 future-use field다. */
uint32_t reserved;
/** Lexeme/operator/call 괄호/unit 식을 가리키며 항상 =span= 안에 포함되는 source span이다. */
math_engine_expression_span_t value_span;
} math_engine_expression_node_t;
math_engine_expression_node_t.struct_size
Exact ABI byte size인
sizeof(math_engine_expression_node_t)이다./** Exact ABI byte size인 =sizeof(math_engine_expression_node_t)=이다. */ uint32_t struct_size;math_engine_expression_node_t.version
MATH_ENGINE_EXPRESSION_NODE_VERSION_1인 ABI version이다./** =MATH_ENGINE_EXPRESSION_NODE_VERSION_1=인 ABI version이다. */ uint32_t version;math_engine_expression_node_t.kind
이 node의
math_engine_expression_node_kind_t값이다./** 이 node의 =math_engine_expression_node_kind_t= 값이다. */ uint32_t kind;math_engine_expression_node_t.flags
Literal spelling 또는 Unicode symbol을 나타내는 token-flag subset; 그 밖 bit는 0이다.
/** Literal spelling 또는 Unicode symbol을 나타내는 token-flag subset; 그 밖 bit는 0이다. */ uint32_t flags;math_engine_expression_node_t.span
이 node와 모든 descendant를 덮는 원본 source half-open span이다.
/** 이 node와 모든 descendant를 덮는 원본 source half-open span이다. */ math_engine_expression_span_t span;math_engine_expression_node_t.left
Prefix operand, binary/assignment lhs, call callee/unit value index; 미사용은 NONE, 사용 시 현재 index 미만이다.
/** Prefix operand, binary/assignment lhs, call callee/unit value index; 미사용은 NONE, 사용 시 현재 index 미만이다. */ uint32_t left;math_engine_expression_node_t.right
Binary/assignment rhs index; 미사용은 NONE, 사용 시 현재 node index 미만이다.
/** Binary/assignment rhs index; 미사용은 NONE, 사용 시 현재 node index 미만이다. */ uint32_t right;math_engine_expression_node_t.first_child
CALL 첫 argument index; 없으면 NONE, 있으면 현재 CALL node index 미만이다.
/** CALL 첫 argument index; 없으면 NONE, 있으면 현재 CALL node index 미만이다. */ uint32_t first_child;math_engine_expression_node_t.next_sibling
다음 argument index; 마지막이면 NONE, 있으면 현재 index보다 크고
node_count보다 작다./** 다음 argument index; 마지막이면 NONE, 있으면 현재 index보다 크고 =node_count=보다 작다. */ uint32_t next_sibling;math_engine_expression_node_t.token_kind
Literal/symbol의 source kind 또는 prefix/binary/call/unit의 대표 operator token kind다.
/** Literal/symbol의 source kind 또는 prefix/binary/call/unit의 대표 operator token kind다. */ uint32_t token_kind;math_engine_expression_node_t.reserved
Version 1에서는 0이어야 하는 future-use field다.
/** Version 1에서는 0이어야 하는 future-use field다. */ uint32_t reserved;math_engine_expression_node_t.value_span
Lexeme/operator/call 괄호/unit 식을 가리키며 항상
span안에 포함되는 source span이다./** Lexeme/operator/call 괄호/unit 식을 가리키며 항상 =span= 안에 포함되는 source span이다. */ math_engine_expression_span_t value_span;
math_engine_expression_lexer_options_t
Lexer token ceiling과 reserved policy를 담는 versioned options다.
typedef struct math_engine_expression_lexer_options {
/** Exact ABI byte size인 =sizeof(math_engine_expression_lexer_options_t)=이다. */
uint32_t struct_size;
/** =MATH_ENGINE_EXPRESSION_LEXER_OPTIONS_VERSION_1=인 ABI version이다. */
uint32_t version;
/** Terminal END를 포함해 생성할 수 있는 maximum token count. 값은 1 이상이다. */
uint32_t maximum_tokens;
/** Version 1에서는 0이어야 하는 lexer policy flag storage다. */
uint32_t flags;
/** Version 1에서는 두 element 모두 0이어야 하는 future-use storage다. */
uint64_t reserved_u64[2];
} math_engine_expression_lexer_options_t;
math_engine_expression_lexer_options_t.struct_size
Exact ABI byte size인
sizeof(math_engine_expression_lexer_options_t)이다./** Exact ABI byte size인 =sizeof(math_engine_expression_lexer_options_t)=이다. */ uint32_t struct_size;math_engine_expression_lexer_options_t.version
MATH_ENGINE_EXPRESSION_LEXER_OPTIONS_VERSION_1인 ABI version이다./** =MATH_ENGINE_EXPRESSION_LEXER_OPTIONS_VERSION_1=인 ABI version이다. */ uint32_t version;math_engine_expression_lexer_options_t.maximum_tokens
Terminal END를 포함해 생성할 수 있는 maximum token count. 값은 1 이상이다.
/** Terminal END를 포함해 생성할 수 있는 maximum token count. 값은 1 이상이다. */ uint32_t maximum_tokens;math_engine_expression_lexer_options_t.flags
Version 1에서는 0이어야 하는 lexer policy flag storage다.
/** Version 1에서는 0이어야 하는 lexer policy flag storage다. */ uint32_t flags;math_engine_expression_lexer_options_t.reserved_u64
Version 1에서는 두 element 모두 0이어야 하는 future-use storage다.
/** Version 1에서는 두 element 모두 0이어야 하는 future-use storage다. */ uint64_t reserved_u64[2];
math_engine_expression_parse_options_t
Grammar profile, 허용 syntax와 deterministic token/node/depth ceiling이다.
typedef struct math_engine_expression_parse_options {
/** Exact ABI byte size인 =sizeof(math_engine_expression_parse_options_t)=이다. */
uint32_t struct_size;
/** =MATH_ENGINE_EXPRESSION_PARSE_OPTIONS_VERSION_1=인 ABI version이다. */
uint32_t version;
/** COMPACT 또는 DESKTOP =math_engine_expression_grammar_profile_t= 값이다. */
uint32_t grammar_profile;
/** =MATH_ENGINE_EXPRESSION_PARSE_ALLOW_*= bitset; COMPACT에서는 반드시 0이다. */
uint32_t flags;
/** Terminal END를 포함한 nonzero token ceiling이다. */
uint32_t maximum_tokens;
/** 생성 가능한 nonzero AST node ceiling이다. */
uint32_t maximum_nodes;
/** Nonzero Pratt recursion ceiling; COMPACT는 최대 32, DESKTOP은 최대 128이다. */
uint32_t maximum_depth;
/** Version 1에서는 0이어야 하는 future-use field다. */
uint32_t reserved;
/** Version 1에서는 두 element 모두 0이어야 하는 future-use storage다. */
uint64_t reserved_u64[2];
} math_engine_expression_parse_options_t;
math_engine_expression_parse_options_t.struct_size
Exact ABI byte size인
sizeof(math_engine_expression_parse_options_t)이다./** Exact ABI byte size인 =sizeof(math_engine_expression_parse_options_t)=이다. */ uint32_t struct_size;math_engine_expression_parse_options_t.version
MATH_ENGINE_EXPRESSION_PARSE_OPTIONS_VERSION_1인 ABI version이다./** =MATH_ENGINE_EXPRESSION_PARSE_OPTIONS_VERSION_1=인 ABI version이다. */ uint32_t version;math_engine_expression_parse_options_t.grammar_profile
COMPACT 또는 DESKTOP
math_engine_expression_grammar_profile_t값이다./** COMPACT 또는 DESKTOP =math_engine_expression_grammar_profile_t= 값이다. */ uint32_t grammar_profile;math_engine_expression_parse_options_t.flags
MATH_ENGINE_EXPRESSION_PARSE_ALLOW_*bitset; COMPACT에서는 반드시 0이다./** =MATH_ENGINE_EXPRESSION_PARSE_ALLOW_*= bitset; COMPACT에서는 반드시 0이다. */ uint32_t flags;math_engine_expression_parse_options_t.maximum_tokens
Terminal END를 포함한 nonzero token ceiling이다.
/** Terminal END를 포함한 nonzero token ceiling이다. */ uint32_t maximum_tokens;math_engine_expression_parse_options_t.maximum_nodes
생성 가능한 nonzero AST node ceiling이다.
/** 생성 가능한 nonzero AST node ceiling이다. */ uint32_t maximum_nodes;math_engine_expression_parse_options_t.maximum_depth
Nonzero Pratt recursion ceiling; COMPACT는 최대 32, DESKTOP은 최대 128이다.
/** Nonzero Pratt recursion ceiling; COMPACT는 최대 32, DESKTOP은 최대 128이다. */ uint32_t maximum_depth;math_engine_expression_parse_options_t.reserved
Version 1에서는 0이어야 하는 future-use field다.
/** Version 1에서는 0이어야 하는 future-use field다. */ uint32_t reserved;math_engine_expression_parse_options_t.reserved_u64
Version 1에서는 두 element 모두 0이어야 하는 future-use storage다.
/** Version 1에서는 두 element 모두 0이어야 하는 future-use storage다. */ uint64_t reserved_u64[2];
math_engine_expression_lex_result_t
Lexing이 소비한 byte, token/diagnostic 수와 deterministic fingerprint다.
typedef struct math_engine_expression_lex_result {
/** Producer가 쓰는 exact ABI byte size인 =sizeof(math_engine_expression_lex_result_t)=이다. */
uint32_t struct_size;
/** =MATH_ENGINE_EXPRESSION_LEX_RESULT_VERSION_1=인 ABI version이다. */
uint32_t version;
/** =MATH_ENGINE_EXPRESSION_RESULT_FLAG_*= 조합인 lex outcome bitset이다. */
uint32_t flags;
/** Version 1에서는 0인 future-use field다. */
uint32_t reserved;
/** 생성됐거나 필요한 token element 수. 완전한 stream에서는 terminal END를 포함한다. */
uint64_t token_count;
/** 생성됐거나 필요한 diagnostic element 수. Version 1 범위는 0 또는 1이다. */
uint64_t diagnostic_count;
/** Source 시작부터 lexing이 검사한 byte 수이며 =source_size= 이하다. */
uint64_t consumed_bytes;
/** 순서대로 token kind, flags와 exact lexeme byte를 반영한 FNV-1a64 값이다. */
uint64_t token_fingerprint;
} math_engine_expression_lex_result_t;
math_engine_expression_lex_result_t.struct_size
Producer가 쓰는 exact ABI byte size인
sizeof(math_engine_expression_lex_result_t)이다./** Producer가 쓰는 exact ABI byte size인 =sizeof(math_engine_expression_lex_result_t)=이다. */ uint32_t struct_size;math_engine_expression_lex_result_t.version
MATH_ENGINE_EXPRESSION_LEX_RESULT_VERSION_1인 ABI version이다./** =MATH_ENGINE_EXPRESSION_LEX_RESULT_VERSION_1=인 ABI version이다. */ uint32_t version;math_engine_expression_lex_result_t.flags
MATH_ENGINE_EXPRESSION_RESULT_FLAG_*조합인 lex outcome bitset이다./** =MATH_ENGINE_EXPRESSION_RESULT_FLAG_*= 조합인 lex outcome bitset이다. */ uint32_t flags;math_engine_expression_lex_result_t.reserved
Version 1에서는 0인 future-use field다.
/** Version 1에서는 0인 future-use field다. */ uint32_t reserved;math_engine_expression_lex_result_t.token_count
생성됐거나 필요한 token element 수. 완전한 stream에서는 terminal END를 포함한다.
/** 생성됐거나 필요한 token element 수. 완전한 stream에서는 terminal END를 포함한다. */ uint64_t token_count;math_engine_expression_lex_result_t.diagnostic_count
생성됐거나 필요한 diagnostic element 수. Version 1 범위는 0 또는 1이다.
/** 생성됐거나 필요한 diagnostic element 수. Version 1 범위는 0 또는 1이다. */ uint64_t diagnostic_count;math_engine_expression_lex_result_t.consumed_bytes
Source 시작부터 lexing이 검사한 byte 수이며
source_size이하다./** Source 시작부터 lexing이 검사한 byte 수이며 =source_size= 이하다. */ uint64_t consumed_bytes;math_engine_expression_lex_result_t.token_fingerprint
순서대로 token kind, flags와 exact lexeme byte를 반영한 FNV-1a64 값이다.
/** 순서대로 token kind, flags와 exact lexeme byte를 반영한 FNV-1a64 값이다. */ uint64_t token_fingerprint;
math_engine_expression_parse_result_t
Parse root/index/count, 최대 깊이와 pointer-free AST fingerprint다.
typedef struct math_engine_expression_parse_result {
/** Producer가 쓰는 exact ABI byte size인 =sizeof(math_engine_expression_parse_result_t)=이다. */
uint32_t struct_size;
/** =MATH_ENGINE_EXPRESSION_PARSE_RESULT_VERSION_1=인 ABI version이다. */
uint32_t version;
/** Parse에 적용한 =math_engine_expression_grammar_profile_t= 값이다. */
uint32_t grammar_profile;
/** Lex와 parse에서 누적된 =MATH_ENGINE_EXPRESSION_RESULT_FLAG_*= bitset이다. */
uint32_t flags;
/** Lex stage가 생성했거나 필요하다고 보고한 token element 수다. */
uint64_t token_count;
/** Parse stage가 생성한 AST node element 수다. */
uint64_t node_count;
/** 생성됐거나 필요한 diagnostic 수. Version 1 범위는 0 또는 1이다. */
uint64_t diagnostic_count;
/** 실제 도달한 Pratt recursion depth. 단위는 nesting level이다. */
uint64_t maximum_depth_reached;
/** 성공 시 root node index, 실패/미생성 시 =MATH_ENGINE_EXPRESSION_INDEX_NONE=이다. */
uint32_t root_index;
/** Version 1에서는 0인 future-use field다. */
uint32_t reserved;
/** 성공 시 source bytes와 node field sequence의 canonical FNV-1a64 값, 실패 시 0이다. */
uint64_t ast_fingerprint;
} math_engine_expression_parse_result_t;
math_engine_expression_parse_result_t.struct_size
Producer가 쓰는 exact ABI byte size인
sizeof(math_engine_expression_parse_result_t)이다./** Producer가 쓰는 exact ABI byte size인 =sizeof(math_engine_expression_parse_result_t)=이다. */ uint32_t struct_size;math_engine_expression_parse_result_t.version
MATH_ENGINE_EXPRESSION_PARSE_RESULT_VERSION_1인 ABI version이다./** =MATH_ENGINE_EXPRESSION_PARSE_RESULT_VERSION_1=인 ABI version이다. */ uint32_t version;math_engine_expression_parse_result_t.grammar_profile
Parse에 적용한
math_engine_expression_grammar_profile_t값이다./** Parse에 적용한 =math_engine_expression_grammar_profile_t= 값이다. */ uint32_t grammar_profile;math_engine_expression_parse_result_t.flags
Lex와 parse에서 누적된
MATH_ENGINE_EXPRESSION_RESULT_FLAG_*bitset이다./** Lex와 parse에서 누적된 =MATH_ENGINE_EXPRESSION_RESULT_FLAG_*= bitset이다. */ uint32_t flags;math_engine_expression_parse_result_t.token_count
Lex stage가 생성했거나 필요하다고 보고한 token element 수다.
/** Lex stage가 생성했거나 필요하다고 보고한 token element 수다. */ uint64_t token_count;math_engine_expression_parse_result_t.node_count
Parse stage가 생성한 AST node element 수다.
/** Parse stage가 생성한 AST node element 수다. */ uint64_t node_count;math_engine_expression_parse_result_t.diagnostic_count
생성됐거나 필요한 diagnostic 수. Version 1 범위는 0 또는 1이다.
/** 생성됐거나 필요한 diagnostic 수. Version 1 범위는 0 또는 1이다. */ uint64_t diagnostic_count;math_engine_expression_parse_result_t.maximum_depth_reached
실제 도달한 Pratt recursion depth. 단위는 nesting level이다.
/** 실제 도달한 Pratt recursion depth. 단위는 nesting level이다. */ uint64_t maximum_depth_reached;math_engine_expression_parse_result_t.root_index
성공 시 root node index, 실패/미생성 시
MATH_ENGINE_EXPRESSION_INDEX_NONE이다./** 성공 시 root node index, 실패/미생성 시 =MATH_ENGINE_EXPRESSION_INDEX_NONE=이다. */ uint32_t root_index;math_engine_expression_parse_result_t.reserved
Version 1에서는 0인 future-use field다.
/** Version 1에서는 0인 future-use field다. */ uint32_t reserved;math_engine_expression_parse_result_t.ast_fingerprint
성공 시 source bytes와 node field sequence의 canonical FNV-1a64 값, 실패 시 0이다.
/** 성공 시 source bytes와 node field sequence의 canonical FNV-1a64 값, 실패 시 0이다. */ uint64_t ast_fingerprint;
math_engine_expression_serialization_result_t
Wire I/O의 실제/필요 크기, root와 payload fingerprint다.
typedef struct math_engine_expression_serialization_result {
/** Producer가 쓰는 exact ABI byte size인 serialization-result POD 크기다. */
uint32_t struct_size;
/** =MATH_ENGINE_EXPRESSION_SERIALIZATION_RESULT_VERSION_1=인 ABI version이다. */
uint32_t version;
/** Version 1에서는 0인 serialization outcome flag storage다. */
uint32_t flags;
/** Serialized AST root index이며 valid payload에서는 =node_count-1=이다. */
uint32_t root_index;
/** Payload에 포함됐거나 필요한 source byte 수이며 =UINT32_MAX= 이하다. */
uint64_t source_size;
/** Payload에 포함됐거나 필요한 80-byte wire-node element 수이며 1 이상이다. */
uint64_t node_count;
/** Serialize/deserialize가 다룬 전체 48-byte header+source+node payload byte 수다. */
uint64_t bytes_consumed;
/** 48-byte wire header 뒤 source+node payload의 byte-exact FNV-1a64 값이다. */
uint64_t payload_fingerprint;
/** 필요한 source byte capacity. Serialize에서는 입력 =source_size=를 그대로 기록한다. */
uint64_t required_source_size;
/** 필요한 AST node capacity. Serialize에서는 입력 =node_count=를 그대로 기록한다. */
uint64_t required_node_count;
} math_engine_expression_serialization_result_t;
math_engine_expression_serialization_result_t.struct_size
Producer가 쓰는 exact ABI byte size인 serialization-result POD 크기다.
/** Producer가 쓰는 exact ABI byte size인 serialization-result POD 크기다. */ uint32_t struct_size;math_engine_expression_serialization_result_t.version
MATH_ENGINE_EXPRESSION_SERIALIZATION_RESULT_VERSION_1인 ABI version이다./** =MATH_ENGINE_EXPRESSION_SERIALIZATION_RESULT_VERSION_1=인 ABI version이다. */ uint32_t version;math_engine_expression_serialization_result_t.flags
Version 1에서는 0인 serialization outcome flag storage다.
/** Version 1에서는 0인 serialization outcome flag storage다. */ uint32_t flags;math_engine_expression_serialization_result_t.root_index
Serialized AST root index이며 valid payload에서는
node_count-1이다./** Serialized AST root index이며 valid payload에서는 =node_count-1=이다. */ uint32_t root_index;math_engine_expression_serialization_result_t.source_size
Payload에 포함됐거나 필요한 source byte 수이며
UINT32_MAX이하다./** Payload에 포함됐거나 필요한 source byte 수이며 =UINT32_MAX= 이하다. */ uint64_t source_size;math_engine_expression_serialization_result_t.node_count
Payload에 포함됐거나 필요한 80-byte wire-node element 수이며 1 이상이다.
/** Payload에 포함됐거나 필요한 80-byte wire-node element 수이며 1 이상이다. */ uint64_t node_count;math_engine_expression_serialization_result_t.bytes_consumed
Serialize/deserialize가 다룬 전체 48-byte header+source+node payload byte 수다.
/** Serialize/deserialize가 다룬 전체 48-byte header+source+node payload byte 수다. */ uint64_t bytes_consumed;math_engine_expression_serialization_result_t.payload_fingerprint
48-byte wire header 뒤 source+node payload의 byte-exact FNV-1a64 값이다.
/** 48-byte wire header 뒤 source+node payload의 byte-exact FNV-1a64 값이다. */ uint64_t payload_fingerprint;math_engine_expression_serialization_result_t.required_source_size
필요한 source byte capacity. Serialize에서는 입력
source_size를 그대로 기록한다./** 필요한 source byte capacity. Serialize에서는 입력 =source_size=를 그대로 기록한다. */ uint64_t required_source_size;math_engine_expression_serialization_result_t.required_node_count
필요한 AST node capacity. Serialize에서는 입력
node_count를 그대로 기록한다./** 필요한 AST node capacity. Serialize에서는 입력 =node_count=를 그대로 기록한다. */ uint64_t required_node_count;
Anonymous enum
anonymous_enum_at_line_169
@name math_engine_expression_token_t.flags bit
enum {
/** Token 바로 앞에서 하나 이상의 ASCII whitespace byte를 건너뛰었다. */
MATH_ENGINE_EXPRESSION_TOKEN_FLAG_PRECEDED_BY_SPACE = 1u << 0,
/** NUMBER lexeme가 decimal point/exponent 없는 integer spelling이다. */
MATH_ENGINE_EXPRESSION_TOKEN_FLAG_LITERAL_INTEGER = 1u << 1,
/** NUMBER lexeme가 decimal point를 포함하고 exponent는 없는 spelling이다. */
MATH_ENGINE_EXPRESSION_TOKEN_FLAG_LITERAL_DECIMAL = 1u << 2,
/** NUMBER lexeme가 =e= 또는 =E= exponent를 포함하는 spelling이다. */
MATH_ENGINE_EXPRESSION_TOKEN_FLAG_LITERAL_SCIENTIFIC = 1u << 3,
/** IDENTIFIER lexeme에 ASCII 밖의 well-formed UTF-8 code point가 있다. */
MATH_ENGINE_EXPRESSION_TOKEN_FLAG_IDENTIFIER_UNICODE = 1u << 4
};
MATH_ENGINE_EXPRESSION_TOKEN_FLAG_PRECEDED_BY_SPACE
Token 바로 앞에서 하나 이상의 ASCII whitespace byte를 건너뛰었다.
/** Token 바로 앞에서 하나 이상의 ASCII whitespace byte를 건너뛰었다. */ MATH_ENGINE_EXPRESSION_TOKEN_FLAG_PRECEDED_BY_SPACE = 1u << 0,MATH_ENGINE_EXPRESSION_TOKEN_FLAG_LITERAL_INTEGER
NUMBER lexeme가 decimal point/exponent 없는 integer spelling이다.
/** NUMBER lexeme가 decimal point/exponent 없는 integer spelling이다. */ MATH_ENGINE_EXPRESSION_TOKEN_FLAG_LITERAL_INTEGER = 1u << 1,MATH_ENGINE_EXPRESSION_TOKEN_FLAG_LITERAL_DECIMAL
NUMBER lexeme가 decimal point를 포함하고 exponent는 없는 spelling이다.
/** NUMBER lexeme가 decimal point를 포함하고 exponent는 없는 spelling이다. */ MATH_ENGINE_EXPRESSION_TOKEN_FLAG_LITERAL_DECIMAL = 1u << 2,MATH_ENGINE_EXPRESSION_TOKEN_FLAG_LITERAL_SCIENTIFIC
NUMBER lexeme가
e또는Eexponent를 포함하는 spelling이다./** NUMBER lexeme가 =e= 또는 =E= exponent를 포함하는 spelling이다. */ MATH_ENGINE_EXPRESSION_TOKEN_FLAG_LITERAL_SCIENTIFIC = 1u << 3,MATH_ENGINE_EXPRESSION_TOKEN_FLAG_IDENTIFIER_UNICODE
IDENTIFIER lexeme에 ASCII 밖의 well-formed UTF-8 code point가 있다.
/** IDENTIFIER lexeme에 ASCII 밖의 well-formed UTF-8 code point가 있다. */ MATH_ENGINE_EXPRESSION_TOKEN_FLAG_IDENTIFIER_UNICODE = 1u << 4,
anonymous_enum_at_line_185
@name math_engine_expression_parse_options_t.flags bit
enum {
/** Desktop grammar에서 top-level symbol assignment를 허용한다. */
MATH_ENGINE_EXPRESSION_PARSE_ALLOW_ASSIGNMENT = 1u << 0,
/** Desktop grammar에서 parenthesized argument-list call syntax를 허용한다. */
MATH_ENGINE_EXPRESSION_PARSE_ALLOW_CALLS = 1u << 1,
/** Desktop grammar에서 whitespace 뒤 unit product/division/power suffix를 허용한다. */
MATH_ENGINE_EXPRESSION_PARSE_ALLOW_UNIT_SUFFIX = 1u << 2,
/** Desktop grammar에서 non-ASCII UTF-8 identifier를 허용한다. */
MATH_ENGINE_EXPRESSION_PARSE_ALLOW_UNICODE_IDENTIFIERS = 1u << 3
};
MATH_ENGINE_EXPRESSION_PARSE_ALLOW_ASSIGNMENT
Desktop grammar에서 top-level symbol assignment를 허용한다.
/** Desktop grammar에서 top-level symbol assignment를 허용한다. */ MATH_ENGINE_EXPRESSION_PARSE_ALLOW_ASSIGNMENT = 1u << 0,MATH_ENGINE_EXPRESSION_PARSE_ALLOW_CALLS
Desktop grammar에서 parenthesized argument-list call syntax를 허용한다.
/** Desktop grammar에서 parenthesized argument-list call syntax를 허용한다. */ MATH_ENGINE_EXPRESSION_PARSE_ALLOW_CALLS = 1u << 1,MATH_ENGINE_EXPRESSION_PARSE_ALLOW_UNIT_SUFFIX
Desktop grammar에서 whitespace 뒤 unit product/division/power suffix를 허용한다.
/** Desktop grammar에서 whitespace 뒤 unit product/division/power suffix를 허용한다. */ MATH_ENGINE_EXPRESSION_PARSE_ALLOW_UNIT_SUFFIX = 1u << 2,MATH_ENGINE_EXPRESSION_PARSE_ALLOW_UNICODE_IDENTIFIERS
Desktop grammar에서 non-ASCII UTF-8 identifier를 허용한다.
/** Desktop grammar에서 non-ASCII UTF-8 identifier를 허용한다. */ MATH_ENGINE_EXPRESSION_PARSE_ALLOW_UNICODE_IDENTIFIERS = 1u << 3,
anonymous_enum_at_line_199
@name Expression lex/parse result flag
enum {
/** Lex/parse outcome에 ERROR severity diagnostic이 기록되었음을 나타낸다. */
MATH_ENGINE_EXPRESSION_RESULT_FLAG_HAS_ERROR = 1u << 0,
/** 오류 뒤 추가 처리를 중단하고 stable terminal outcome으로 bounded recovery했음을 나타낸다. */
MATH_ENGINE_EXPRESSION_RESULT_FLAG_RECOVERED_TO_END = 1u << 1,
/** Token stream 또는 AST가 non-ASCII Unicode identifier를 사용했다. */
MATH_ENGINE_EXPRESSION_RESULT_FLAG_USED_UNICODE = 1u << 2,
/** AST가 하나 이상의 UNIT_SUFFIX node를 포함한다. */
MATH_ENGINE_EXPRESSION_RESULT_FLAG_USED_UNIT_SUFFIX = 1u << 3
};
MATH_ENGINE_EXPRESSION_RESULT_FLAG_HAS_ERROR
Lex/parse outcome에 ERROR severity diagnostic이 기록되었음을 나타낸다.
/** Lex/parse outcome에 ERROR severity diagnostic이 기록되었음을 나타낸다. */ MATH_ENGINE_EXPRESSION_RESULT_FLAG_HAS_ERROR = 1u << 0,MATH_ENGINE_EXPRESSION_RESULT_FLAG_RECOVERED_TO_END
오류 뒤 추가 처리를 중단하고 stable terminal outcome으로 bounded recovery했음을 나타낸다.
/** 오류 뒤 추가 처리를 중단하고 stable terminal outcome으로 bounded recovery했음을 나타낸다. */ MATH_ENGINE_EXPRESSION_RESULT_FLAG_RECOVERED_TO_END = 1u << 1,MATH_ENGINE_EXPRESSION_RESULT_FLAG_USED_UNICODE
Token stream 또는 AST가 non-ASCII Unicode identifier를 사용했다.
/** Token stream 또는 AST가 non-ASCII Unicode identifier를 사용했다. */ MATH_ENGINE_EXPRESSION_RESULT_FLAG_USED_UNICODE = 1u << 2,MATH_ENGINE_EXPRESSION_RESULT_FLAG_USED_UNIT_SUFFIX
AST가 하나 이상의 UNIT_SUFFIX node를 포함한다.
/** AST가 하나 이상의 UNIT_SUFFIX node를 포함한다. */ MATH_ENGINE_EXPRESSION_RESULT_FLAG_USED_UNIT_SUFFIX = 1u << 3,
Macro와 constant
MATH_ENGINE_EXPRESSION_DIAGNOSTIC_VERSION_1
math_engine_expression_diagnostic_t 의 최초 ABI version 값이다.
#define MATH_ENGINE_EXPRESSION_DIAGNOSTIC_VERSION_1 1u
MATH_ENGINE_EXPRESSION_GRAMMAR_VERSION_1
Compact/desktop grammar contract의 최초 public version 값이다.
#define MATH_ENGINE_EXPRESSION_GRAMMAR_VERSION_1 1u
MATH_ENGINE_EXPRESSION_INDEX_NONE
유효한 node/token index가 없음을 나타내는 UINT32_MAX sentinel이다.
#define MATH_ENGINE_EXPRESSION_INDEX_NONE UINT32_MAX
MATH_ENGINE_EXPRESSION_LEXER_OPTIONS_VERSION_1
math_engine_expression_lexer_options_t 의 최초 ABI version 값이다.
#define MATH_ENGINE_EXPRESSION_LEXER_OPTIONS_VERSION_1 1u
MATH_ENGINE_EXPRESSION_LEX_RESULT_VERSION_1
math_engine_expression_lex_result_t 의 최초 ABI version 값이다.
#define MATH_ENGINE_EXPRESSION_LEX_RESULT_VERSION_1 1u
MATH_ENGINE_EXPRESSION_NODE_VERSION_1
math_engine_expression_node_t 의 최초 ABI version 값이다.
#define MATH_ENGINE_EXPRESSION_NODE_VERSION_1 1u
MATH_ENGINE_EXPRESSION_PARSE_OPTIONS_VERSION_1
math_engine_expression_parse_options_t 의 최초 ABI version 값이다.
#define MATH_ENGINE_EXPRESSION_PARSE_OPTIONS_VERSION_1 1u
MATH_ENGINE_EXPRESSION_PARSE_RESULT_VERSION_1
math_engine_expression_parse_result_t 의 최초 ABI version 값이다.
#define MATH_ENGINE_EXPRESSION_PARSE_RESULT_VERSION_1 1u
MATH_ENGINE_EXPRESSION_SERIALIZATION_RESULT_VERSION_1
math_engine_expression_serialization_result_t 의 최초 ABI version 값이다.
#define MATH_ENGINE_EXPRESSION_SERIALIZATION_RESULT_VERSION_1 1u
MATH_ENGINE_EXPRESSION_SERIALIZATION_VERSION_1
Little-endian MEEX expression wire schema의 최초 version 값이다.
#define MATH_ENGINE_EXPRESSION_SERIALIZATION_VERSION_1 1u
MATH_ENGINE_EXPRESSION_TOKEN_VERSION_1
math_engine_expression_token_t 의 최초 ABI version 값이다.
#define MATH_ENGINE_EXPRESSION_TOKEN_VERSION_1 1u
Function
math_engine_expression_lexer_options_init
4096-token ceiling의 deterministic lexer policy를 초기화한다.
- 매개변수
out_options: 성공 시 완전히 초기화되는 caller output. - 반환: 성공 시 OK. NULL에서는 INVALID_ARGUMENT이며 output은 존재하지 않는다.
- Math Engine ownership:
out_options=caller - Math Engine nullable:
out_options=false - Math Engine thread_safety:
safe
MATH_ENGINE_API math_engine_status_t math_engine_expression_lexer_options_init(
math_engine_expression_lexer_options_t* out_options);
math_engine_expression_parse_options_init
Compact 또는 desktop Pratt grammar 기본값을 초기화한다.
- 매개변수
grammar_profile: COMPACT 또는 DESKTOP grammar profile. - 매개변수
out_options: 성공 시 grammar별 flag와 ceiling을 받는 caller output. - 반환: 성공 시 OK. 잘못된 profile에서는 output을 보존하고, embedded build의 DESKTOP은
UNSUPPORTED다.
- Math Engine ownership:
out_options=caller - Math Engine nullable:
out_options=false - Math Engine thread_safety:
safe
MATH_ENGINE_API math_engine_status_t math_engine_expression_parse_options_init(
uint32_t grammar_profile,
math_engine_expression_parse_options_t* out_options);
math_engine_expression_lex_utf8
source_size 밖을 읽지 않고 완전한 UTF-8 buffer를 token화한다.
- 매개변수
source: UTF-8 source bytes. =source_size=0이면 NULL 가능하다. - 매개변수
source_size: source byte 수.UINT32_MAX이하여야 한다. - 매개변수
options: token ceiling을 담은 immutable lexer options. - 매개변수
context: budget와 동기 cancellation callback을 담은 immutable context. - 매개변수
tokens: caller-owned token 배열. Capacity 0이면 NULL 가능하다. - 매개변수
token_capacity:tokenselement capacity. - 매개변수
diagnostics: caller-owned diagnostic 배열. Capacity 0이면 NULL 가능하다. - 매개변수
diagnostic_capacity:diagnosticselement capacity. - 매개변수
out_result: token/diagnostic 필요 수와 fingerprint를 받는 caller output. - 반환: 성공 시 OK. Token 배열이 작으면 INSUFFICIENT_WORKSPACE와 필요 count를 commit한다.
UTF-8/syntax/cancellation 오류는 stable result와 가능한 첫 diagnostic을 commit한다. ABI 검증 실패에서는 caller output을 보존한다. 모든 배열은 서로 non-overlapping이어야 한다. 모든 pointer는 return까지만 빌리며 보관하지 않는다. Context cancellation callback은 현재 caller thread에서 동기 호출되고 C ABI 밖으로 exception을 throw/unwind하면 안 된다.
- Math Engine ownership:
source=borrowed options=borrowed context=borrowed tokens=caller diagnostics=caller out_result=caller - Math Engine nullable:
source=count_zero_only options=false context=false tokens=capacity_zero_only diagnostics=capacity_zero_only out_result=false - Math Engine thread_safety:
safe
MATH_ENGINE_API math_engine_status_t math_engine_expression_lex_utf8(
const char* source,
size_t source_size,
const math_engine_expression_lexer_options_t* options,
const math_engine_context_t* context,
math_engine_expression_token_t* tokens,
size_t token_capacity,
math_engine_expression_diagnostic_t* diagnostics,
size_t diagnostic_capacity,
math_engine_expression_lex_result_t* out_result);
math_engine_expression_parse_utf8
UTF-8 buffer에서 완전한 expression 하나를 token화하고 Pratt AST로 parse한다.
- 매개변수
source: UTF-8 source bytes. =source_size=0이면 NULL 가능하다. - 매개변수
source_size: source byte 수.UINT32_MAX이하여야 한다. - 매개변수
options: grammar, syntax flag와 token/node/depth ceiling. - 매개변수
context: budget와 동기 cancellation callback을 담은 immutable context. - 매개변수
tokens: caller-owned scratch token 배열. - 매개변수
token_capacity:tokenselement capacity. 0이면 NULL 가능하다. - 매개변수
nodes: caller-owned scratch AST node 배열. - 매개변수
node_capacity:nodeselement capacity. 0이면 NULL 가능하다. - 매개변수
diagnostics: caller-owned diagnostic 배열. - 매개변수
diagnostic_capacity:diagnosticselement capacity. 0이면 NULL 가능하다. - 매개변수
out_result: root/count/depth/fingerprint를 받는 caller output. - 반환: 성공 시 OK. Syntax, UTF-8, depth, workspace, budget 또는 cancellation status에서도
highlighting용 result와 가능한 diagnostic을 commit한다. Token/node 배열은 scratch이며 오류 후 의미를 보장하지 않는다. ABI 검증 실패에서는 result를 보존한다. 모든 범위는 non-overlapping이다. 모든 pointer는 return까지만 빌리며 보관하지 않는다. Context cancellation callback은 caller thread에서 동기 호출되고 C ABI 밖으로 exception을 throw/unwind하면 안 된다.
- Math Engine ownership:
source=borrowed options=borrowed context=borrowed tokens=caller nodes=caller diagnostics=caller out_result=caller - Math Engine nullable:
source=count_zero_only options=false context=false tokens=capacity_zero_only nodes=capacity_zero_only diagnostics=capacity_zero_only out_result=false - Math Engine thread_safety:
safe
MATH_ENGINE_API math_engine_status_t math_engine_expression_parse_utf8(
const char* source,
size_t source_size,
const math_engine_expression_parse_options_t* options,
const math_engine_context_t* context,
math_engine_expression_token_t* tokens,
size_t token_capacity,
math_engine_expression_node_t* nodes,
size_t node_capacity,
math_engine_expression_diagnostic_t* diagnostics,
size_t diagnostic_capacity,
math_engine_expression_parse_result_t* out_result);
math_engine_expression_serialized_size
Source text와 fixed-size node의 exact little-endian wire 크기를 계산한다.
- 매개변수
source_size: serialization할 source byte 수. - 매개변수
node_count: serialization할 node element 수. - 매개변수
out_size: 성공 시 header+source+node byte 수를 받는 caller output. - 반환: 성공 시 OK. 32-bit wire ceiling 또는
size_t산술 overflow에서는 output을
보존하고 OVERFLOW를 반환한다.
- Math Engine ownership:
out_size=caller - Math Engine nullable:
out_size=false - Math Engine thread_safety:
safe
MATH_ENGINE_API math_engine_status_t math_engine_expression_serialized_size(
size_t source_size,
size_t node_count,
size_t* out_size);
math_engine_expression_serialize
완전히 검증한 source와 pointer-free AST를 little-endian wire payload로 serialize한다.
- 매개변수
source: source bytes. =source_size=0이면 NULL 가능하다. - 매개변수
source_size: source byte 수. - 매개변수
nodes: 최소 하나인 immutable AST node 배열. - 매개변수
node_count: node element 수. Root는 마지막 node여야 한다. - 매개변수
root_index: serialization할 root index.node_count-1이어야 한다. - 매개변수
output: caller-owned wire byte buffer. Capacity 0이면 NULL 가능하다. - 매개변수
output_capacity:outputbyte capacity. - 매개변수
out_result: 실제/필요 크기와 fingerprint를 받는 caller output. - 반환: 성공 시 OK. 작은 buffer에서는 output을 보존하고 size result만 commit한다.
Node/index/span 검증 또는 overflow 실패에서는 output과 result를 보존한다. Source, nodes, output, result storage는 서로 overlap하지 않아야 한다.
- Math Engine ownership:
source=borrowed nodes=borrowed output=caller out_result=caller - Math Engine nullable:
source=count_zero_only nodes=false output=capacity_zero_only out_result=false - Math Engine thread_safety:
safe
MATH_ENGINE_API math_engine_status_t math_engine_expression_serialize(
const char* source,
size_t source_size,
const math_engine_expression_node_t* nodes,
size_t node_count,
uint32_t root_index,
unsigned char* output,
size_t output_capacity,
math_engine_expression_serialization_result_t* out_result);
math_engine_expression_deserialize
Fingerprint, schema와 모든 index를 검증한 뒤 AST와 source를 deserialize한다.
- 매개변수
input: 전체 little-endian wire payload. NULL일 수 없다. - 매개변수
input_size: input byte 수. Wire header 이상이어야 한다. - 매개변수
source_output: caller-owned source byte buffer. Capacity 0이면 NULL 가능하다. - 매개변수
source_capacity:source_outputbyte capacity. - 매개변수
nodes: caller-owned AST node 배열. Capacity 0이면 NULL 가능하다. - 매개변수
node_capacity:nodeselement capacity. - 매개변수
out_result: payload 크기/count/fingerprint와 필요 capacity를 받는 caller output. - 반환: 성공 시 OK. Stale schema는 UNSUPPORTED, 손상 payload는 INVALID_ARGUMENT다.
Buffer가 작으면 두 output buffer를 보존하고 required count result를 commit한다. 다른 실패에서도 output buffer를 보존한다. 모든 input/output 범위는 non-overlapping이다.
- Math Engine ownership:
input=borrowed source_output=caller nodes=caller out_result=caller - Math Engine nullable:
input=false source_output=capacity_zero_only nodes=capacity_zero_only out_result=false - Math Engine thread_safety:
safe
MATH_ENGINE_API math_engine_status_t math_engine_expression_deserialize(
const unsigned char* input,
size_t input_size,
char* source_output,
size_t source_capacity,
math_engine_expression_node_t* nodes,
size_t node_capacity,
math_engine_expression_serialization_result_t* out_result);