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

  Рет қаралды 117,056

Tsoding Daily

Tsoding Daily

Жыл бұрын

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
@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?
@__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
@Phytolizer
@Phytolizer Жыл бұрын
Python is my favorite kind of assembly
@valovanonym
@valovanonym Жыл бұрын
Ah yes pyasm
@gusic4529
@gusic4529 4 ай бұрын
pasm
@ThisShitWontWor
@ThisShitWontWor 2 ай бұрын
pasthmatic
@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 6 ай бұрын
So is Terry Davis' HolyC okay?
@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..
@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 7 ай бұрын
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!
@lowlight1063
@lowlight1063 2 ай бұрын
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
@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!
@fer.barrios
@fer.barrios Жыл бұрын
That was awesome (including your neighbors "moving furniture" lol), really cool to watch!
@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
@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
@AndrewTSq
@AndrewTSq Жыл бұрын
My favourite coder on twitch and youtube!.
@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: kzbin.info/www/bejne/boKzY5l6d66roK8
@sebastiangudino9377
@sebastiangudino9377 Жыл бұрын
It comes from Go
@nekoill
@nekoill Жыл бұрын
General Tso only codes in PHP ironically I love this guy
@ggoadmusic
@ggoadmusic 5 ай бұрын
Dude I love your content.
@_dnL
@_dnL Жыл бұрын
what a php rollercoaster ride from insanity of comparison to "as safe as rust" out of bounds checks :D
@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
@cheebadigga4092
@cheebadigga4092 6 ай бұрын
I had no idea implementing cat was so easy tbh jokes aside, thank you for the lexer algorithm. This is super useful!
@joaomachado9105
@joaomachado9105 Жыл бұрын
you have some pretty amazing project ideas 🤣
@ayoubbelatrous9914
@ayoubbelatrous9914 Жыл бұрын
a C programmer forgetting to add a semicolon at the end of lines very suspicious.
@ilyasabi8920
@ilyasabi8920 Жыл бұрын
My God, he is the chosen one! The divine intellect, may saint terry protect you from glovies tsoding.
@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
@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! 👍
@ChickenFingers42
@ChickenFingers42 Жыл бұрын
UnholyC
@Lemon_Inspector
@Lemon_Inspector Жыл бұрын
This is undoubtedly the greatest atrocity of the 21st century
@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.
@Lars-ce4rd
@Lars-ce4rd 2 ай бұрын
Nice text file editing session.
@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 7 ай бұрын
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?
@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.
@the_primal_instinct
@the_primal_instinct 2 күн бұрын
The main reason why php devs don't close the
@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 KZbin.
@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.
@GegoXaren
@GegoXaren Жыл бұрын
I'm Pretty sure the scientific notation problem is fixed with the introductian of type hinting.
@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!
@notarandom7
@notarandom7 Жыл бұрын
Let this be a lesson, just because you can do it, doesn't mean you should
@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.
@ankitpoudel8750
@ankitpoudel8750 7 ай бұрын
Absolute madman lmao
@XELER53
@XELER53 Жыл бұрын
Epic
@deathlife2414
@deathlife2414 Жыл бұрын
Thinking of being php at summer.
@abrarmasumabir3809
@abrarmasumabir3809 Жыл бұрын
Using vim huh! That's good to see!
@roshanjungkunwar8440
@roshanjungkunwar8440 5 ай бұрын
emacs too
@omarkandil1515
@omarkandil1515 8 ай бұрын
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
@b1.7.3
@b1.7.3 Жыл бұрын
Now I've seen everything.
@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
@enriquejosemunozavellan5517 11 ай бұрын
Hi there! Where would you suggest learning php instead? Like getting to know the inside outs of the langage, not only the surface parts...?
@Pi7on
@Pi7on Жыл бұрын
Any plans to bring back some porth content?
@strongleongch
@strongleongch Жыл бұрын
I want to believe
@kuijaye
@kuijaye Жыл бұрын
Can you implement sed in sed?
@mg-bm1js
@mg-bm1js Жыл бұрын
Quite entertainig...
@RenderDragon
@RenderDragon Жыл бұрын
19:05 Yea, PHP is some kind of "Web Java" xD
@atrumluminarium
@atrumluminarium Жыл бұрын
What in god's name have you unleashed upon this earth... 🙈
@Lars-ce4rd
@Lars-ce4rd 2 ай бұрын
Tsoding talking good about javascript
@GoWithAndy-cp8tz
@GoWithAndy-cp8tz 4 ай бұрын
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 ;)
@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.
@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:
@mierce
@mierce Жыл бұрын
Хорош,мужик
@markmckenzie5343
@markmckenzie5343 Жыл бұрын
Man fights with PHP for 3 hours
@오오예스
@오오예스 Жыл бұрын
Omg
@fasogoss
@fasogoss Жыл бұрын
What's the story behind your tshirt ? How can i get one , I like it
@Synthetic_geth
@Synthetic_geth Жыл бұрын
cursed
@user-wi6mw2ge3f
@user-wi6mw2ge3f Жыл бұрын
In Emacs 28 you can
@dickheadrecs
@dickheadrecs Жыл бұрын
Pure Hell Programming
@AbdelhakOussaid
@AbdelhakOussaid Жыл бұрын
The longest April Fool's joke I've ever seen!
@paolobooker4163
@paolobooker4163 Ай бұрын
Next video: C compiler en HTML OMEGALUL
@linux_devs
@linux_devs Жыл бұрын
That 7gb porn folder 😂
@_runic
@_runic Жыл бұрын
lmao
@mattetis
@mattetis Жыл бұрын
"I know that PHP doesn't yest have native Enumerations" *Asked 14 years ago* "Ah so they were introduced relatively recently..." Lol 😂
@twospikes7387
@twospikes7387 Жыл бұрын
подвинь окно камеры немного вверх, чтобы можно было видеть строку состояния vim
@cbbcbb6803
@cbbcbb6803 Жыл бұрын
Wasn't php written in C/C++?
@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)
@shubhamverma1407
@shubhamverma1407 Жыл бұрын
no PHP was harmed in this video
@skyblue5220
@skyblue5220 Жыл бұрын
Not even one line of code.
@naive_algorithm
@naive_algorithm Жыл бұрын
next challenge make a php compiler where you don't need to use $ for variable
@TheUKofBananas
@TheUKofBananas Жыл бұрын
Why not C compiler in HTML?
@arie1906
@arie1906 Жыл бұрын
Not sure if April Fool or cursed
@AndrieMinecraft
@AndrieMinecraft 9 ай бұрын
April Fools but the vod is late
@mariomaliqi184
@mariomaliqi184 Жыл бұрын
Why do u use the better editor only on April fools?
@user-fv6nc7qi2x
@user-fv6nc7qi2x 10 ай бұрын
ahzoozying session
@makidelille
@makidelille 3 ай бұрын
Imagine if for next april fools, he makes "php.js" a Javascript php runtime, this could be so cursed
@caiocouto3450
@caiocouto3450 7 ай бұрын
16:05 "we build applications that allows people to build applications"
@margaritasato1365
@margaritasato1365 Жыл бұрын
lol, i think only today about it. Ahahaha)
@Lanzelord
@Lanzelord Жыл бұрын
In the foreach you are passing a reference by doing this &$value, it would be like this foreach($array as $value) {}
@user-nf8zb4qp6j
@user-nf8zb4qp6j 7 ай бұрын
Can you do the same, but with 1c language?
@codebroker_
@codebroker_ Жыл бұрын
Emacs can do ligatures now
@grutomo1287
@grutomo1287 Жыл бұрын
I saw the title and almost fainted
@grutomo1287
@grutomo1287 Жыл бұрын
And he used vim lord help me
@simonfarre4907
@simonfarre4907 Жыл бұрын
At 18:15 that is not a ligature.
@teev660
@teev660 Жыл бұрын
now make python with c php!! it would be super fast!
@user-vn1cq5gy4d
@user-vn1cq5gy4d Жыл бұрын
Next challenge, write a compiler in PHP to compile PHP
@izarchtech1528
@izarchtech1528 11 ай бұрын
Do you mean "interpreter" ?
@gargleblasta
@gargleblasta Жыл бұрын
Why was I not subscribed??? I fixed it at once...
@a-rustacean
@a-rustacean Жыл бұрын
PHP is as safe as Rust. Rustaceans: 💀
@chiquinhodelidia
@chiquinhodelidia 8 ай бұрын
- Why? - Yes
@Fernando-du5uj
@Fernando-du5uj 8 ай бұрын
What vim theme is this?
@christopherjaya342
@christopherjaya342 Жыл бұрын
Next up: Python interpreter in PHP
@samjanssens1509
@samjanssens1509 Жыл бұрын
there is a knocking sound in the bg
@antronixful
@antronixful Жыл бұрын
the most cursed shit ever
@wagsman9999
@wagsman9999 Жыл бұрын
Is Tsoding Daily the real engine behind ChatGPT?
@skyblue5220
@skyblue5220 Жыл бұрын
Yes.
@ashrafulmomenshuvo5344
@ashrafulmomenshuvo5344 3 ай бұрын
Make a compiler for php please
@hansdampf2284
@hansdampf2284 Жыл бұрын
Some men just like to see to world burn
@motbus3
@motbus3 Жыл бұрын
"even JavaScript doesn't do shit like this"
@yangtianshuo7358
@yangtianshuo7358 Жыл бұрын
damn
@felipepalermo6719
@felipepalermo6719 Жыл бұрын
Bro, code a C compiler in MOO. Btw, wtf, i hope someday have that knowledge!
I tried React and it Ruined My Life
1:19:10
Tsoding Daily
Рет қаралды 117 М.
Survival skills: A great idea with duct tape #survival #lifehacks #camping
00:27
OMG😳 #tiktok #shorts #potapova_blog
00:58
Potapova_blog
Рет қаралды 4,2 МЛН
Жайдарман | Туған күн 2024 | Алматы
2:22:55
Jaidarman OFFICIAL / JCI
Рет қаралды 1,5 МЛН
Paid Zig Stream
3:20:37
Tsoding Daily
Рет қаралды 86 М.
TypeScript is better than C for this
2:20:56
Tsoding Daily
Рет қаралды 21 М.
You don't need Generics in C
1:37:38
Tsoding Daily
Рет қаралды 58 М.
WHY did this C++ code FAIL?
38:10
The Cherno
Рет қаралды 190 М.
Compilers, How They Work, And Writing Them From Scratch
23:53
Adam McDaniel
Рет қаралды 82 М.
Is this the Future of Programming Languages?
2:53:18
Tsoding Daily
Рет қаралды 63 М.
Gitlab DELETING Production Databases | Prime Reacts
17:27
ThePrimeTime
Рет қаралды 307 М.
coding in C but I start over for every compiler error
16:34
Low Level Learning
Рет қаралды 263 М.
Let's Create a Compiler (Pt.1)
1:11:03
Pixeled
Рет қаралды 485 М.
cute mini iphone
0:34
승비니 Seungbini
Рет қаралды 6 МЛН
YOTAPHONE 2 - СПУСТЯ 10 ЛЕТ
15:13
ЗЕ МАККЕРС
Рет қаралды 153 М.
Что не так с яблоком Apple? #apple #macbook
0:38
Не шарю!
Рет қаралды 345 М.
Main filter..
0:15
CikoYt
Рет қаралды 13 МЛН