

GitHub - ircmaxell/PHP-Yacc: A PHP port of kmyacc
source link: https://github.com/ircmaxell/PHP-Yacc
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

PHP-Yacc
This is a port of kmyacc
into PHP. It is a parser-generator, meaning it takes a YACC grammar file and generates a parser file.
A Direct Port (For Now)
Right now, this is a direct port. Meaning that it works exactly like kmyacc
. Looking in the examples, you can see that this means that you must supply a "parser template" in addition to the grammar.
Longer term, we want to add simplifying functionality. We will always support providing a template, but we will offer a series of default templates for common use-cases.
What can I do with this?
You can parse most structured and unstructured grammars. There are some gotchas to LALR(1) parsers that you need to be aware of (for example, Shift/Shift conflicts and Shift/Reduce conflicts). But those are beyond this simple intro.
How does it work?
I don't know. I just ported the code until it worked correctly.
YACC Grammar
That's way beyond the scope of this documentation, but checkout The YACC page here for some info.
Over time we will document the grammar more...
How do I use it?
For now, check out the examples folder. The current state of the CLI tool will change, so any usage today should please provide feedback and use-cases so that we can better design the tooling support.
Why did you do this?
Many projects have the need for parsers (and therefore parser-generators). Nikita's PHP-Parser is one tool that uses kmyacc to generate its parser. There are many other projects out there that either use hand-written parsers, or use kmyacc or another parser-generator.
Unfortunately, not many parser-generators exist for PHP. And those that do exist I have found to be rigid or not powerful enough to parse PHP itself.
This project is an aim to resolve that.
Performance
There's a TON of performance optimizations possible here. The original code was a direct port, so some structures are definitely sub-optimal. Over time we will improve the performance.
However, this will always be at least a slightly-slow process. Generating a parser requires a lot of resources, so should never happen inside of a web request.
Using the generated parser however should be quite fast (the generated parser is fairly well optimized already).
What's left to do?
A bunch of things. Here's the wishlist:
- Refactor to make conventions consistent (some parts currently use camel-case, some parts use snakeCase, etc).
- Performance tuning
- Unit test as much as possible
- Document as much as possible (It's a complicated series of algorithms with no source documentation in either project).
- Redesign the CLI binary and how it operates
- Decide whether multi-language support is worth while, or if we should just move to only PHP codegen support.
- Add default templates and parser implementations
- At least one of which generates an "AST" by default, similar to Ruby's Treetop library
- Build a reasonably performant lexer-generator (very likely as a separate project)
- A lot of debugging (though we don't know of any bugs, they are there)
- Building out of features we didn't need for the initial go (for example, support for
%union
, etc).
And a lot more.
Contributing
Recommend
-
115
README.md shadowsocks-go Current version: 1.2.1
-
60
GitHub is where people build software. More than 28 million people use GitHub to discover, fork, and contribute to over 85 million projects.
-
54
README.md A compiler for PHP Ok, so this used to be a dead project. It required calling out to all sorts of hackery to generate PHP extensions, or PHP...
-
57
README.md PHP Ast Visualizer This library will take an AST generated from Nikita's PHP-Parser and gen...
-
46
README.md PHPVM This project is currently an experiment. It will likely break your system. You have been warned. Installation Cl...
-
44
README.md sock_port iOS 11.0-12.2 tfp0 for all devices (in theory). Some info: Uses socket bug by Ned Williamson Uses some...
-
53
three.kt (Work in progress) Kotlin/JVM port of the popular three.js 3D library (r106). Be warned,...
-
16
In the field of parsing Lex and
-
8
lex&yacc 2014.2 春节期间,空闲时间较多,于是研究了一下lex和yacc的用法。知道lex和yacc,那还是大四学习编译原理那门课时候的事情了。转眼之间,那已经是十年前的事情了。 编译原理在整个大学期间的专业课中,属于难度比较...
-
7
编译原理工具系列(2)——yacc 发表于 ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK