using PHP like its 2023!
Chelo comrade!
i elevated your code to use features, a professional PHP developer would use in 2023.
This addresses most of your concerns you had with the language during your livestream, and i feel like the diff of this PR will provide you with a simple oversight of what is possible and what the language provides nowadays, without you having to learn/lookup stuff.
As you just have written this code, you probably can easily spot the differences and draw your conclusions. Maybe you will even give PHP a second chance some time in the future ;P
Does this break compatibility with older versions of PHP?
Does this break compatibility with older versions of PHP?
yes I think it support php >= 8.1 (because enums are introduced in php 8.1)
Does this break compatibility with older versions of PHP?
yes, this is correct. follwing is a deduction of the features according to PHP version:
constructor property promotion (for less verbosity):
this came with PHP 8.0
strong attribute types:
these are available (with the union types) since PHP 8.0
strong parameter types:
these are available (with custom class Types) from PHP 7.4
strong return types:
this (especially the void type) came about in PHP 7.2
the mighty enums:
are available since PHP 8.1
so in conclusion, the minimum version to run all my changes is PHP 8.1. I do not think that would be a problem, as this does not have to run as a cgi script for a webserver, so using newer PHP versions should be fine.
For a broader support, would not it work better to use regex to get the tokens?
@KeremArdicli I think regex is only allowed for HTML parsers. This is a C compiler.
with fopen() you read the content of a file as a string hence can use regex on it. So you can tokenize whatever you like. If you are good at regex, Then you can push tokens into array and can iterate on that array for the compiler part.
the whole tokenizer will not be longer than 10 lines of codes.
lgtm
with fopen() you read the content of a file as a string hence can use regex on it. So you can tokenize whatever you like. If you are good at regex, Then you can push tokens into array and can iterate on that array for the compiler part.
the whole tokenizer will not be longer than 10 lines of codes.
you really should read up a bit about recursive descent parsers and why they do not use regular expressions most of the time.
you really should read up a bit about recursive descent parsers and why they do not use regular expressions most of the time.
@KeremArdicli is talking about using regex for just the tokenizer/lexer, not the grammar parser.
A 'real' php developer walk's in the room.... ;-) This pr needs polyfills to make it work with php 7.4 and newer.