Ok, I made C compiler in PHP (c.php Ep.01)

Поделиться
HTML-код
  • Опубликовано: 3 апр 2023
  • I initially planned to compile C into Assembly but due to limited time I implemented only the Python backend. But the code is pretty flexible. So if you need the Assembly backend feel free to submit a PR: github.com/tsoding/c.php
    Chapters:
    - Coming soon...
    References:
    - stackoverflow.com/questions/2...
    - github.com/tsoding/c.php
  • НаукаНаука

Комментарии • 259

  • @__gadonk__
    @__gadonk__ Год назад +246

    oh god the title is so cursed

    • @gabriellevesque2185
      @gabriellevesque2185 Год назад +18

      Exactly my thoughts haha
      I said: "Oh god..."
      I obviously clicked, then saw the video length... 3 hours
      "OOohhhh Goddddd"...

    • @vladinosky
      @vladinosky Год назад

      You shall burn in hell for such evil!

    • @eboubaker3722
      @eboubaker3722 Год назад

      I love php, like c but less verbose

  • @manacht2727
    @manacht2727 Год назад +596

    Next challenge is to make a c compiler in MySQL

    • @happyfase
      @happyfase Год назад +22

      Why you embed this idea as a fact of our immutable reality?

    • @wuxxy
      @wuxxy Год назад +29

      @@happyfase if its immutable js add mut

    • @soniablanche5672
      @soniablanche5672 Год назад +4

      you mean in Visual Basic

    • @LabhamJain
      @LabhamJain Год назад +1

      go for asm

    • @_lenn.box_
      @_lenn.box_ Год назад +1

      @@soniablanche5672 you mean in whitespace?

  • @Phytolizer
    @Phytolizer Год назад +220

    Python is my favorite kind of assembly

  • @xravenx24fe
    @xravenx24fe Год назад +287

    Ahh PHP, a language perfect for the implementation of the UnHolyC language.

  • @asthmaticpathic
    @asthmaticpathic Год назад +236

    watching this as a php dev has taught me that the internet is awful at teaching PHP

    • @eboubaker3722
      @eboubaker3722 Год назад +28

      they hate it just to hate it.

    • @narkocat
      @narkocat Год назад +35

      Yep, most suggestions are outdated,docs lack type hints, missing shorthand versions of stuff.

    • @Alguem387
      @Alguem387 Год назад +19

      is it true that php devs drive lambos?

    • @nctrn07
      @nctrn07 Год назад +11

      @@Alguem387 i dont

    • @crrodriguez
      @crrodriguez Год назад +18

      Yes, somehow pretty much all advice is stalled at PHP5 at best..

  • @RenderDragon
    @RenderDragon Год назад +17

    18:13 I have been waiting for the phrase "Can your Emacs do that?"

  • @byterbrodTV
    @byterbrodTV Год назад +12

    Finally the content that we are all deserve.🔥
    Didn't watch the whole video yet, but i'll it definetly.
    And btw, welcome to the PHP club!

  • @daviddwq4513
    @daviddwq4513 8 месяцев назад +1

    Awesome! Simple really like it! The whole processe of thinking and how to use even an almost unknown language and build something from scratch! This video teach me a lot of things, not of PHP but how to really code thinking! Thank you so much!

  • @fer.barrios
    @fer.barrios Год назад

    That was awesome (including your neighbors "moving furniture" lol), really cool to watch!

  • @bradley1995
    @bradley1995 2 месяца назад

    Finding myself working with php is exactly like this video. Everything has its own set of rules compared to oop and type structure. Love seeing your problem solving and frustration at the sametime!

  • @lowlight1063
    @lowlight1063 3 месяца назад

    This is so nice. Just watching a man discover something new for himself, just a pure stream of curiosity. Makes me wanna go out and learn a random language

  • @yuyi-hao
    @yuyi-hao Год назад +22

    i just started to learn compiler design hope so this video will help me in some way

    • @mazZZzilaplayer
      @mazZZzilaplayer Год назад +6

      I guess Porth development series has to be quite relevant for you

    • @jackgame8841
      @jackgame8841 Год назад

      don't he is so powerfull

  • @MaxCoplan
    @MaxCoplan Год назад +12

    56:22 that iota idea for enums is actually a 200IQ move 🧠

    • @twospikes7387
      @twospikes7387 Год назад +3

      He did it already:
      Making Programming Language in Python - Porth Ep.1: ruclips.net/video/8QP2fDBIxjM/видео.html

    • @sebastiangudino9377
      @sebastiangudino9377 Год назад +1

      It comes from Go

  • @johnbeeckler
    @johnbeeckler Год назад +2

    Bravo! at 15:49, the best 20 seconds ever! I love your channel. Keep it up, that was epic.

    • @johnbeeckler
      @johnbeeckler Год назад

      Ohn man, there is so much good stuff in this video! 16:50

  • @AndrewTSq
    @AndrewTSq Год назад

    My favourite coder on twitch and youtube!.

  • @_dnL
    @_dnL Год назад +3

    what a php rollercoaster ride from insanity of comparison to "as safe as rust" out of bounds checks :D

  • @keremardicli4013
    @keremardicli4013 Год назад +21

    While using PHP you have to keep in mind that it is a language mainly developed for web pages, can run together with html and so. It evolved alot and has become a real backend language with great oops features. It is not a compiled language and meant to run as long as possible with interference.
    To prevent type conversion etc you can use strict types. Then you need to tell what kind of a variable it is

  • @nekoill
    @nekoill Год назад

    General Tso only codes in PHP ironically
    I love this guy

  • @ayoubbelatrous9914
    @ayoubbelatrous9914 Год назад +6

    a C programmer forgetting to add a semicolon at the end of lines very suspicious.

  • @kraftwerk28
    @kraftwerk28 Год назад +7

    Parser Combinators would be a reasonable thing to implement in php

  • @cheebadigga4092
    @cheebadigga4092 7 месяцев назад

    I had no idea implementing cat was so easy tbh
    jokes aside, thank you for the lexer algorithm. This is super useful!

  • @joaomachado9105
    @joaomachado9105 Год назад +1

    you have some pretty amazing project ideas 🤣

  • @ggoadmusic
    @ggoadmusic 6 месяцев назад

    Dude I love your content.

  • @GegoXaren
    @GegoXaren Год назад +30

    It seems you can use type-hinting in PHP now.
    It's been possible since 7.4. That would make code a bit more readable.
    You can do something like:
    class A {
    public string $my_str;
    public __construct (string $str) {
    $this->my_str = $str;
    }
    }

    • @yyny0
      @yyny0 Год назад +21

      This is the only thing we allow at work, no more dynamic typing.

    • @GegoXaren
      @GegoXaren Год назад +3

      ​@@yyny0
      Yeah, dynamic typing is a bane.

    • @project-lu3qv
      @project-lu3qv Год назад +11

      You can even do something like this since php8:
      class A {
      public function __construct(public string $str){}
      }

    • @GegoXaren
      @GegoXaren Год назад +4

      @@project-lu3qv
      That is a bit too.... Un-verbose for my taste. Lol.

    • @jordixboy
      @jordixboy Год назад +2

      @@yyny0 I never understood that, why use a language like PHP or Python to later force Types? the whole point of these languages is exactly that: "If it walks like a duck, quacks like a duck, then probably its a duck". If you want type-safety use a language that comes with type-safety like rust

  • @FranFuentesR
    @FranFuentesR Год назад

    Thanks. I was thinking "why is this guy calling, actual, the devil doing this so weird thing? Maybe he couldn't find a recent corpse and a crossroad with a hang tree?"... But, guy, it's amazing! 👍

  • @RenderDragon
    @RenderDragon Год назад +5

    20:18 watching some man editing text files is my favourite thing to do, btw

  • @ilyasabi8920
    @ilyasabi8920 Год назад +2

    My God, he is the chosen one! The divine intellect, may saint terry protect you from glovies tsoding.

  • @ChickenFingers42
    @ChickenFingers42 Год назад +13

    UnholyC

  • @Lemon_Inspector
    @Lemon_Inspector Год назад +3

    This is undoubtedly the greatest atrocity of the 21st century

  • @Mozartenhimer
    @Mozartenhimer Год назад +7

    Re: remembering syntax. I noticed once I started understanding multiple languages, there's a separate layer in my brain that translates syntax into the abstract concepts of the programming language represent. It took awhile to decouple the syntax from the brains abstract syntax tree.

  • @the_primal_instinct
    @the_primal_instinct 27 дней назад

    The main reason why php devs don't close the

  • @thedreadedgman
    @thedreadedgman Год назад +12

    Of course PHP has associative arrays as first-class citizens, and classes only added later, so idiomatic PHP would have used associative arrays for most of the data structures.. what you've written is a very C-style PHP with structs as classes... I do like what you've done tho - very entertaining

    • @soniablanche5672
      @soniablanche5672 Год назад +1

      arrays are really weird in php, out of all the languages I use, it's the only one that copies the array when you pass it to another variable or to a function argument. If you don't want to copy the array, you have to explicitly put a "&" in the function parameter so that it's passed by reference.

  • @auntiecarol
    @auntiecarol Год назад +2

    Feeling grateful that you didn't ditch the Debian in favour of Hanna Montana Linux.
    Vim is pushing it.
    Windows would have been a joke too far, though, for sure.

  • @churchers
    @churchers Год назад +3

    I know a lot of people hate on php and it has its faults, but it’s annoying to see someone constantly complain when they are trying to blow through the process so fast they don’t bother to actually read up on anything for more than 3 seconds and don’t try to understand what’s right in front on them. Re the stack trace at the start, it very clearly threw at line 4. The trace shows that it was called via the todo function (#0), from the Lexer method call (#1), called from main (#3). There’s absolutely nothing wrong with it.

    • @robmckennie4203
      @robmckennie4203 7 месяцев назад +1

      Okay but you carefully read things and have not written a C compiler in PHP in 3 hours, so who's the real winner here?

  • @GegoXaren
    @GegoXaren Год назад +2

    I'm Pretty sure the scientific notation problem is fixed with the introductian of type hinting.

  • @DonaldDuvall
    @DonaldDuvall Год назад +7

    I understand your frustration with the auto evaluation compare operator == but I would like to point out that the string from md5 is not a string like the hex that is printed when you echo it. It is a literal ByteString, not a string like ascii or utf8 or another. Think of it as a ByteArray but works with almost all the str functions. Nowhere have I seen this explained, but in my DFA parser library in PHP it tripped me a few times. Thanks for the good development streams. I watch all of them that make it to RUclips.

    • @TsodingDaily
      @TsodingDaily  Год назад +4

      This fact is besides my point twitter.com/tsoding/status/1643464258192015360

    • @DonaldDuvall
      @DonaldDuvall Год назад +2

      Sorry, I misspoke on the md5 that one is actually a string. It is the sodium_* functions which return the raw bytes in a string.
      How is my sympathy of the frustration of the eval comparator operator beside the point?

    • @soniablanche5672
      @soniablanche5672 Год назад

      in php, regular string are actually byte arrays.
      $emoji = "😀";
      echo strlen($emoji) // returns 4
      echo $emoji[0]; // returns "�" because it's not a valid utf8 byte sequence
      echo $emoji[0] . $emoji[1] . $emoji[2] . $emoji[3]; //returns "😀" because it's the utf8 byte sequence of this emoji
      It makes sense since PHP is heavily inspired by C

    • @DonaldDuvall
      @DonaldDuvall Год назад

      @@soniablanche5672 This has bitten me many times in the past. Thankfully, they have all of the `mb*` functions. I am a little curious why those are not just the default, but instead need to be enabled as an extension.

  • @tonym5857
    @tonym5857 Год назад +1

    Hi Mr T, great video again 💪, please Can you finish it with assembler generation 🙏🙏🙏. Regards

  • @JohnMurphy-iw2ce
    @JohnMurphy-iw2ce Год назад +1

    How you become so good in programming? damn!

  • @Lars-ce4rd
    @Lars-ce4rd 3 месяца назад

    Nice text file editing session.

  • @notarandom7
    @notarandom7 Год назад +1

    Let this be a lesson, just because you can do it, doesn't mean you should

  • @kuijaye
    @kuijaye Год назад +3

    Can you implement sed in sed?

  • @omarkandil1515
    @omarkandil1515 9 месяцев назад

    and u can use struct mode to avoid alot of convertion issues
    for variables types u have type hinting system
    and for constructors u have property promotion for avoids a lot of boiler plate
    and u did gj

  • @fasogoss
    @fasogoss Год назад +1

    What's the story behind your tshirt ? How can i get one , I like it

  • @Pi7on
    @Pi7on Год назад +7

    Any plans to bring back some porth content?

  • @cbbcbb6803
    @cbbcbb6803 Год назад +1

    Wasn't php written in C/C++?

  • @mariomaliqi184
    @mariomaliqi184 Год назад +1

    Why do u use the better editor only on April fools?

  • @DonaldDuvall
    @DonaldDuvall Год назад +1

    I wish I had been able to watch you live. It hurts watching you stumble through PHP, having to rely on bad docs and posts Google shows you.

  • @PetaPelikan
    @PetaPelikan Год назад

    Alternative title : bullying PHP for three hours straight

  • @TheUKofBananas
    @TheUKofBananas Год назад +1

    Why not C compiler in HTML?

  • @abrarmasumabir3809
    @abrarmasumabir3809 Год назад

    Using vim huh! That's good to see!

  • @GoWithAndy-cp8tz
    @GoWithAndy-cp8tz 5 месяцев назад

    isn't better to make C compiler in C in case of compilation speed? I am impressed by the way of what you achieved. Cheers!
    P.S> If no more challenges waiting for you then make C compiler in MS Excel ;)

  • @deathlife2414
    @deathlife2414 Год назад +1

    Thinking of being php at summer.

  • @DumblyDorr
    @DumblyDorr Год назад +3

    W3C is about the worst way to learn about PHP. Not just aren't constructors not mentioned - it lacks all typing and modern features, like readonly properties, (backed) enums, constructor property promotion, annotations. PHP is pretty close to most other OO-languages with first-class functions by now with the omission of generics and typed instance variables (though there are plugins supported by most IDEs where you can add generic type-checking via docblocks or annotation). Even has a few things that are more convenient for writing good OO-code than e.g. C# or Java. Old built-in function sometimes have inconsistent parameter order, but that's not really a problem in an IDE. For the last 4-5 years, it's been pretty clean, performant (has a JIT compiler since 8) and comfortable. It's mixin-handling and package-management are some of the most convenient I know. You also have a strict-typing option, which prevents accidental typecasting. Anf if you then type your functions, you also get an error when you try to pass/return something not matching the signature.
    I still much prefer languages with generics - but most have their own problems. TypeScript has a great type-system, but its got node/deno/bun for server-side programming and the entailed suboptimal package-management. Scala has a superb type-system, but JVM has such a big footprint, and native compilation is limited and a hassle - only Coq, Idris 2 and Agda have a nicer type-system for me, but you don't build applications with those. Rust is also nice, but too inconvenient for higher-level stuff. Python's typing has matured a great deal, and I quite like it, even though generics are a bit cumbersome. If one can live with design-time generics via annotations or docblocks, PHP is actually a decent choice for quite a few situations, because for all the increased expressive power and ability to write clean OO-code, it hasn't lost its convenience, low footprint and high velocity. Far less cumbersome than C or C++, far more lightweight than C# or Java.
    I didn't understand the problem with the stack trace... it exactly traces the callstack in inside-out order, nothing random about it.

    • @enriquejosemunozavellan5517
      @enriquejosemunozavellan5517 Год назад

      Hi there!
      Where would you suggest learning php instead?
      Like getting to know the inside outs of the langage, not only the surface parts...?

  • @atrumluminarium
    @atrumluminarium Год назад

    What in god's name have you unleashed upon this earth... 🙈

  • @XELER53
    @XELER53 Год назад

    Epic

  • @user-nf8zb4qp6j
    @user-nf8zb4qp6j 8 месяцев назад

    Can you do the same, but with 1c language?

  • @Fernando-du5uj
    @Fernando-du5uj 8 месяцев назад

    What vim theme is this?

  • @RenderDragon
    @RenderDragon Год назад +4

    19:05 Yea, PHP is some kind of "Web Java" xD

  • @user-wi6mw2ge3f
    @user-wi6mw2ge3f Год назад +1

    In Emacs 28 you can

  • @markmckenzie5343
    @markmckenzie5343 Год назад +1

    Man fights with PHP for 3 hours

  • @wagsman9999
    @wagsman9999 Год назад +1

    Is Tsoding Daily the real engine behind ChatGPT?

  • @georgecop9538
    @georgecop9538 Год назад +15

    Don't know how you pull up these themes. It's absolutely crazy. I would like to see a video centered around V(lang)

  • @twospikes7387
    @twospikes7387 Год назад +1

    подвинь окно камеры немного вверх, чтобы можно было видеть строку состояния vim

  • @linux_devs
    @linux_devs Год назад +2

    That 7gb porn folder 😂

  • @ankitpoudel8750
    @ankitpoudel8750 8 месяцев назад

    Absolute madman lmao

  • @naive_algorithm
    @naive_algorithm Год назад

    next challenge make a php compiler where you don't need to use $ for variable

  • @AbdelhakOussaid
    @AbdelhakOussaid Год назад

    The longest April Fool's joke I've ever seen!

  • @arie1906
    @arie1906 Год назад +6

    Not sure if April Fool or cursed

  • @Lanzelord
    @Lanzelord Год назад

    In the foreach you are passing a reference by doing this &$value, it would be like this
    foreach($array as $value) {}

  • @b1.7.3
    @b1.7.3 Год назад

    Now I've seen everything.

  • @user-vn1cq5gy4d
    @user-vn1cq5gy4d Год назад

    Next challenge, write a compiler in PHP to compile PHP

  • @mg-bm1js
    @mg-bm1js Год назад

    Quite entertainig...

  • @codebroker_
    @codebroker_ Год назад

    Emacs can do ligatures now

  • @paolobooker4163
    @paolobooker4163 Месяц назад

    Next video: C compiler en HTML OMEGALUL

  • @Franky_PT
    @Franky_PT Год назад +5

    Therapist: A C compiler made in PHP doesn't exhist it can't hurt you...
    Meanwhile, a C compiler made in PHP:

  • @shubhamverma1407
    @shubhamverma1407 Год назад +1

    no PHP was harmed in this video

  • @Lars-ce4rd
    @Lars-ce4rd 3 месяца назад

    Tsoding talking good about javascript

  • @simonfarre4907
    @simonfarre4907 Год назад

    At 18:15 that is not a ligature.

  • @gargleblasta
    @gargleblasta Год назад

    Why was I not subscribed??? I fixed it at once...

  • @makidelille
    @makidelille 4 месяца назад

    Imagine if for next april fools, he makes "php.js" a Javascript php runtime, this could be so cursed

  • @Synthetic_geth
    @Synthetic_geth Год назад +8

    cursed

  • @abccba4565
    @abccba4565 Год назад

    what is his folder name in the bottom of the screenn??

    • @NobFella
      @NobFella 10 месяцев назад

      Porn lmaoo

  • @mattetis
    @mattetis Год назад +3

    "I know that PHP doesn't yest have native Enumerations"
    *Asked 14 years ago*
    "Ah so they were introduced relatively recently..."
    Lol 😂

  • @xfxpositions
    @xfxpositions Год назад

    which vim theme tso using?

    • @NobFella
      @NobFella 10 месяцев назад

      Gruvbox maybee

  • @teev660
    @teev660 Год назад

    now make python with c php!! it would be super fast!

  • @samjanssens1509
    @samjanssens1509 Год назад

    there is a knocking sound in the bg

  • @mierce
    @mierce Год назад

    Хорош,мужик

  • @caiocouto3450
    @caiocouto3450 8 месяцев назад

    16:05 "we build applications that allows people to build applications"

  • @grutomo1287
    @grutomo1287 Год назад

    I saw the title and almost fainted

    • @grutomo1287
      @grutomo1287 Год назад

      And he used vim lord help me

  • @felipepalermo6719
    @felipepalermo6719 Год назад

    Bro, code a C compiler in MOO.
    Btw, wtf, i hope someday have that knowledge!

  • @rogo7330
    @rogo7330 Год назад +6

    Imagine comparing strings and on some input it will convert to 0 integer (and probably back to '0' but string). Funny

    • @morgengabe1
      @morgengabe1 Год назад +2

      Sounds like another day on javascript island

    • @soniablanche5672
      @soniablanche5672 Год назад

      that's why you use === instead of == in both php and javascript

    • @rogo7330
      @rogo7330 Год назад +1

      @@soniablanche5672 correction: that's why strings should be just an array of bytes and converting them is the matter of functions like atoi or strtol

    • @morgengabe1
      @morgengabe1 Год назад

      @@soniablanche5672 that's why those languages are for soggy people

    • @soniablanche5672
      @soniablanche5672 Год назад

      strings in php are actually just bytes, that's why we have strlen() and mb_strlen(), the first one gives you the number of bytes, the second one gives you the number of characters with utf8 as default encoding

  • @dickheadrecs
    @dickheadrecs Год назад

    Pure Hell Programming

  • @a-rustacean
    @a-rustacean Год назад

    PHP is as safe as Rust.
    Rustaceans: 💀

  • @user-fv6nc7qi2x
    @user-fv6nc7qi2x 11 месяцев назад

    ahzoozying session

  • @QuickBitMastery
    @QuickBitMastery Год назад +1

    Every programmer should have a tab for chatgpt, faster than docs ktself

    • @HatsuSixtyOne
      @HatsuSixtyOne Год назад +2

      Well, very good opinion, but Russia

  • @christopherjaya342
    @christopherjaya342 Год назад

    Next up: Python interpreter in PHP

  • @ExZeMIP
    @ExZeMIP 10 месяцев назад

    17:33 thats actually real PHP syntax, not just something made up for the docs

    • @robmckennie4203
      @robmckennie4203 7 месяцев назад

      I don't think he's saying it's not valid syntax, I think he's saying the type in the function prototype is only there as documentation for the programmer and doesn't have any meaning to the interpreter

  • @skyblue5220
    @skyblue5220 Год назад

    Now try to make a C compiler in Assembly or BASIC. xD

  • @gandab
    @gandab Год назад

    33:28 That looks like the 'type coercion' in Javascript, but worse.

  • @hold4564
    @hold4564 7 месяцев назад

    bro has never touched grass.