i think easiest way to learn how compiler works, or how the computer executes the instructions, is by writing a virtual machine that operates on stack or virtual registers. a draft vm can be written in about 130~ loc, and most topics a person learns while doing a vm, are learnt relatively smooth. also vm is a thing literally every self respecting C streamer did in a spare time
Thanks for a very clear explanation. I wonder why all the "goto again" s are included rather than the usual style of using break and placing the switch in a do while loop controlled by a handled bool.
Glad that you liked the video! I wondered the same thing, but I gotta admit that even using goto's looks pretty clean. Because of this unexpected observation, I don't want to alter the code of these examples if possible. I like seeing different programming styles, even though I don't necessarily like them!
I know, I thought the same thing - but I decided to leave the code be as the original author wrote it. I guess we could **improve** the code to make a "compiler in 1 line of C" :D
Google for a fragment of code eg. sym == WHILE_SYM. That will give you one or more hits for git... One I examined had a comment pointing to original source.
Use google to search for some possibly unique word or expression from source shown in video. I had no trouble finding multiple references to relevant file and from source file you may find, you can find reference to original author's web site. YT deleted multiple comments I posted and this hopefully stays.
I'm wondering if the link in the description was changed or if the people complaining about it don't know how to copy and paste. Even cell phones allow you to copy and paste from descriptions so I can only assume it was altered. That said, it'd be cool if you took the TinyC code and refactored it. Use more modern idioms and maybe add some optimizations to it. Perhaps turn it into an actual compiler that generates either assembly or a binary object file ready to link.
Typically, a compiler is separated into two parts: the front end and the back end. The front end parses the input data, the source code, and generates the abstract syntax tree (and does optional optimizations) and that intermediate representation is handed off to the the back end that generates whatever output is desired. It does not matter if the compiler generates assembly (take gcc for example), bytecode (Java, C# or WebASM) or directly outputs machine code, it still compiled the source code translating it from source code to something that is either directly executable or that can be further worked on to generate something that can be executed. In the case of tinyc, the compiler comes bundled with a virtual machine (like Java, C# and WebASM) that can execute the output from the compiler. So, no, tinyc is not an interpreter, it is a compiler since it performs the work of a compiler.
Concise though I think this would be a bit terse for a beginner. Good for a TH-cam video though. Also the amount of code on each line is way too much for me, I’m too used to clang format haha
Yeah, I also think there is too much stuff on one line a lot of times. I wanted to format the example using clang, but then I decided to leave it as is. I think it's sometimes interesting to see how other people organize their code :D. BTW - regarding formatters - if I saw code formatted like this on a project I'm working on, I'd probably snap!
I don't understand why there is no LISP like low-level programming language. If the syntax was a LISP, then the compiler would not have to worry about converting tokens into an AST, because who cares about that anyway? The job of the compiler is to produce portable or optimized code, not do re-invent wheels. Imagine a C like low-level systems programming language that forces their users to write in a LISP like syntax, so that the context of any number of operations and functions is crystal clear for the compiler (and unambiguous). The compilers would have a lot less complexity that way and can focus on stuff that makes them "magic" (all the implicit re-writes and transformations that makes code faster). Just my thoughts that were spontaneously popping in my head as I was listening to this video...
Lisp is low level on the Lisp machines. Otherwise have a look at RPL; sysRPL is the assembly language for the machines that run it, and it's inspired by Forth and Lisp. Forth has an extremely simple compiler that doesn't use any AST, and colorForth is the assembly language for GreenArray computers. Open Firmware also runs Forth, though it uses a bytecode interpreter (allowing it to be CPU architecture independent).
Thanks for the video, but the link given in the description seems invalid, can you give a valid one ?
You can google "tinyc.c" with the double quotation mark included.
i think easiest way to learn how compiler works, or how the computer executes the instructions, is by writing a virtual machine that operates on stack or virtual registers.
a draft vm can be written in about 130~ loc, and most topics a person learns while doing a vm, are learnt relatively smooth.
also vm is a thing literally every self respecting C streamer did in a spare time
That's exactly what I did. Wrote my own Forth compiler in assembly language!
Smooth? :-) CrowdStrike's VM embedded in a device driver caused an amazing amount of disruption.
@NotMarkKnopfler Did you open-source the project? :D
why is your system named "fridge"
to confuse hackers lol
how else will it stay cool
Cuz he's chill like that
he liked you and left you ghosted
Thanks for a very clear explanation. I wonder why all the "goto again" s are included rather than the usual style of using break and placing the switch in a do while loop controlled by a handled bool.
Glad that you liked the video!
I wondered the same thing, but I gotta admit that even using goto's looks pretty clean. Because of this unexpected observation, I don't want to alter the code of these examples if possible. I like seeing different programming styles, even though I don't necessarily like them!
"in 191 Lines of C"
The lines: if (sym == ID) { x=new_node(VAR); x->val=id_name[0]-'a'; next_sym(); }
I know, I thought the same thing - but I decided to leave the code be as the original author wrote it.
I guess we could **improve** the code to make a "compiler in 1 line of C" :D
I liked when you compiled the compiler.
link not working, can you put in git?
Google for a fragment of code eg. sym == WHILE_SYM. That will give you one or more hits for git...
One I examined had a comment pointing to original source.
Use google to search for some possibly unique word or expression from source shown in video. I had no trouble finding multiple references to relevant file and from source file you may find, you can find reference to original author's web site.
YT deleted multiple comments I posted and this hopefully stays.
Can you provide a source for the tinyc code? Im afraid the link in the description doesnt work
Should be there now!
@@cheesed_upthank you so much! Im cheesed to say im subscribed
How the first compiler was compiled? 🤔
The first true compliers were written by hand in assembly/machine code (0's and 1's) by people like Grace Hopper and John Backus.
This was awesome
bel video frate :D
which font is this? for a second I thought it was comic sands😂
It's monospace comic sans...
maybe it's comic mono
@@lankin9217 didn't know such a thing existed...
It's called Comic Mono
from undertable
I'm wondering if the link in the description was changed or if the people complaining about it don't know how to copy and paste. Even cell phones allow you to copy and paste from descriptions so I can only assume it was altered. That said, it'd be cool if you took the TinyC code and refactored it. Use more modern idioms and maybe add some optimizations to it. Perhaps turn it into an actual compiler that generates either assembly or a binary object file ready to link.
Regarding links: TH-cam masks them if the channel is not big enough or something like that.
@@cheesed_up If that's what it was, then congrats on getting big enough. Hopefully that doesn't sound weird.
thats not a compiler, but an interpreter
a compiler would output assember code / binary code
Typically, a compiler is separated into two parts: the front end and the back end. The front end parses the input data, the source code, and generates the abstract syntax tree (and does optional optimizations) and that intermediate representation is handed off to the the back end that generates whatever output is desired.
It does not matter if the compiler generates assembly (take gcc for example), bytecode (Java, C# or WebASM) or directly outputs machine code, it still compiled the source code translating it from source code to something that is either directly executable or that can be further worked on to generate something that can be executed.
In the case of tinyc, the compiler comes bundled with a virtual machine (like Java, C# and WebASM) that can execute the output from the compiler. So, no, tinyc is not an interpreter, it is a compiler since it performs the work of a compiler.
@@chibisuke6731 they literally talked about this in the first few minutes
This is like saying that clang is not a compiler
@@Joorin4711by that logic, all interpreters would be a compiler, bevause all of them use Tokenizers and Parsers
Not necessarily. A compiler might output byte code like Java or C#.
The source link is broken, can you fix it?
FELLOW COMIC CODE ENJOYER 🎉
Ayy
Very interesting! I found some source code which seems similar here
Where do you find these codes?
Link broken :(
What accent is this guy speaking?
russ/slav
video looks good, but sound is not clear
Thanks for the feedback, I'm working on this :D
Concise though I think this would be a bit terse for a beginner. Good for a TH-cam video though.
Also the amount of code on each line is way too much for me, I’m too used to clang format haha
Yeah, I also think there is too much stuff on one line a lot of times.
I wanted to format the example using clang, but then I decided to leave it as is. I think it's sometimes interesting to see how other people organize their code :D.
BTW - regarding formatters - if I saw code formatted like this on a project I'm working on, I'd probably snap!
Wow!
I don't understand why there is no LISP like low-level programming language. If the syntax was a LISP, then the compiler would not have to worry about converting tokens into an AST, because who cares about that anyway? The job of the compiler is to produce portable or optimized code, not do re-invent wheels. Imagine a C like low-level systems programming language that forces their users to write in a LISP like syntax, so that the context of any number of operations and functions is crystal clear for the compiler (and unambiguous). The compilers would have a lot less complexity that way and can focus on stuff that makes them "magic" (all the implicit re-writes and transformations that makes code faster). Just my thoughts that were spontaneously popping in my head as I was listening to this video...
Crystal clear to the compiler but hard on the human with *L* ots of *I* rritating *S* uperfluous *P* arentheses. 🙂 (A very old joke).
Lisp is low level on the Lisp machines. Otherwise have a look at RPL; sysRPL is the assembly language for the machines that run it, and it's inspired by Forth and Lisp. Forth has an extremely simple compiler that doesn't use any AST, and colorForth is the assembly language for GreenArray computers. Open Firmware also runs Forth, though it uses a bytecode interpreter (allowing it to be CPU architecture independent).
Excuse me, _what_
WHO?
for the love of christ never show your code publicly again