marp | theme |
---|---|
true |
uncover |
1 + a + 2
-> (1 + a) + 2
-> (a + 1) + 2
-> a + (1 + 2)
-> a + 3
ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
expression
: expression POW expression
| expression (TIMES | DIV) expression
| expression (PLUS | MINUS) expression
| LPAREN expression RPAREN
| (PLUS | MINUS)* atom;
atom
: scientific
| variable;
scientific
: SCIENTIFIC_NUMBER;
variable
: VARIABLE;
val lazyTree = LazyTree("1 + a + 2")
lazyTree.expression().foreach { node =>
println(s"${beautifyName(node)} [${extract(node)}]")
}
Only LPAREN/RPAREN/PLUS/atom is allowed.
1 + a + 2
-> (1 + a) + 2
a + (1 + 2)
-> a + 3
select 1 + a + 2 as x from tbl
select a + 3 as x from tbl
- Antlr4
- Pattern Matching
- Create a DSL
load mysql as mysql_x select * from x;
select * from mysql_x join y
text -> AST(antlr4) -> AST (More Abstraction)
sql -> AST -> LogicalPlan -> PhysicalPlan