簡體   English   中英

ANTLR:輸入端沒有可行的選擇

[英]ANTLR: no viable alternative at input

對不起,我的英語不好。

我從本手冊中為GDB / MI輸出命令編寫了ANTLR4-語法:

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的一些輸出字符串:

  1. “〜\\”從C:\\\\ src.exe讀取符號... \\“”-確定(帶外記錄->流記錄-> console_stream_output)
  2. “(gdb)”->確定(終止符記錄)
  3. “^ DONE,BKPT = {數= \\” 1 \\”,鍵入= \\ “斷點\\”,DISP = \\ “保持\\”,啟用= \\ “Y \\”,地址= \\ “0x00000000004014e4 \\”,文件= \\ “src.s \\”,全名= \\ “C:\\\\ src.s \\”,行= \\ “17 \\”,線程組= [\\ “I1 \\”],倍= \\ “0 \\”,原-location = \\“ main \\”}“-失敗(例外:第1:0行在輸入'^ done,bkpt = {number ='處無其他選擇)
  4. “ ^ done,bkpt = \\” 1 \\“”-失敗(行1:0在輸入'^ done,bkpt =處沒有可行的選擇)
  5. “ ^ done,bkpt = {}”-失敗(行1:0在輸入'^ done,bkpt = {}'處沒有可行的選擇)

為什么我的解析器無法識別3-5號字符串?

PS:Nuget的ANTLR v.4.2.0預發行版的C#目標

對於初學者,請讓您的STRING_LITERAL匹配引號:不要在解析器規則中匹配引號。 並讓您的VARIABLE規則至少匹配一個字符(將*更改為+)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM