4 ms·
A few days ago I designed a DSL for CREATE TABLE statements. https://gist.github.com/nomsolence/69bc0b5fe1ba943d82cd37fdbd23df6d#file-db-png https://gist.githu
by kohtatsu 7y ago
A few days ago I designed a DSL for CREATE TABLE statements.
https://gist.github.com/nomsolence/69bc0b5fe1ba943d82cd37fdbd23df6d#file-db-png https://gist.github.com/nomsolence/69bc0b5fe1ba943d82cd37fdb...
Being able to focus on the relationships without worrying about commas is nice.
I'm still writing the compiler (it's my first, I'm sure it will be awful), but I'm starting from the finish so it's been easy for me to pick up where I left off; I started by deciding the language, then writing the outputs by hand for the tokenizer, my two stages of AST, and the actual SQL.
- kohtatsu 7y agoDirect image link: https://gist.githubusercontent.com/nomsolence/69bc0b5fe1ba943d82cd37fdbd23df6d/raw/87abcc0805f0a0b3456707792a78fa763db20110/db.png https://gist.githubusercontent.com/nomsolence/69bc0b5fe1ba94... Not shown is the second stage of AST; it resolves types for the SQL dialect, e.g. "bool" to "BOOLEAN" for SQLite (all caps for convention of course), as well as things like the special "ROWID" type for SQLite, and finding types for "FK" columns, adding the constraints declarations, and finally validation! Maybe the first AST is an IR? I'll read the compiler design book and find out.