ANTLR, ANother Tool for Language Recognition, is a language tool that provides a framework for constructing recognizers, interpreters, compilers, and translators from grammatical descriptions containing actions in a variety of target languages. ANTLR provides excellent support for tree construction, tree walking, translation, error recovery, and error reporting.
根據
ANTLR官方網站的介紹,ANTLR是一個能提供辨識文章結構、語法的語言工具,根據使用者定義的文法結構,把資料讀入處理過後再輸出。而ANTLR算是一個中介語言,他能把使用者自訂的文法結構轉換成使用者指定的程式語言,例如:Java, C/C++, C#...等。(
支援語言列表)
簡單來說,ANTLR就是一個parser的製造機。什麼是parser,感覺就像灌香腸,把原料絞肉(input data)放進去,經過機器(parser),就變成肥肥的香腸(data output)。
ANTLR主要由兩樣東西組成:
Lexer和
Parser。