3 ms·
We did a programming language for a project. It was a clinical rules language. The distinguishing features of it were the data model (it had first class access
by whartung 5y ago
We did a programming language for a project. It was a clinical rules language.
The distinguishing features of it were the data model (it had first class access to the temporal data model we had on the back end), and that we kept the tri-state model of SQL with values and NULL.
Other than that it didn't have any real structured types, and just few high level actions.
It was a straightforward project, ALGOL-esque, basic control structures. It compiled to Java source code, and the resulting classes loaded in to the app server.
We used a "compiler compiler" tool, rather than doing it ourselves. It gave us an AST that we then walked. First time doing anything like that, especially with a tool like that.
Especially in an ALGOL like language, getting the expressions to work is the "hard" part. That's where your "napkin to white board to syntax file" falls apart with reduce errors and what not.
But when you get it to work, it's magic. When you get "a = a + 1" to work, and know that where 1 line of code works, 10000 lines of code will work, it's an amazing feeling. You just build the things a piece at a time, testing all the way.
In the end, we had an unresolved precedence issue (as I recall), but we never bothered to fix.
The funniest unexpected outcome was the classic SQL model of using NULL. Simply, 1 + NULL = NULL, and we expanded that to all expressions.
It kind of fell apart in something like: IF A = 1 AND B = 2 OR C > 3 THEN...
If any of those variable (A, B, C) was NULL, the entire expression evaluated to NULL, which was false. It took me by surprise when it happened, but, "duh", of course.
I simply changed the NULL rule to no apply to boolean operators. Instead of evaluating to NULL, I had them all evaluate to FALSE, and that fixed that.
Looking at Wirths work (Pascal, Oberon, etc.), you'll see that compilers can be simple. They're work, but they're simple work. We obviously make them more and more sophisticated all the time, but your compilers don't need to be that way to be effective, productive, and useful. We created thousands of lines of code using that language, it solved the problem very nicely that it was supposed to do.
Runtimes can be hard, but that's a separate problem.
- Findecanor 5y ago> The funniest unexpected outcome was the classic SQL model of using NULL. Simply, 1 + NULL = NULL, and we expanded that to all expressions. > It kind of fell apart in something like: IF A = 1 AND B = 2 OR C > 3 THEN... That is similar to how NaN values are propagated in IEEE 754 floating point standard. However, a comparison with a NaN would cause an exception (in CPU or programming language, unless you're using a language such as C where FP exceptions are disabled by default). And then there are several min and max operators that don't cause an exception on every NaN but which have different preferences for propagating NaN or values. The distinction is that a comparison affects control flow whereas min/max are still considered data flow.
- karmakaze 5y ago> Simply, 1 + NULL = NULL, and we expanded that to all expressions. That's not quite right. In SQL NULL represents an unknown value, so 1 + unknown => unknown. TRUE OR NULL => TRUE FALSE OR NULL => NULL FALSE AND NULL => FALSE TRUE AND NULL => NULL Which is also why NULL = NULL => NULL, i.e. unknown == unknown => unknown.
- deleted 5y ago[deleted]
- grumpyprole 5y agoNULLs in SQL are a mess so I don't think one should try to attach any general meaning to them. Nor should SQL's NULL handling be a model for any other language. For example, 1+NULL is NULL, but adding the same two values via SUM(1, NULL), returns 1.
- brundolf 5y ago> But when you get it to work, it's magic. When you get "a = a + 1" to work, and know that where 1 line of code works, 10000 lines of code will work, it's an amazing feeling. You just build the things a piece at a time, testing all the way. This is it right here. Ever since I started dipping into this stuff, it's been one of the most intoxicating drinks for me in all of programming. You just get a few little pieces working, and then you know you've created infinite permutations of working programs. Each feature you implement is another infinity of possibilities. There's nothing quite like it.