Compiler in 191 Lines of C | tinyc

  Рет қаралды 24,431

Cheesed Up

Cheesed Up

Күн бұрын

Пікірлер: 68
@amuerta3041
@amuerta3041 5 ай бұрын
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
@NotMarkKnopfler
@NotMarkKnopfler 5 ай бұрын
That's exactly what I did. Wrote my own Forth compiler in assembly language!
@DeclanMBrennan
@DeclanMBrennan 4 ай бұрын
Smooth? :-) CrowdStrike's VM embedded in a device driver caused an amazing amount of disruption.
@cheesed_up
@cheesed_up 4 ай бұрын
@NotMarkKnopfler Did you open-source the project? :D
@marouaniAymen
@marouaniAymen 5 ай бұрын
Thanks for the video, but the link given in the description seems invalid, can you give a valid one ?
@EuphCat
@EuphCat 5 ай бұрын
You can google "tinyc.c" with the double quotation mark included.
@madbanana22
@madbanana22 5 ай бұрын
why is your system named "fridge"
@Lonely_Wiz
@Lonely_Wiz 5 ай бұрын
to confuse hackers lol
@ThatGuyGEWP
@ThatGuyGEWP 5 ай бұрын
how else will it stay cool
@jeremymcadams7743
@jeremymcadams7743 4 ай бұрын
Cuz he's chill like that
@aciddev_
@aciddev_ 3 ай бұрын
he liked you and left you ghosted
@WiseWeeabo
@WiseWeeabo 4 ай бұрын
"in 191 Lines of C" The lines: if (sym == ID) { x=new_node(VAR); x->val=id_name[0]-'a'; next_sym(); }
@cheesed_up
@cheesed_up 4 ай бұрын
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
@DeclanMBrennan
@DeclanMBrennan 4 ай бұрын
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.
@cheesed_up
@cheesed_up 4 ай бұрын
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!
@Qstate
@Qstate 5 ай бұрын
I liked when you compiled the compiler.
@atabac
@atabac 5 ай бұрын
link not working, can you put in git?
@MrDomingo55
@MrDomingo55 5 ай бұрын
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.
@MrDomingo55
@MrDomingo55 5 ай бұрын
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.
@anon_y_mousse
@anon_y_mousse 4 ай бұрын
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.
@cheesed_up
@cheesed_up 4 ай бұрын
Regarding links: KZbin masks them if the channel is not big enough or something like that.
@anon_y_mousse
@anon_y_mousse 4 ай бұрын
@@cheesed_up If that's what it was, then congrats on getting big enough. Hopefully that doesn't sound weird.
@enriquedelacal2814
@enriquedelacal2814 5 ай бұрын
Can you provide a source for the tinyc code? Im afraid the link in the description doesnt work
@cheesed_up
@cheesed_up 4 ай бұрын
Should be there now!
@enriquedelacal2814
@enriquedelacal2814 4 ай бұрын
@@cheesed_upthank you so much! Im cheesed to say im subscribed
@vinayakmahajan4513
@vinayakmahajan4513 5 ай бұрын
How the first compiler was compiled? 🤔
@Melesio-wm9uv
@Melesio-wm9uv 5 ай бұрын
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.
@chibisuke6731
@chibisuke6731 5 ай бұрын
thats not a compiler, but an interpreter a compiler would output assember code / binary code
@Joorin4711
@Joorin4711 5 ай бұрын
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.
@nothappyz
@nothappyz 5 ай бұрын
@@chibisuke6731 they literally talked about this in the first few minutes
@AschKris
@AschKris 5 ай бұрын
This is like saying that clang is not a compiler
@antonpieper
@antonpieper 5 ай бұрын
​@@Joorin4711by that logic, all interpreters would be a compiler, bevause all of them use Tokenizers and Parsers
@NotMarkKnopfler
@NotMarkKnopfler 5 ай бұрын
Not necessarily. A compiler might output byte code like Java or C#.
@narrowbtw3970
@narrowbtw3970 5 ай бұрын
bel video frate :D
@nothappyz
@nothappyz 5 ай бұрын
This was awesome
@suou7938
@suou7938 5 ай бұрын
which font is this? for a second I thought it was comic sands😂
@lankin9217
@lankin9217 5 ай бұрын
It's monospace comic sans...
@imsuck12
@imsuck12 5 ай бұрын
maybe it's comic mono
@suou7938
@suou7938 5 ай бұрын
@@lankin9217 didn't know such a thing existed...
@BlueSheep95
@BlueSheep95 5 ай бұрын
It's called Comic Mono
@sean_r
@sean_r 5 ай бұрын
from undertable
@NicolasVycasNery
@NicolasVycasNery 5 ай бұрын
The source link is broken, can you fix it?
@ji1046
@ji1046 5 ай бұрын
Link broken :(
@polarnight-no
@polarnight-no 5 ай бұрын
Very interesting! I found some source code which seems similar here
@ycemilk
@ycemilk 5 ай бұрын
Where do you find these codes?
@maximkovalkov1334
@maximkovalkov1334 5 ай бұрын
FELLOW COMIC CODE ENJOYER 🎉
@cheesed_up
@cheesed_up 5 ай бұрын
Ayy
@CyprianBergonia
@CyprianBergonia 5 ай бұрын
video looks good, but sound is not clear
@cheesed_up
@cheesed_up 4 ай бұрын
Thanks for the feedback, I'm working on this :D
@gaeshows1938
@gaeshows1938 5 ай бұрын
What accent is this guy speaking?
@bunny.bunbob
@bunny.bunbob 5 ай бұрын
russ/slav
@brentpappas4055
@brentpappas4055 5 ай бұрын
Concise though I think this would be a bit terse for a beginner. Good for a KZbin video though. Also the amount of code on each line is way too much for me, I’m too used to clang format haha
@cheesed_up
@cheesed_up 4 ай бұрын
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!
@clojurediary
@clojurediary 5 ай бұрын
Wow!
@Paxsali
@Paxsali 5 ай бұрын
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...
@DeclanMBrennan
@DeclanMBrennan 4 ай бұрын
Crystal clear to the compiler but hard on the human with *L* ots of *I* rritating *S* uperfluous *P* arentheses. 🙂 (A very old joke).
@0LoneTech
@0LoneTech 3 ай бұрын
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).
@TopchetoEU
@TopchetoEU 4 ай бұрын
for the love of christ never show your code publicly again
@TinyDeskEngineer
@TinyDeskEngineer 5 ай бұрын
Excuse me, _what_
@cheesed_up
@cheesed_up 4 ай бұрын
WHO?
I Made My Own Programming Language
10:20
CodeNoodles
Рет қаралды 103 М.
"BEST C++ CODE ever written" // Code Review
27:38
The Cherno
Рет қаралды 122 М.
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
Une nouvelle voiture pour Noël 🥹
00:28
Nicocapone
Рет қаралды 9 МЛН
Cat mode and a glass of water #family #humor #fun
00:22
Kotiki_Z
Рет қаралды 42 МЛН
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН
I wrote a Compiler for my Custom 16-bit Computer
13:09
Mathis
Рет қаралды 55 М.
Real-Time Operating System in 96 Lines of C | RIOS
10:04
Cheesed Up
Рет қаралды 89 М.
Python 3.13 vs. Julia 1.11 with Word Frequencies
5:56
EKB PhD
Рет қаралды 2,8 М.
Arenas, strings and Scuffed Templates in C
12:28
VoxelRifts
Рет қаралды 103 М.
Teaching myself C so I can build a particle simulation
11:52
Gradience
Рет қаралды 344 М.
C++ Super Optimization: 1000X Faster
15:33
Dave's Garage
Рет қаралды 333 М.
Writing Code That Runs FAST on a GPU
15:32
Low Level
Рет қаралды 578 М.
how do hackers exploit buffers that are too small?
8:25
Low Level
Рет қаралды 208 М.
A Compiler For Our Own Programming Language // Full Guide
18:54
Faster than Rust and C++: the PERFECT hash table
33:52
strager
Рет қаралды 616 М.
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН