Back
Lao Zi logo
Lao Zi DSL
Try It Live
Expression Language

The Lao Zi DSL

A purpose-built expression language for aggregation-over-data calculations. Compiles deterministically to SQL — validated at parse time, not runtime. No raw SQL exposure. Strict PEMDAS enforcement.

PEMDAS Operator Precedence

The recursive-descent parser explicitly encodes operator precedence. This means SUM(a) + SUM(b) * 100 always evaluates as SUM(a) + (SUM(b) * 100), not (SUM(a) + SUM(b)) * 100.

PrecedenceOperatorsParser Method
1 (highest)( ) parenthesesparsePrimary
2unary -parseUnary
3* / %parseMultiplicative
4 (lowest)+ -parseAdditive

Function Reference

FunctionDescriptionExample
SUM(column)Sum of valuesSUM(amount)
AVG(column)Arithmetic meanAVG(amount) OVER(90 days)
COUNT(*)Row countCOUNT(*) WHERE(type = 'CREDIT')
COUNT(DISTINCT col)Distinct countCOUNT(DISTINCT payee)
MIN(column)Minimum valueMIN(amount)
MAX(column)Maximum valueMAX(amount) OVER(last_year)
MEDIAN(column)50th percentileMEDIAN(amount)
STDEV(column)Standard deviationSTDEV(amount) OVER(30 days)

Named Periods

last_weekprior_weeklast_monthprior_monthlast_quarterprior_quarterlast_yearprior_yearYTDMTDWTDQTDQ1Q2Q3Q4last_N_dayslast_N_monthsprior_N_daysprior_N_months

Day filters: weekends, weekdays, mondaysunday (and abbreviations monsun).

Expression Examples

Income-to-Expense Ratio

Calculate the income-to-expense ratio as a percentage over the last 30 days, rounded to 2 decimal places.

ROUND(
  (SUM(amount) WHERE(type = 'income') OVER(30 days))
  /
  NULLIF(SUM(amount) WHERE(type = 'expense') OVER(30 days), 0)
  * 100,
  2
)
AggregationMathTemporalFilter

Credit Transaction Count

Count all credit transactions in the current year.

COUNT(*) WHERE(type = 'CREDIT') PERIOD(YTD)
AggregationFilterTemporal

Payee Concentration Index

Calculate the Gini coefficient for payment distribution across payees to detect concentration risk.

GINI(amount GROUP_BY(payee))
Statistical

Quarterly Revenue Change

Measure the percentage change in total revenue over the last 3 months.

CHANGE(amount, 3 months)
Temporal

High-Value Transaction Detection

Sum amounts of transactions exceeding $10,000 on weekends over the last 90 days.

SUM(amount) WHERE(amount > 10000 AND ON(weekends)) OVER(90 days)
AggregationFilterTemporal

Expense Volatility

Calculate the standard deviation of monthly expenses to measure spending volatility.

STDEV(amount) WHERE(type = 'expense') OVER(last_year)
AggregationFilterTemporal

Try It Live

Type a DSL expression below to see it parsed into an AST and compiled to SQL in real time. Click any example above to copy it, then paste it here.

DSL Expression
Press Ctrl+Enter to parse
Quick Examples