php-parser/grammar
Nikita Popov c758510a37 Add support for PHP 8.1
With the introduction of intersection types, PHP now lexes the
token '&' either as T_AMPERSAND_(NOT_)FOLLOWED_BY_VAR_OR_VARARG.
This completely breaks parsing of any code containing '&'.

Fix this by canonicalizing to the new token format (unconditionally,
independent of emulation) and adjusting the parser to use the two
new tokens.

This doesn't add actual support for intersection types yet.
2021-07-09 16:52:58 +02:00
..
parser.template Rename YYNLSTATES to numNonLeafStates 2017-11-12 16:09:00 +01:00
php5.y Add support for PHP 8.1 2021-07-09 16:52:58 +02:00
php7.y Add support for PHP 8.1 2021-07-09 16:52:58 +02:00
phpyLang.php Moved phpy pseudo lang functions to separate file 2021-04-10 13:40:52 +02:00
README.md Default to using php-yacc to generate the parsers 2019-10-19 15:24:38 +02:00
rebuildParsers.php Moved phpy pseudo lang functions to separate file 2021-04-10 13:40:52 +02:00
tokens.template Move token constants into separate class 2015-06-13 18:39:55 +02:00
tokens.y Add support for PHP 8.1 2021-07-09 16:52:58 +02:00

What do all those files mean?

  • php5.y: PHP 5 grammar written in a pseudo language
  • php7.y: PHP 7 grammar written in a pseudo language
  • tokens.y: Tokens definition shared between PHP 5 and PHP 7 grammars
  • parser.template: A kmyacc parser prototype file for PHP
  • tokens.template: A kmyacc prototype file for the Tokens class
  • rebuildParsers.php: Preprocesses the grammar and builds the parser using kmyacc

.phpy pseudo language

The .y file is a normal grammar in kmyacc (yacc) style, with some transformations applied to it:

  • Nodes are created using the syntax Name[..., ...]. This is transformed into new Name(..., ..., attributes())
  • Some function-like constructs are resolved (see rebuildParsers.php for a list)

Building the parser

Run php grammar/rebuildParsers.php to rebuild the parsers. Additional options:

  • The KMYACC environment variable can be used to specify an alternative kmyacc binary. By default the phpyacc dev dependency will be used. To use the original kmyacc, you need to compile moriyoshi's fork.
  • The --debug option enables emission of debug symbols and creates the y.output file.
  • The --keep-tmp-grammar option preserves the preprocessed grammar file.