【发布时间】:2009-11-09 16:36:54
【问题描述】:
权威 ANTLR 指南从一个简单的识别器开始。使用语法逐字定位 C 运行时失败,因为 '%s' 对 ANTLR 意味着什么:
$ cat T.g
grammar T;
options {
language = C;
}
@parser::includes
{
#include <stdio.h>
}
/** Match things like "call foo;" */
r : 'call' ID ';' {printf("invoke %s\n", $ID.text);} ;
ID: 'a'..'z'+ ;
WS: (' '|'\n'|'\r')+ {$channel=HIDDEN;} ; // ignore whitespace
$ java org.antlr.Tool T.g
error(146): T.g:13:19: invalid StringTemplate % shorthand syntax: '%s'.
在这种情况下如何告诉 ANTLR 忽略 '%'?
【问题讨论】: