GRUN for Antlr4:如何使用? [英] GRUN for Antlr4: How to use?
问题描述
对于语法:
grammar qwe;询问: 列运算符值 EOF;柱子: [a-z_]+;操作员: ('='|'>'|'<');标量: [a-z_]+;价值: 标量;WS : [ \t\r\n]+ ->跳过 ;
COLUMN
和 SCALAR
有相同的规则.
从项目 learning_antlr4
级别运行:
grun qwe tokens -tokens qwe/qwe.tokens
输出为空.
我做错了什么?别名保存在哪里?
假设您已经设置了 grun 别名(如果没有,请参阅本页顶部的 QuickStart https://www.antlr.org):
您想要的是查看由 Lexer 处理您的输入生成的令牌流(而不是您的 qwe.tokens
文件)
qwe.txt:
total_sales>qwe
ANTLR on master [✘+?]➜ antlr4 qwe.g4ANTLR on master [✘+?]➜ javac *.javaANTLR on master [✘+?]➜ grun qwe 令牌 -tokens ,1:0][@1,11:11='>',<操作员>,1:11][@2,12:14='qwe',,1:12][@3,15:14='<EOF>',<EOF>,1:15]
正如你所看到的...... total_sales
和 qwe
都被识别为 COLUMN
令牌,
For grammar:
grammar qwe;
query
: COLUMN OPERATOR value EOF
;
COLUMN
: [a-z_]+
;
OPERATOR
: ('='|'>'|'<')
;
SCALAR
: [a-z_]+
;
value
: SCALAR
;
WS : [ \t\r\n]+ -> skip ;
there are identical rules COLUMN
and SCALAR
. Here I was advised to use grun
aliases.
I installed it for my Ubuntu. And for folders structure:
ran this from project learning_antlr4
level:
grun qwe tokens -tokens < qwe/qwe.tokens
The output was empty.
What do I wrong? Where that aliases are saved?
Assuming you have the grun alias set up (if not, see the QuickStart at the tops of this page https://www.antlr.org):
What you want is to view the token stream produced by the Lexer processing your input (not your qwe.tokens
file)
qwe.txt:
total_sales>qwe
ANTLR on master [✘+?]
➜ antlr4 qwe.g4
ANTLR on master [✘+?]
➜ javac *.java
ANTLR on master [✘+?]
➜ grun qwe tokens -tokens < qwe.txt
[@0,0:10='total_sales',<COLUMN>,1:0]
[@1,11:11='>',<OPERATOR>,1:11]
[@2,12:14='qwe',<COLUMN>,1:12]
[@3,15:14='<EOF>',<EOF>,1:15]
AS you can see... both total_sales
and qwe
are recognized as COLUMN
tokens,
这篇关于GRUN for Antlr4:如何使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!