简体   繁体   English

yy 在扫描仪/词法分析器(例如 jflex)中的意义

[英]Significance of yy in scanner/lexer such as jflex

Whats is the significance of the prefix yy in lexers?词法分析器中前缀yy的意义是什么?

I see methods/fields such as yyline , yycolumn , yytext , etc我看到了yylineyycolumnyytext等方法/字段

Is there some historical significance to the prefix yy in the world of lexers?在词法分析器的世界里,前缀yy有什么历史意义吗?

PS: I am completely new to compilers PS:我对编译器完全陌生

The yy prefix naming convention actually comes from the parser generator Yacc. yy前缀命名约定实际上来自解析器生成器 Yacc。 Lex was originally written to do the lexical analysis for parsers built with Yacc, and so it chose the name yylex for the generated scanner because that is what Yacc expects the scanner to be called. Lex 最初是为用 Yacc 构建的解析器进行词法分析而编写的,因此它为生成的扫描器选择了名称yylex ,因为这正是 Yacc 期望扫描器被调用的名称。

To simplify code generation, both Yacc and Lex use global variables to communicate most information, including the semantic value of the lexemes and their physical position.为了简化代码生成,Yacc 和 Lex 都使用全局变量来传达大部分信息,包括词素的语义值及其物理位置。 Again, the impetus came from Yacc, which expected to find the semantic value for each token in the global variable yylval (which you could think of as meaning yy -lexeme-value).同样,动力来自 Yacc,它希望在全局变量yylval (您可以将其视为yy -lexeme-value)中找到每个标记的语义值。

From there, it was convenient to just require users of scanner and parser generators to avoid all symbols with external linkage whose names start yy , leaving them for the generated code.从那里开始,只要求扫描器和解析器生成器的用户避免所有名称以yy开头的具有外部链接的符号,将它们留给生成的代码是很方便的。 This wasn't seen as much of a restriction since it would have been pretty uncommon for programmers to use a variable with a name starting yy .这不被视为一种限制,因为程序员使用名称以yy开头的变量是非常罕见的。 Even now, it seems unlikely -- I can't recall ever seeing a question on SO related to a variable with a name starting yy conflicting with an internal variable in Lex/Yacc generated code.即使是现在,这似乎也不太可能——我不记得曾经看到过关于 SO 的问题,该问题与名称以yy开头的变量与 Lex/Yacc 生成的代码中的内部变量冲突有关。

Other than being an unusual name prefix, yy was intended to relate to the "y" in "Yacc".除了作为一个不寻常的名称前缀之外, yy旨在与“Yacc”中的“y”相关联。 As it happens, Yacc was so-named as an acronym for "Yet Another Compiler Compiler", which was a self-deprecating and ironic commentary based on the number of attempts to build automated parser generators current in the early 1970s.碰巧的是,Yacc 被称为“Yet Another Compiler Compiler”的首字母缩写词,这是基于 1970 年代初期当前尝试构建自动解析器生成器的次数的自嘲和讽刺评论。 For a variety of reasons, Yacc emerged the winner in this crowded field, and consequently its interface decisions, for better or worse, became a kind of informal standard for future products.由于种种原因,Yacc 在这个拥挤的领域中脱颖而出,因此它的界面决策,无论好坏,都成为未来产品的一种非正式标准。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM