小编Lis*_*isa的帖子

如何在ANTLR中获取完整的用户编写语句(包括空格)

我有一个Java语言定义的"语句"定义如下.

statement
: block
|   ASSERT expression (':' expression)? ';'
|   'if' parExpression statement ('else' statement)?
|   'for' '(' forControl ')' statement
|   'while' parExpression statement
|   'do' statement 'while' parExpression ';'
|   'try' block
    ( catches 'finally' block
    | catches
    | 'finally' block
    )
|   'switch' parExpression switchBlock
|   'synchronized' parExpression block
|   'return' expression? ';'
|   'throw' expression ';'
|   'break' Identifier? ';'
|   'continue' Identifier? ';'
|   ';'
|   statementExpression ';'
|   Identifier ':' statement
;
Run Code Online (Sandbox Code Playgroud)

在执行解析器时,我还想打印完整的用户编写的语句(包含语句中的空格),例如: …

antlr

6
推荐指数
1
解决办法
1457
查看次数

标签 统计

antlr ×1