对不起,我的英语不好。
我从本手册中写了为GDB/MI输出命令的Antlr4-grammar:
grammar GdbOutput;
output : out_of_band_record | result_record | terminator_record;
result_record : TOKEN? '^' RESULT_CLASS (',' result)*;
out_of_band_record : async_record
| stream_record;
async_record : exec_async_output
| status_async_output
| notify_async_output;
exec_async_output : TOKEN? '*' async_output;
status_async_output : TOKEN? '+' async_output;
notify_async_output : TOKEN? '=' async_output;
async_output : async_class (',' result)*;
RESULT_CLASS : 'done'
| 'running'
| 'connected'
| 'error'
| 'exit';
async_class : 'stopped'; //TODO
result : VARIABLE '=' value;
value : const
| tuple
| list;
const : c_string;
c_string : '"' STRING_LITERAL '"';
tuple : '{}'
| '{' result (',' result)* '}';
list : '[]'
| '[' value (',' value)* ']'
| '[' result (',' result)* ']';
stream_record : console_stream_output
| target_stream_output
| log_stream_output;
console_stream_output : '~' c_string;
target_stream_output : '@' c_string;
log_stream_output : '&' c_string;
terminator_record : '(gdb)';
VARIABLE : [a-z-]*;
STRING_LITERAL : (~('"' | '\' | 'r' | 'n') | '\' ('"' | '\'))*;
TOKEN : [0-9]+;
我尝试了GDB的一些输出字符串:
- "〜" c:\ src.exe ... " - ok(out_of_band_record-> stream_record-> console_stream_output)
- "(gdb)" -> ok(terminator_record)
- "file = " src.s ",fullname = " c:\ src.s ",line = " 17 ",thread-groups = [" i1 "],时代= " 0 ",原始位置= " main "}" - 失败(异常:第1:0,在输入'^done,bkpt = {number =')
- "
- "
为什么我的解析器不识别字符串#3-5?
P.S。:C#ANTLR V.4.2.0 Nuget的预发行
对于初学者,让您的STRING_LITERAL
也匹配引号:不要在解析器规则中匹配它们。并让您的VARIABLE
规则匹配至少一个字符(将 * *更改为a )。