这段 PHP 代码的目的是什么?
self::$currentend = $cfp;
self::$currentend = &$cfp->next;
self::$basisend = $cfp;
self::$basisend = &$cfp->bp;
它有什么作用?
位于此处。
更新
我的问题是,既然
self::$currentend = $cfp;
self::$currentend = &$cfp->next;
总是评估为
self::$currentend = &$cfp->next;
那么为什么要多一行呢?
self::$currentend = $cfp;
self::$currentend = &$cfp->next;
self::$basisend = $cfp;
self::$basisend = &$cfp->bp;
What does it do?
Found here.
UPDATE
My question is since
self::$currentend = $cfp;
self::$currentend = &$cfp->next;
always evaluates to
self::$currentend = &$cfp->next;
So why the extra line?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的 PHP 代码是 LEMONPHP 端口> 解析器生成器,其中包含以下代码:
它在 PHP 中,因为它在原始 C 中。在原始 C 中,它通过 currentend 指针写入来替换它指向的任何内容(在其他地方分配的内存,可能包含垃圾),然后它更新
currentend
指针以指向cfp->next
指向的struct节点
(即0< /code>,这里,这就是为什么我认为其他例程稍后会为其分配内存的原因)。
换句话说,它将新的结构规则附加到结构规则列表的末尾,同时维护指向“最后一个条目”的指针。 (好吧,是超出末尾的条目。一旦存在,下一个最后条目将去往何处。所有这些都使得访问列表末尾成为 O(1) 操作,对于改进列表追加操作非常有用。 )
Your PHP code is a C->PHP port of the LEMON parser generator, which includes this code:
It's in the PHP because it was in the original C. In the original C, it writes through the
currentend
pointer to replace the contents of whatever it is pointing at (memory allocated elsewhere, probably contains garbage), and then it updates thecurrentend
pointer to point to thestruct node
pointed to bycfp->next
(which is0
, here, which is why I think some other routine will allocate the memory for it later).In other words, it appends the new
struct rule
to the end of a list ofstruct rule
s while maintaining a pointer to the "last entry". (Well, an entry beyond the end. Where the next last-entry will go, once it exists. All of which makes accessing the end-of-the-list an O(1) operation, superb for improving list-append operations.)我不知道那是什么,看起来很奇怪,但我可以解释:
self:: 指的是当前对象/类的类。
$currentend & $basisend 是存储变量名称的变量 - 也就是说,如果代码是这样的:
那么它本质上计算为:
所以无论 $currentend & 后面的值是什么$basisend,它们引用当前类中的静态变量。
的&是一个引用运算符。它基本上意味着您不想复制变量,而是“共享”其他两个变量引用的变量。实际上,为变量分配一个指针。
除此之外,我不知道那是什么或目的是什么。但看起来很有趣。
I have no idea what that is from, it looks weird, but I can explain:
self:: refers to the class of the current object/class.
$currentend & $basisend are variables storing variable names - that is, if the code were like this:
then it essentially evaluates to:
So whatever the value behind $currentend & $basisend, they are refering to static variables within the current class.
The & is a reference operator. It basically means that you do not want to copy the variable, but "share" the variable referenced by both of the other variables. Actually, to assign a pointer to the variable.
Other than that, I have no idea from what that is or what the purpose is. But it looks funny.
正如上面每个人所说,代码并不完整,但它看起来很像 PHP_ParserGenerator 的 Pear 配置。
我怀疑如果您进一步查看代码,您会发现对此类似内容的引用。
The code is incomplete as everyone has stated above, however it looks suspiciously like the Pear Config for PHP_ParserGenerator.
I would suspect if you look further into the code you will find a reference to this of something similar.