我正在 edx 上做斯坦福大学的 CS143:编译器 我从 this repo
看到了这段代码 /* string ends, we need to deal with some escape characters */
<STRING>\" {
std::string input(yytext, yyleng);
// remove the '\"'s on both sizes.
input = input.substr(1, input.length() - 2);
std::string output = "";
std::string::size_type pos;
if (input.find_first_of('\0') != std::string::npos) {
yylval.error_msg = "String contains null character";
BEGIN 0;
return ERROR;
}
这是一个扫描器规则,用于匹配
string constants
中的flex
。
我不明白的是std::string input(yytext, yyleng);
从哪里来?
我认为这可能是 Flex 的例程,所以我尝试在 Flex 的手册中找到它。我发现了这个:
input() reads the next character from the input stream.
但这似乎不是我要找的。
所以我认为它可能来自图书馆,就像它们包含在文件
的顶部一样#include <cool-parse.h>
#include <stringtab.h>
#include <utilities.h>
#include <string>
我看了一下,但没有发现任何东西。
我对
compiler
还很陌生,任何帮助将不胜感激。