Тёмный

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

Tsoding Daily
Подписаться 119 тыс.
Просмотров 119 тыс.
50% 1

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

Наука

Опубликовано:

 

3 апр 2023

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 259   
@__gadonk__
@__gadonk__ Год назад
oh god the title is so cursed
@gabriellevesque2185
@gabriellevesque2185 Год назад
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 Год назад
Next challenge is to make a c compiler in MySQL
@happyfase
@happyfase Год назад
Why you embed this idea as a fact of our immutable reality?
@wuxxy
@wuxxy Год назад
@@happyfase if its immutable js add mut
@soniablanche5672
@soniablanche5672 Год назад
you mean in Visual Basic
@LabhamJain
@LabhamJain Год назад
go for asm
@_lenn.box_
@_lenn.box_ Год назад
@@soniablanche5672 you mean in whitespace?
@Phytolizer
@Phytolizer Год назад
Python is my favorite kind of assembly
@valovanonym
@valovanonym Год назад
Ah yes pyasm
@gusic4529
@gusic4529 5 месяцев назад
pasm
@ThisShitWontWor
@ThisShitWontWor 3 месяца назад
pasthmatic
@asthmaticpathic
@asthmaticpathic Год назад
watching this as a php dev has taught me that the internet is awful at teaching PHP
@eboubaker3722
@eboubaker3722 Год назад
they hate it just to hate it.
@narkocat
@narkocat Год назад
Yep, most suggestions are outdated,docs lack type hints, missing shorthand versions of stuff.
@Alguem387
@Alguem387 Год назад
is it true that php devs drive lambos?
@nctrn07
@nctrn07 Год назад
@@Alguem387 i dont
@crrodriguez
@crrodriguez Год назад
Yes, somehow pretty much all advice is stalled at PHP5 at best..
@xravenx24fe
@xravenx24fe Год назад
Ahh PHP, a language perfect for the implementation of the UnHolyC language.
@guydoesthings7580
@guydoesthings7580 Год назад
Ah yes, the CIA's programming language
@marioh.
@marioh. Год назад
Lol
@albertminnie4900
@albertminnie4900 7 месяцев назад
So is Terry Davis' HolyC okay?
@RenderDragon
@RenderDragon Год назад
18:13 I have been waiting for the phrase "Can your Emacs do that?"
@byterbrodTV
@byterbrodTV Год назад
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 месяцев назад
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!
@bradley1995
@bradley1995 3 месяца назад
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
@fer.barrios
@fer.barrios Год назад
That was awesome (including your neighbors "moving furniture" lol), really cool to watch!
@keremardicli4013
@keremardicli4013 Год назад
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
@yuyi-hao
@yuyi-hao Год назад
i just started to learn compiler design hope so this video will help me in some way
@mazZZzilaplayer
@mazZZzilaplayer Год назад
I guess Porth development series has to be quite relevant for you
@jackgame8841
@jackgame8841 Год назад
don't he is so powerfull
@MaxCoplan
@MaxCoplan Год назад
56:22 that iota idea for enums is actually a 200IQ move 🧠
@twospikes7387
@twospikes7387 Год назад
He did it already: Making Programming Language in Python - Porth Ep.1: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-8QP2fDBIxjM.html
@sebastiangudino9377
@sebastiangudino9377 Год назад
It comes from Go
@johnbeeckler
@johnbeeckler Год назад
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
@_dnL
@_dnL Год назад
what a php rollercoaster ride from insanity of comparison to "as safe as rust" out of bounds checks :D
@RenderDragon
@RenderDragon Год назад
20:18 watching some man editing text files is my favourite thing to do, btw
@kraftwerk28
@kraftwerk28 Год назад
Parser Combinators would be a reasonable thing to implement in php
@GegoXaren
@GegoXaren Год назад
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 Год назад
This is the only thing we allow at work, no more dynamic typing.
@GegoXaren
@GegoXaren Год назад
​@@yyny0 Yeah, dynamic typing is a bane.
@project-lu3qv
@project-lu3qv Год назад
You can even do something like this since php8: class A { public function __construct(public string $str){} }
@GegoXaren
@GegoXaren Год назад
@@project-lu3qv That is a bit too.... Un-verbose for my taste. Lol.
@jordixboy
@jordixboy Год назад
@@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
@ChickenFingers42
@ChickenFingers42 Год назад
UnholyC
@nekoill
@nekoill Год назад
General Tso only codes in PHP ironically I love this guy
@AndrewTSq
@AndrewTSq Год назад
My favourite coder on twitch and youtube!.
@Lemon_Inspector
@Lemon_Inspector Год назад
This is undoubtedly the greatest atrocity of the 21st century
@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!
@thedreadedgman
@thedreadedgman Год назад
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 Год назад
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.
@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! 👍
@ayoubbelatrous9914
@ayoubbelatrous9914 Год назад
a C programmer forgetting to add a semicolon at the end of lines very suspicious.
@ggoadmusic
@ggoadmusic 6 месяцев назад
Dude I love your content.
@ilyasabi8920
@ilyasabi8920 Год назад
My God, he is the chosen one! The divine intellect, may saint terry protect you from glovies tsoding.
@churchers
@churchers Год назад
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 8 месяцев назад
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?
@joaomachado9105
@joaomachado9105 Год назад
you have some pretty amazing project ideas 🤣
@GegoXaren
@GegoXaren Год назад
I'm Pretty sure the scientific notation problem is fixed with the introductian of type hinting.
@Mozartenhimer
@Mozartenhimer Год назад
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.
@DonaldDuvall
@DonaldDuvall Год назад
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 RU-vid.
@TsodingDaily
@TsodingDaily Год назад
This fact is besides my point twitter.com/tsoding/status/1643464258192015360
@DonaldDuvall
@DonaldDuvall Год назад
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.
@the_primal_instinct
@the_primal_instinct Месяц назад
The main reason why php devs don't close the
@auntiecarol
@auntiecarol Год назад
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.
@Lars-ce4rd
@Lars-ce4rd 4 месяца назад
Nice text file editing session.
@Franky_PT
@Franky_PT Год назад
Therapist: A C compiler made in PHP doesn't exhist it can't hurt you... Meanwhile, a C compiler made in PHP:
@notarandom7
@notarandom7 Год назад
Let this be a lesson, just because you can do it, doesn't mean you should
@tonym5857
@tonym5857 Год назад
Hi Mr T, great video again 💪, please Can you finish it with assembler generation 🙏🙏🙏. Regards
@JohnMurphy-iw2ce
@JohnMurphy-iw2ce Год назад
How you become so good in programming? damn!
@PetaPelikan
@PetaPelikan Год назад
Alternative title : bullying PHP for three hours straight
@DumblyDorr
@DumblyDorr Год назад
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
Hi there! Where would you suggest learning php instead? Like getting to know the inside outs of the langage, not only the surface parts...?
@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
@kuijaye
@kuijaye Год назад
Can you implement sed in sed?
@RenderDragon
@RenderDragon Год назад
19:05 Yea, PHP is some kind of "Web Java" xD
@deathlife2414
@deathlife2414 Год назад
Thinking of being php at summer.
@XELER53
@XELER53 Год назад
Epic
@Synthetic_geth
@Synthetic_geth Год назад
cursed
@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 ;)
@b1.7.3
@b1.7.3 Год назад
Now I've seen everything.
@georgecop9538
@georgecop9538 Год назад
Don't know how you pull up these themes. It's absolutely crazy. I would like to see a video centered around V(lang)
@fasogoss
@fasogoss Год назад
What's the story behind your tshirt ? How can i get one , I like it
@mattetis
@mattetis Год назад
"I know that PHP doesn't yest have native Enumerations" *Asked 14 years ago* "Ah so they were introduced relatively recently..." Lol 😂
@DonaldDuvall
@DonaldDuvall Год назад
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.
@abrarmasumabir3809
@abrarmasumabir3809 Год назад
Using vim huh! That's good to see!
@roshanjungkunwar8440
@roshanjungkunwar8440 6 месяцев назад
emacs too
@markmckenzie5343
@markmckenzie5343 Год назад
Man fights with PHP for 3 hours
@mg-bm1js
@mg-bm1js Год назад
Quite entertainig...
@atrumluminarium
@atrumluminarium Год назад
What in god's name have you unleashed upon this earth... 🙈
@ankitpoudel8750
@ankitpoudel8750 8 месяцев назад
Absolute madman lmao
@TheUKofBananas
@TheUKofBananas Год назад
Why not C compiler in HTML?
@paolobooker4163
@paolobooker4163 2 месяца назад
Next video: C compiler en HTML OMEGALUL
@Pi7on
@Pi7on Год назад
Any plans to bring back some porth content?
@strongleongch
@strongleongch Год назад
I want to believe
@user-wi6mw2ge3f
@user-wi6mw2ge3f Год назад
In Emacs 28 you can
@AbdelhakOussaid
@AbdelhakOussaid Год назад
The longest April Fool's joke I've ever seen!
@cbbcbb6803
@cbbcbb6803 Год назад
Wasn't php written in C/C++?
@Lars-ce4rd
@Lars-ce4rd 4 месяца назад
Tsoding talking good about javascript
@twospikes7387
@twospikes7387 Год назад
подвинь окно камеры немного вверх, чтобы можно было видеть строку состояния vim
@linux_devs
@linux_devs Год назад
That 7gb porn folder 😂
@_runic
@_runic Год назад
lmao
@arie1906
@arie1906 Год назад
Not sure if April Fool or cursed
@AndrieMinecraft
@AndrieMinecraft 10 месяцев назад
April Fools but the vod is late
@Lanzelord
@Lanzelord Год назад
In the foreach you are passing a reference by doing this &$value, it would be like this foreach($array as $value) {}
@caiocouto3450
@caiocouto3450 8 месяцев назад
16:05 "we build applications that allows people to build applications"
@mierce
@mierce Год назад
Хорош,мужик
@user-nf8zb4qp6j
@user-nf8zb4qp6j 8 месяцев назад
Can you do the same, but with 1c language?
@dickheadrecs
@dickheadrecs Год назад
Pure Hell Programming
@mariomaliqi184
@mariomaliqi184 Год назад
Why do u use the better editor only on April fools?
@오오예스
@오오예스 Год назад
Omg
@shubhamverma1407
@shubhamverma1407 Год назад
no PHP was harmed in this video
@skyblue5220
@skyblue5220 Год назад
Not even one line of code.
@codebroker_
@codebroker_ Год назад
Emacs can do ligatures now
@makidelille
@makidelille 4 месяца назад
Imagine if for next april fools, he makes "php.js" a Javascript php runtime, this could be so cursed
@naive_algorithm
@naive_algorithm Год назад
next challenge make a php compiler where you don't need to use $ for variable
@user-fv6nc7qi2x
@user-fv6nc7qi2x 11 месяцев назад
ahzoozying session
@gargleblasta
@gargleblasta Год назад
Why was I not subscribed??? I fixed it at once...
@simonfarre4907
@simonfarre4907 Год назад
At 18:15 that is not a ligature.
@user-vn1cq5gy4d
@user-vn1cq5gy4d Год назад
Next challenge, write a compiler in PHP to compile PHP
@izarchtech1528
@izarchtech1528 Год назад
Do you mean "interpreter" ?
@margaritasato1365
@margaritasato1365 Год назад
lol, i think only today about it. Ahahaha)
@chiquinhodelidia
@chiquinhodelidia 10 месяцев назад
- Why? - Yes
@teev660
@teev660 Год назад
now make python with c php!! it would be super fast!
@antronixful
@antronixful Год назад
the most cursed shit ever
@grutomo1287
@grutomo1287 Год назад
I saw the title and almost fainted
@grutomo1287
@grutomo1287 Год назад
And he used vim lord help me
@Fernando-du5uj
@Fernando-du5uj 9 месяцев назад
What vim theme is this?
@christopherjaya342
@christopherjaya342 Год назад
Next up: Python interpreter in PHP
@rogo7330
@rogo7330 Год назад
Imagine comparing strings and on some input it will convert to 0 integer (and probably back to '0' but string). Funny
@morgengabe1
@morgengabe1 Год назад
Sounds like another day on javascript island
@soniablanche5672
@soniablanche5672 Год назад
that's why you use === instead of == in both php and javascript
@rogo7330
@rogo7330 Год назад
@@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
@QuickBitMastery
@QuickBitMastery Год назад
Every programmer should have a tab for chatgpt, faster than docs ktself
@HatsuSixtyOne
@HatsuSixtyOne Год назад
Well, very good opinion, but Russia
@wagsman9999
@wagsman9999 Год назад
Is Tsoding Daily the real engine behind ChatGPT?
@skyblue5220
@skyblue5220 Год назад
Yes.
@gandab
@gandab Год назад
33:28 That looks like the 'type coercion' in Javascript, but worse.
@samjanssens1509
@samjanssens1509 Год назад
there is a knocking sound in the bg
@a-rustacean
@a-rustacean Год назад
PHP is as safe as Rust. Rustaceans: 💀
@ExZeMIP
@ExZeMIP 10 месяцев назад
17:33 thats actually real PHP syntax, not just something made up for the docs
@robmckennie4203
@robmckennie4203 8 месяцев назад
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
@abccba4565
@abccba4565 Год назад
what is his folder name in the bottom of the screenn??
@NobFella
@NobFella 10 месяцев назад
Porn lmaoo
Далее
I unironically liked PHP better than C (c.php Ep.02)
2:47:28
I tried React and it Ruined My Life
1:19:10
Просмотров 122 тыс.
I contributed to C3 Compiler and So Can You
4:15:02
Просмотров 53 тыс.
I regret doing this...
1:20:07
Просмотров 68 тыс.
Is this the Future of Programming Languages?
2:53:18
Просмотров 65 тыс.
Hare Programming Language
1:39:25
Просмотров 49 тыс.
Parsing Java Bytecode with Python (JelloVM Ep.01)
2:25:53
Cracking Secret Message with C and Computer Vision
2:00:36
Why i think C++ is better than rust
32:48
Просмотров 289 тыс.
how NASA writes space-proof code
6:03
Просмотров 2,1 млн
Let's Create a Compiler (Pt.1)
1:11:03
Просмотров 500 тыс.
I fixed Lua
2:16:48
Просмотров 46 тыс.
КАКОЙ SAMSUNG КУПИТЬ В 2024 ГОДУ
14:59
Новые iPhone 16 и 16 Pro Max
0:42
Просмотров 2,4 млн