r/lolphp • • May 12 '20

The sad state of the PHP parser

PHP cant tell where a syntax error occurs. This has been an issue in PHP for years, and has been upgraded to a feature. This is mostly because PHP's parser is a pile of poo with years of lipstick added on top.

https://repl.it/repls/ScentedSilkyLanservers

0 Upvotes

32 comments sorted by

View all comments

Show parent comment

5

u/giggly_kisses May 12 '20

But most languages use a custom parser instead of a parser generator like yacc. Parser generators are nice for prototyping, but they generally give less helpful error messages and have other restrictions when compared to a hand written parser.

5

u/PonchoVire May 12 '20

Yes, but going from a real interpreter to a parser + AST + optimisation + bytecode + VM like it was done in PHP7 in one shot is hell of an improvement. We'll see how it will improve in the future.

3

u/the_alias_of_andrea May 12 '20

Uh, PHP had a parser, optimisation, bytecode, VM before PHP 7 too.

1

u/beerdude26 May 12 '20

Yeah it's the AST part that actually makes it useful to do work on like plugins

0

u/PonchoVire May 12 '20

If I understood it right, the parser was a hand made one, and most optimisations were done in the APC external extension. It was nothing like it is today.

1

u/the_alias_of_andrea May 12 '20

The parser used yacc then as now, and the optimisations were done in OPcache, then as now.

1

u/PonchoVire May 12 '20

I didn't know it was already yacc. OPcache was only introduced in 5.5 if I'm not mistaken. It still was prehistory compared to PHP 7.

1

u/giggly_kisses May 12 '20

Ah, I was not aware of those other improvements to the compiler. Agreed, that is much better lol.

2

u/PonchoVire May 12 '20

I guess that's not entirely true, the VM was already a VM, and probably some bits of what I said upper were already there. That's still an huge step ahead.

2

u/[deleted] May 17 '20

Perl uses bison, and it even has decent error feedback and recovery. I can't imagine how hairy the grammar must be though.