Movatterモバイル変換


[0]ホーム

URL:


ANTLR

What is ANTLR?

ANTLR (ANother Tool for Language Recognition) is apowerful parser generator for reading, processing, executing, ortranslating structured text or binary files. It's widely used to buildlanguages, tools, and frameworks. From a grammar, ANTLR generates aparser that can build and walk parse trees.

terenceTerence Parr is a tech lead at Google and until 2022 was a professor of data science / computer science at Univ. of San Francisco. He is the maniac behind ANTLR and has beenworking on language tools since 1989.

Check out Terence impersonating a machine learning droid:explained.ai
Quick Start
To try ANTLR immediately, jump to thenewANTLR Lab!

To install locally, useantlr4-tools, which installs Java and ANTLR if needed and createsantlr4 andantlr4-parse executables:

$pip install antlr4-tools

(Windows must add..\LocalCache\local-packages\Python310\Scripts to thePATH). See theGetting Started doc. Paste the following grammar into fileExpr.g4 and, from that directory, run theantlr4-parse command. Hit control-D on Unix (or control-Z on Windows) to indicate end-of-input. A window showing the parse tree will appear.

grammarExpr;prog:   (exprNEWLINE)* ;expr:expr ('*'|'/')expr    |expr ('+'|'-')expr    |INT    |   '('expr ')'    ;NEWLINE : [\r\n]+ ;INT     : [0-9]+ ;
$antlr4-parse Expr.g4 prog -gui10+20*30^D$antlr4 Expr.g4  # gen code$ls ExprParser.javaExprParser.java
sample3

Latest News

Tweets by @the_antlr_guy

Testimonials

Kudos. I'm actually really liking ANTLR! I have a pretty darn goodvelocity with a rapid prototyping project I am doing in my Google 20%time. For example, I just discovered a feature in rewrite rules thatdoes exactly what I need (referencing previous rule ASTs, p. 174 inyour book). It took me about 5 minutes to get this to work and removean ugly wart from my grammar. Hats off!Guido van Rossum, Inventor of Python
ANTLR is an exceptionally powerful and flexible tool for parsingformal languages. At Twitter, we use it exclusively for query parsingin Twitter search. Our grammars are clean and concise, and thegenerated code is efficient and stable. Thebook is our go-toreference for ANTLR v4 -- engaging writing, clear descriptions andpractical examples all in one place.Samuel Luckenbill, Senior Manager of Search Infrastructure, Twitter, inc.
Just wanted to take the opportunity to say thanks. ANTLR is a BIGimprovement over yacc/lex, and your support for it mostcommendable. Managed to get my tired old brain around it in aday. Nice work!Brad Cox, Inventor of Objective-C
More...

Resources



Getting started with ANTLR v4

ANTLRDocumentation

Runtime API Doc

Browse source tree (github)

Frequently Asked Questions

StringTemplate template engine

[8]ページ先頭

©2009-2025 Movatter.jp