Compiler in 191 Lines of C | tinyc

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ธ.ค. 2024

ความคิดเห็น • 68

  • @marouaniAymen
    @marouaniAymen 4 หลายเดือนก่อน +66

    Thanks for the video, but the link given in the description seems invalid, can you give a valid one ?

    • @EuphCat-j8s
      @EuphCat-j8s 4 หลายเดือนก่อน

      You can google "tinyc.c" with the double quotation mark included.

  • @amuerta3041
    @amuerta3041 4 หลายเดือนก่อน +26

    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 4 หลายเดือนก่อน +3

      That's exactly what I did. Wrote my own Forth compiler in assembly language!

    • @DeclanMBrennan
      @DeclanMBrennan 3 หลายเดือนก่อน +1

      Smooth? :-) CrowdStrike's VM embedded in a device driver caused an amazing amount of disruption.

    • @cheesed_up
      @cheesed_up  3 หลายเดือนก่อน +1

      @NotMarkKnopfler Did you open-source the project? :D

  • @madbanana22
    @madbanana22 4 หลายเดือนก่อน +52

    why is your system named "fridge"

    • @Lonely_Wiz
      @Lonely_Wiz 4 หลายเดือนก่อน +23

      to confuse hackers lol

    • @ThatGuyGEWP
      @ThatGuyGEWP 4 หลายเดือนก่อน +28

      how else will it stay cool

    • @jeremymcadams7743
      @jeremymcadams7743 2 หลายเดือนก่อน

      Cuz he's chill like that

    • @aciddev_
      @aciddev_ หลายเดือนก่อน

      he liked you and left you ghosted

  • @DeclanMBrennan
    @DeclanMBrennan 3 หลายเดือนก่อน +2

    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  3 หลายเดือนก่อน +2

      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!

  • @WiseWeeabo
    @WiseWeeabo 3 หลายเดือนก่อน +3

    "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  3 หลายเดือนก่อน +1

      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

  • @Qstate
    @Qstate 4 หลายเดือนก่อน +1

    I liked when you compiled the compiler.

  • @atabac
    @atabac 4 หลายเดือนก่อน +12

    link not working, can you put in git?

    • @MrDomingo55
      @MrDomingo55 4 หลายเดือนก่อน

      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 4 หลายเดือนก่อน +8

      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.

  • @enriquedelacal2814
    @enriquedelacal2814 4 หลายเดือนก่อน +2

    Can you provide a source for the tinyc code? Im afraid the link in the description doesnt work

    • @cheesed_up
      @cheesed_up  3 หลายเดือนก่อน +1

      Should be there now!

    • @enriquedelacal2814
      @enriquedelacal2814 3 หลายเดือนก่อน +1

      @@cheesed_upthank you so much! Im cheesed to say im subscribed

  • @vinayakmahajan4513
    @vinayakmahajan4513 4 หลายเดือนก่อน +3

    How the first compiler was compiled? 🤔

    • @Melesio-wm9uv
      @Melesio-wm9uv 4 หลายเดือนก่อน +26

      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.

  • @nothappyz
    @nothappyz 4 หลายเดือนก่อน +1

    This was awesome

  • @narrowbtw3970
    @narrowbtw3970 4 หลายเดือนก่อน +1

    bel video frate :D

  • @suou7938
    @suou7938 4 หลายเดือนก่อน +2

    which font is this? for a second I thought it was comic sands😂

    • @lankin9217
      @lankin9217 4 หลายเดือนก่อน +8

      It's monospace comic sans...

    • @imsuck12
      @imsuck12 4 หลายเดือนก่อน

      maybe it's comic mono

    • @suou7938
      @suou7938 4 หลายเดือนก่อน +1

      @@lankin9217 didn't know such a thing existed...

    • @BlueSheep95
      @BlueSheep95 4 หลายเดือนก่อน +2

      It's called Comic Mono

    • @sean_r
      @sean_r 4 หลายเดือนก่อน

      from undertable

  • @anon_y_mousse
    @anon_y_mousse 3 หลายเดือนก่อน

    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  3 หลายเดือนก่อน +1

      Regarding links: TH-cam masks them if the channel is not big enough or something like that.

    • @anon_y_mousse
      @anon_y_mousse 3 หลายเดือนก่อน

      @@cheesed_up If that's what it was, then congrats on getting big enough. Hopefully that doesn't sound weird.

  • @chibisuke6731
    @chibisuke6731 4 หลายเดือนก่อน +44

    thats not a compiler, but an interpreter
    a compiler would output assember code / binary code

    • @Joorin4711
      @Joorin4711 4 หลายเดือนก่อน +29

      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 4 หลายเดือนก่อน

      @@chibisuke6731 they literally talked about this in the first few minutes

    • @AschKris
      @AschKris 4 หลายเดือนก่อน +5

      This is like saying that clang is not a compiler

    • @antonpieper
      @antonpieper 4 หลายเดือนก่อน

      ​@@Joorin4711by that logic, all interpreters would be a compiler, bevause all of them use Tokenizers and Parsers

    • @NotMarkKnopfler
      @NotMarkKnopfler 4 หลายเดือนก่อน +3

      Not necessarily. A compiler might output byte code like Java or C#.

  • @NicolasVycasNery
    @NicolasVycasNery 4 หลายเดือนก่อน

    The source link is broken, can you fix it?

  • @maximkovalkov1334
    @maximkovalkov1334 4 หลายเดือนก่อน

    FELLOW COMIC CODE ENJOYER 🎉

  • @polarnight-no
    @polarnight-no 4 หลายเดือนก่อน +1

    Very interesting! I found some source code which seems similar here

    • @ycemilk
      @ycemilk 4 หลายเดือนก่อน

      Where do you find these codes?

  • @ji1046
    @ji1046 4 หลายเดือนก่อน

    Link broken :(

  • @gaeshows1938
    @gaeshows1938 4 หลายเดือนก่อน +1

    What accent is this guy speaking?

    • @bunny.bunbob
      @bunny.bunbob 4 หลายเดือนก่อน

      russ/slav

  • @CyprianBergonia
    @CyprianBergonia 4 หลายเดือนก่อน +1

    video looks good, but sound is not clear

    • @cheesed_up
      @cheesed_up  3 หลายเดือนก่อน

      Thanks for the feedback, I'm working on this :D

  • @brentpappas4055
    @brentpappas4055 4 หลายเดือนก่อน

    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

    • @cheesed_up
      @cheesed_up  3 หลายเดือนก่อน +1

      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 3 หลายเดือนก่อน

    Wow!

  • @Paxsali
    @Paxsali 3 หลายเดือนก่อน

    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 3 หลายเดือนก่อน +1

      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 2 หลายเดือนก่อน

      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).

  • @TinyDeskEngineer
    @TinyDeskEngineer 4 หลายเดือนก่อน

    Excuse me, _what_

    • @cheesed_up
      @cheesed_up  3 หลายเดือนก่อน

      WHO?

  • @TopchetoEU
    @TopchetoEU 3 หลายเดือนก่อน

    for the love of christ never show your code publicly again