In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-11-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this article Xiaobian for you to introduce in detail "PHP how to achieve lexical analysis and custom language", the content is detailed, the steps are clear, the details are handled properly, I hope that this "PHP how to achieve lexical analysis and custom language" article can help you solve your doubts, following the editor's ideas slowly in depth, together to learn new knowledge.
There was a requirement in the previous project. The business staff wrote some custom formulas in Chinese, and then we needed to implement the background to return the results to the interface, so we wrote this lexical analyzer based on the finite state machine, which is relatively simple. I hope to be able to throw a brick to attract jade.
I. Analysis of requirements
Enter a Chinese formula and return the result, such as:
Existing salary = 10000; personal tax starting point = 3000; current year = 2021; if (current year = 2022) {personal tax starting point = 5000;} return (existing salary-personal tax starting point) * 0.2
Second, to meet the needs
The original idea is to use string substitution to replace Chinese keywords with php keywords, and then call eval to execute, which is indeed possible, but it is not very beautiful and cannot be dynamically parsed. I thought it would be nice to implement a simple lexical analysis and then convert the lexical analysis into php code with ast. The current version does not use abstract syntax trees to generate code, all using string concatenation.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.