3 ms·
I wrote something very similar recently, also a single-pass, but with a trivial internal representation: https://github.com/skx/math-compiler https://github.co
by stevekemp 6y ago
I wrote something very similar recently, also a single-pass, but with a trivial internal representation:
https://github.com/skx/math-compiler https://github.com/skx/math-compiler
The real difference between the compiler in the example, and mine, is that I handle floating-point operations and also explicitly use printf to show the output. (Because otherwise your return value is limited to an 8bit number.)
- userbinator 6y agoBecause otherwise your return value is limited to an 8bit number Only on Linux; Windows lets you use the full 32 bits.
- stevekemp 6y agoThat's true. Though I guess even there there are limitations, because you can't return non-integers :)
- tom_mellior 6y agoThis is nice. The -debug flag is a cool feature. But if you first build a representation of the whole program in memory, then traverse that representation to generate code, it's not really single-pass.
- stevekemp 6y agoSorry my comment was wrong, I should have said "not a single-pass", that's why I mentiond the trivial internal representation. Too late to edit now!