Parsing 是否可以在不编写解析器的情况下测试JFlex中的lexer?

Parsing 是否可以在不编写解析器的情况下测试JFlex中的lexer?,parsing,lexer,jflex,cup,Parsing,Lexer,Jflex,Cup,我开始使用JFlex,我想先尝试编写一个lexer,然后再使用解析器。然而,似乎如果不在CUP中编写解析器,就无法测试JFlex lexer 我要做的就是编写一个lexer,给它一个输入文件,然后输出词素,以检查它是否正确读取了所有内容。稍后我想输出标记,但词素将是一个好的开始。是的,可以编写独立的扫描仪。您可以阅读第页的详细信息。如果指定%standalone指令,它将向生成的类添加main方法。您可以将输入文件作为命令行参数来运行此程序。jflex tar附带一个examples目录,您可以

我开始使用JFlex,我想先尝试编写一个lexer,然后再使用解析器。然而,似乎如果不在CUP中编写解析器,就无法测试JFlex lexer


我要做的就是编写一个lexer,给它一个输入文件,然后输出词素,以检查它是否正确读取了所有内容。稍后我想输出标记,但词素将是一个好的开始。

是的,可以编写独立的扫描仪。您可以阅读第页的详细信息。如果指定
%standalone
指令,它将向生成的类添加
main
方法。您可以将输入文件作为命令行参数来运行此程序。jflex tar附带一个examples目录,您可以在
examples/standalone maven/src/main/jflex
目录中找到一个独立的示例。为了快速参考,我在这里发布了一个示例代码

/**
   This is a small example of a standalone text substitution scanner 
   It reads a name after the keyword name and substitutes all occurences 
   of "hello" with "hello <name>!". There is a sample input file 
   "sample.inp" provided in this directory 
*/
package de.jflex.example.standalone;

%%

%public
%class Subst
%standalone

%unicode

%{
  String name;
%}

%%

"name " [a-zA-Z]+  { name = yytext().substring(5); }
[Hh] "ello"        { System.out.print(yytext()+" "+name+"!"); }
/**
这是一个独立文本替换扫描仪的小示例
它读取关键字名称后的名称,并替换所有出现的名称
“你好”和“你好!”。有一个示例输入文件
此目录中提供了“sample.inp”
*/
包de.jflex.example.standalone;
%%
%公开的
%类Subst
%独立的
%统一码
%{
字符串名;
%}
%%
“name”[a-zA-Z]+{name=yytext().子字符串(5);}
[Hh]“ello”{System.out.print(yytext()+“”+name+“!”);}

您是否查看了
%debug
指令?