GaiaX Expression Module: Cross-Platform Expression Evaluation Design Based on LR(1) Grammar
GaiaX’s cross‑platform expression module uses a C++ LR(1) parser with lexical, syntax and semantic analysis to bind data, support arithmetic and functions, unify values via GXValue, bridge iOS and Android through JNI, and achieves sub‑millisecond execution for simple and nested expressions.
GaiaX is a high-performance cross-platform rendering engine developed by Alibaba's Youku team, widely used within Youku, Taopiaopiao, and Damo applications. This article focuses on the expression module design, which is crucial for data binding and dynamic logic in templates.
Expression Overview
Expressions in GaiaX serve as the bridge for data binding between views and business logic. They support value retrieval, arithmetic operations, and function calls. To ensure cross-platform consistency, C++ is used as the underlying implementation language.
Technical Design - Expression Parsing Process
The expression parsing process follows the compilation principle:
Lexical Analysis : Scans the input character stream and divides it into meaningful token sequences based on lexical rules.
Syntax Analysis : Constructs syntax trees and symbol tables by analyzing token sequences and verifying structural correctness.
Semantic Analysis : Validates semantic rules using the syntax tree and symbol table.
LR(1) Grammar for Syntax Tree Construction
LR(1) parsing scans from left to right, uses rightmost derivation, and looks ahead one character. The grammar hierarchy determines operator precedence - deeper derivation levels indicate higher precedence. For arithmetic operations, multiplication/division are placed at a lower hierarchy level than addition/subtraction to achieve correct precedence.
Cross-Platform Implementation
The cross-platform implementation involves two scenarios:
1. Platforms calling C++ layer: iOS directly includes C++ headers; Android uses JNI as an intermediary.
2. C++ calling platform methods: Requires defining virtual functions in the GXAnalyze class, implementing them in platform-specific classes (GXAnalyzeAndroid for Android, GXAnalyzeImpl for iOS), and using JNI to bridge the calls.
Unified Data Type
The GXValue class provides a unified data structure across platforms:
class GXValue {
public:
int64_t tag;
int32_t int32; //Bool 1,0
float float64; //Float
int64_t intNum; //long
void *ptr; //Array,Map
char *str; //String
};Performance Results
Android real device tests show excellent performance: single value computation takes 0.017ms, data retrieval 0.024ms, arithmetic operations 0.029ms, and complex nested expressions 0.060ms per execution.
Youku Technology
Discover top-tier entertainment technology here.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.