Earlier quoted context omitted.
Infix parsing chews up a remarkable amount code and memory. It's scary just how much easier it is to parse languages without infix parsing.
where it takes up the memory in the human brain, where we have more limited working set, than in computers. That is probably why postfix notation is mostly a thing of the past by now in languages intended to be used by humans.
Writing a C compiler in 500 lines of Python
151–160 of 183 posts
Re: Writing a C compiler in 500 lines of Python
#152 block
;; code for "i = 0"
loop
;; code for "i
It doesn't require cloning the lexer so probably would still fit in 500 lines? But yeah, in normal assembly it's way easier, even in one-pass: ;; code for "i = 0"
.loop_test:
;; code for "i
Of course, normally you'd want to re-arrange things like so: ;; code for "i = 0"
jmp .loop_test
.loop_body:
;; code for "j = j * 2 + 1"
.loop_incr:
;; code for "i = i + 1"
.loop_test:
;; code for "i
I propose the better loop syntax for languages with one-pass implementations, then: "for (i = 0) { j = j * 2 + 1; } (i = i + 1; i < 5);" :)Re: Writing a C compiler in 500 lines of Python
#153Re: Writing a C compiler in 500 lines of Python
#154Earlier quoted context omitted.
I wasn't really aware of the embedded DSL distinction. But even then. I was never really able to get into Observable because although it looks like JavaScript, there are kind of hidden objects and methods available to you that I found weirdly hard to discover.
What's 'Observable'?
Kind of like Jupyter notebooks for JavaScript? Kind of?
Re: Writing a C compiler in 500 lines of Python
#155Earlier quoted context omitted.
where it takes up the memory in the human brain, where we have more limited working set, than in computers. That is probably why postfix notation is mostly a thing of the past by now in languages intended to be used by humans.
(in (is "prefix notation" (and "alive" "kicking")) "all lisps")
(- "alive"
(and "kicking")
(is "prefix notation" )
(in "all lisps"))Re: Writing a C compiler in 500 lines of Python
#156Actually with SLY ( https://sly.readthedocs.io ) now dead, what is the recommended Lexer/Parser library in Python?
Re: Writing a C compiler in 500 lines of Python
#157Cool. Now try writing a Python compiler in 500 lines of C.
Re: Writing a C compiler in 500 lines of Python
#158Earlier quoted context omitted.
But they could've fixed that by going a=(*p) and a=(-b); Kind of how we use (*p)->next instead of *p->next where p is node_t**
That seems a little backwards and barbaric, though right? Imagine if we had to watch out for this as a common pitfall: // BUG! Actually subtracts x from current val of neg_x. neg_x = -x; Even moreso, how would these two lines behave? Would they differ in semantics? n = -5 n =- 5 Overall, -= is just so much less ambiguous. EDIT: To your point about ->, I personally think C would be better if: *p->next parsed as: (*p)-…
Regarding "n = -5", it would presumably be interpreted as "n=(-5)", same as today. Operators don't have spaces in them. So "n- -5" is "n-(-5)", rather than "n--5" (not valid).