ANTLR v3 FAQ よくある質問
の編集
Top
/ ANTLR v3 FAQ よくある質問
[
トップ
] [
編集
|
差分
|
バックアップ
|
添付
|
リロード
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
-- 雛形とするページ --
10の質問
ABC予想
AI
AI API
AI プロンプト
AIでつかわれているtransformerのまとめ
AIの話題
ANTLR
ANTLR v3 FAQ よくある質問
ANTLR 独学
ANTLR4 独学
ANTLRでOracleのDDLを解析してみる
ANTLRチュートリアル
AOP
API
ARMマイコン基盤
ATOM SHELL理論
Access VBAメモ
Access-Control-Allow-Origin
AndroidとTensorflow
Android開発
Android開発 入門
AngularJS
Anko
Apache Bench
ArchUnitを学ぶ
Axiosとは
Axis2
BI Publisherで始めるデータ駆動型レポート作成
BPMNの勉強
BackTrack4
Blog from iPhone
Bootstrapとは
BracketName
C3 AI Applications
C3 AI エクスマキナ
CSS備忘録
CentOS
ChatGPTの話題
Chevrotainのパーサメソッド
Chevrotain一覧
Chromeエクステンション
Cocoa Touch Static Library
CoffeeScript
Confluent Control Centerやってみる
C言語でオブジェクト志向な記述方法
DDD ドメイン駆動設計
DDL生成ツール
DJUnit
DMM.comのAPIとか
DOSコマンドメモ
Dashcode
DeepFloyd IF
Dockerが動かない場合の対処
ES2015
Eclipse Monkey
Eclipse Plugin
Eclipseの色設定
Eclipse使いがXCode使い初めて知りたいこと
ElasticMQメモ
Elixir
Emmet
Erlangメモ
ExcelファイルをAIに読ませる
Exceptionを見やすく
Expression Tree
FLEX
FLEX リフレクション
Fisheye
FlashやJavascriptを使った演出
FormattingRules
FrontPage
GAE
GAE Data Store API
GENERAL SQL PARSER JAVA を試してみる
GLOBAL
GPT4ALL
GQL
GUIからMacPortsを管理するアプリケーション - Porticus
Generative Adversarial Networks
Gin JavaScriptで構文解析
Git Blame
GitHubアクションを使ったトロイの木馬のまとめ
GitLab
GitLabRunnerを増やす
GitLabでPlantUML使ってみる
GitLabでプロジェクト管理する
GitLabの機能をそのまま使って認証システム作ったらどこまでできる?
GitLabサーバインストールとメンテ注意事項
GitとAntとSpringとJUnit
Google Cloud Platform
Googleの裏技
Google認定プロジェクトマネージャの勉強メモ
Grails
GraphQL
HTM 階層型時間メモリ
HTML スクレイピング
HTML パース
HTML5
HTML5 Canvas
Hadoop
Help
If Then Maybe プログラミング
Inkscape script
InterWiki
InterWikiName
InterWikiSandBox
JAVAの記事一覧
JBoss
JDBC テーブル一覧を得る
JDBC カラム一覧を得る
JDT eclipse
JGRIB
JHIPSTER JDL
JHIPSTER OpenAPI
JHIPSTER エンティティをフィルタリングする
JHIPSTER6.1.2
JHIPSTERでスマホサイト
JHIPSTERのBLUEPRINTを作る
JHIPSTER一覧
JHipster
JHipster API FirstDepelop
JHipster エンティティを更新する
JHipster7をつかってみる
JHipsterでBuleprintを使いこなす
JHipsterのコード生成を改造
JHipsterのプロジェクトをGitLabでCI/CDする
JHipsterのプロジェクトをデプロイする
JMeter
JOOQとは
JSFとStruts
JSqlParser
Java Closure
Java Compiler API
Java Function
Java SQL Parserを調査する
Java Spring AOP
Java Spriteを設計してみる
Java オブジェクトのダンプ
Java ドラックできる曲線
Java 備忘録
Java 文字化け
Java11以降のJRE
Java7サンプルコード
JavaFx
JavaScriptでパーサを作る Chevrotain
Javaasist 動的にクラスを編集
Javascript グラフィックライブラリ
Javascript コーディングパターン
Javascript界隈
Javassist
JavaでSVG
Javaで関数型で引数をとる
JavaのジェネリクスTip
Javaのラムダ式
Javaの有名なライブラリ紹介
Javaは、IDEのテンプレートを使いこなせばいいよ
Javaプログラマ向けモナド
Javaメモリリーク
Jenkins
Jenkins(Hudson)メモ
Jestとは
Jhipsterマイグレーション
Json Yaml Xml Hash Scala
Kafka REST Proxy さわってみる
Kotolin
LDAPサーバをdockerで立ち上げる
Linux メモ
LiquiBaseとは
Lombok
MDBをコンパクトにするVBA
MQL5 小作品
MT4
MT5 EA
MYSQL
MacTool
Macにしゃべらせる
Mac用のメモ
Mattermostを使ってオンプレミスでチャット環境を作る
Maven
Mementoパターン
MenuBar
NILScript
NetBeanでプロファイル
Network Service Desk Engineer
Node-RED
Node-Red
NumPy
OQL オブジェクト問い合わせ言語
OSコマンドインジェクション
ObjctiveC サウンド
ObjectMapperの備忘録
ObjectiveC NSString
ObjectiveC サーバ
ObjectiveC ターミナル用コマンドを作る
ObjectiveC バックグラウンド
ObjectiveC ワーニング
Oculusアプリの開発
OpenFeint
OpenOffice
OpenResty
Outlook VBA
PHP
POSTGRESQL
Pandas Python Data Analysis Library
PdfBox Java用PDFライブラリ
Plagger
PukiWiki
PukiWiki/1.4
PukiWiki/1.4/Manual
PukiWiki/1.4/Manual/Plugin
PukiWiki/1.4/Manual/Plugin/A-D
PukiWiki/1.4/Manual/Plugin/E-G
PukiWiki/1.4/Manual/Plugin/H-K
PukiWiki/1.4/Manual/Plugin/L-N
PukiWiki/1.4/Manual/Plugin/O-R
PukiWiki/1.4/Manual/Plugin/S-U
PukiWiki/1.4/Manual/Plugin/V-Z
PyHipster
QuartzCore
RAD
REST
RWKV
Rails3
Railsと差分開発についての考察
React.js
React.js モーダル画面
RecentDeleted
RedmineLE
Redshift
Relumeでサイトの骨格を作る
Require.js
Rubycocoa
RubyでScalaをコンパイルするツールをつくる
Rubyアソシエーション認定証
Ruby入門
SCALA REPL
SCALA support tool
SCALAの記事一覧
SELinux
SEO
SEO Yahoo対策
SEO対策一覧
SPAM対策
SQLite
SSH
SVNをJavaで操作
SakuraZencoding
SandBox
Scala / Hadoop
Scala Process exec
Scala 遅延評価
Scala/LiftでSlim3
ScalaSigParser
ScalaWithExcel
Scala チュートリアル
Scalaで3D
ScalaでLisp
ScalaとGroovyのPOJO比較
ScalaのIDEについて
Scala言語を学ぶやさしいツール「Kojo」
Slack API やってみる
SocketAppender
Spring
Spring bootでのテストのTIPS
SpringBootのSTSの新規プロジェクトでるエラーの対応
SpringSecurity SAML
Sqlite
Squirrel
StringTemplate
Stringクラス拡張
TALEND
ThreadLocal
Todo一覧
Trac Lightning
Twitter
UltraEdit
Unityでシューティングゲーム作る際のメモ
VBAのコード
VBAをOpenOffice.org Basicにする
VBAをOpenOffice.org+Basicにする
VPN構築の勉強メモ
VPSやIaaSメモ
VSCodeでRuby開発
VSCodeメモ
VSCode用ChatGptのPlugin
VSCode設定
VirtualBox On Mac
Visual Studio Code プラグイン開発
Vuexとは
WBS管理の弊害
WIN32API
WSDL
Watson
WebDesign探訪
WebLogic フィルタ
WikiEngines
WikiName
WikiWikiWeb
Windows10のPowerShell でキーボードの言語切り替え
WindowsTool
Worker Thread パターン
XBee
XDOCLET
XForms
XPath
XSL
YahooPIPES
Yahooインフォセンター
Yet Another Pragger
YouTuber
YukiWiki
anacondaをcygwinで使う
ansible
antlr snippet
antlr 再入門
antlrと日本語
autoit
automator
bluemix
bootstrap2
bower
ccze Colorize log files on CentOS and Ubuntu using ccze tool
centos7
cglibを使って動的コード生成
cocos2d
cygwin
diff
dockerのローカルイメージをDocker-in-Dockerで参照する
eclipse設定
emacs 備忘録
emacs 文字列置換
emacsをviライクにする
excel tips
expectで自動化
figmaにプラグインをインストールする
ftp自動化
gemini
generator-jhipster-gql
git diffを使った構成管理の省力化
goをやってみる
grizzly
gulp
homebrew
iPhone Bluetoothプログラミング
iPhone iAd
iPhone 実機テスト手続き
iPhoneでグラフィックのHellowWorld
iPhoneとGmailメール
iPhoneに実機転送
iPhoneプログラミング
iPhoneプログラミング/ビューを理解すればiPhoneアプリの基礎を押さえられる
iPhoneプログラミング一覧
iPhoneプログラミング入門
iPhone開発/Interface Builder Plug-in
iPhone開発/キャプチャの取り方
intra-mart
jQuery.Flickableのメモ
java spring boot 認証 memo
jersey
jhipster-codeにアノテーション追加してみる
jhipsterのテンプレート改造準備
jparsecドキュメント日本語訳
jparsec入門
kafkaの勉強
log4j2の脆弱性
mac diff
mailcowのインストール
memcached
minecraft マイクラ あるきながら、高速ダンジョン作成
mqttの勉強
nginx_lua
nginxのメモ
node_moduleをnpm linkを使って自分用にする
npm
openapi generator
openapi-generatorをコンパイル
openstack
oraclerac
play framework 1.2.5 sample
play! framework
play!framework selenium
playframework テンプレート
postmanとopenapi
prezi プレゼン
pukiwikiで行動管理
pukiwikiに類似したツール
pukiwiki勉強
pukiwiki記事一覧
python
python3のwindowsでの日本語文字化け対応
pythonでseleniumを使う
pythonのテストに使うライブラリ
rails5
reactでポップアップ表示
redmine
ruby on rails 6.0.0
scala
scala 99problem 32~
scala prototype.zip
scala repl
scala sbaz
scala spring
scala/インストール
scalaでまだ不勉強なところ
scalaのインストール
selenium
slack api
spark
spring boot
spring initializerをつかってプロジェクトのひな型をゲットする
spring-test
springboot
springboot env
storybook
sublimetext2
swagger
tracについて
ubuntu
vaadin
vue を typescriptで開発
vue 共通部品作成
vue.js memo
vue.jsとは
vue.jsのデバッグ
vue一覧
webの編集画面のよくあるパターン
windows環境構築
wordpress
xamppについて
•Axis2の本家のスタートガイドによるWebサービスの作り方
【Javascript】【CLIライブラリ】commanderの勉強
【MQL5】KuniRangeBreakoutEA
いまさらながらC++
びっくりする短いコード
アクター
アニメーション
アノテーション
アプリコット
アプリコット PukiWiki
アプリコード
アプリコード林邦行
イラストのエフェクト
インテンショナルプログラミング
カスタマイズjhipster7.9.3イメージ
カブロボ
ガイガーカウンター
クラスとハッシュマップの関係
クラック対策
クロス集計
コマンドラインという概念への考察
コミニュケーション
コード生成
サロゲートキーを使ったテーブル設計
シェルのサンプル
シェルサンプル
スクレイピング
スレッドプログラミングメモ
ソースtoソース変形
ターミナルをAppleScriptで制御
テキストエディタ作成javascriptフレームワーク
テスト用まっさらDBをdockerでたてる
テスト駆動
テレワーク環境の比較
ドット絵
バイオビルダー合成生物学メモ
バグの少ない設計のためのValueObject
パフォーマンスチューニング
フロントエンドのテストの結合テストを減らすには?
プッシュ技術
プログラマーじゃない人に覚えてほしいプログラムのコメントの書き方
プロジェクト管理スプレッドシート
マイクラ 有名ディメンション モッド
マクスウェル方程式
メタ
ラムダ計算について考える
リベリカJava13いいみたい
リモートワークでのプロジェクト注意点
レイアウトツール
ログ解析
世界の構文解析グラマーたち
予定表
予定表/2009-12-14
予定表/2009-12-18
予定表/2009-12-19
予定表/2009-12-22
予定表/2009-12-23
予定表/2009-12-24
事業の心構え
事業計画方針
人工知能とCUDA
人工知能コンペKaggle
仕様書のフォーマットについての考察
他言語サイトサンプル作成
仮説Oracleの罠
作曲と効果音作り
共和分
口コミ
古いRails5を入れる
哲学
大文字小文字変換
学習をHackする
扶養とシステム
投薬のみのガンの治療薬
擬似コーディングのすすめ
放射能対策
数式を扱う
文章を書く
新エネルギー
新年の抱負2010
新技術 プログラム編
日本のゼネコン式IT開発が失敗する理由
最近更新したページ
未来技術/新技術
枯れた技術の水平思考
株価データ
業界の動向
構文解析の記事一覧
正規表現
気象データ
流れるようなインタフェース
管理画面の生成におけるopenapiとJDLなどの考察
細胞の若返り
経済のことをまとめてみる
脆弱性
自分でPlaggerみたいなのを作るためのメモ
論語/学而第一
負荷テスト
販売/デスクトップPC
販売/ノートパソコン
販売/外部ストレージ
起業
酸化グラフェン
開発哲学
電子出版
電子出版の記事一覧
非可換幾何学
顧客分析のデシル分析とRFM分析
DIコンテナについて考える
MP3から携帯着うたを作る方法
[[構文解析の記事一覧]] *趣旨 [#u4d72e52] 以下のページのタイトルだけでも日本語だったらうれしいとおもったから、和訳に挑戦 http://www.antlr.org/wiki/display/ANTLR3/ANTLR+v3+FAQ *目次 [#j89dd342] #contents *言語ごとのAPI資料 [#i58b97e0] **Java API [#l3924bc8] http://www.antlr.org/api/Java/index.html **C API [#r9793ced] http://www.antlr.org/api/C/index.html **Python API [#ub8f87d9] http://www.antlr.org/api/Python/index.html **C# API [#uad56972] リンク切れ **ActionScript API [#y89f68eb] http://www.antlr.org/api/ActionScript/index.html *ダウンロード可能なサンプル [#y6af65a1] 以下のサイトから Examples と書いてある箇所をさがす http://www.antlr.org/download.html *FAQ - アクション[#v4884d08] **バックトラック中のアクション実行について [#fb0b539f] ANTLR must parse ahead to see if something matches. If it fails, then ANTLR tries the next viable alt. Upon failure, it's pretty hard to undo actions in general so ANTLR gates actions out with something like this: if ( backtracking==0 ) { SymbolTable.getPredefinedType("void"), symtab.getDefaultPkg()); } Labels are still defined, because semantic preds might need them: packageDefinition1=packageDefinition(); AST actions are off during backtracking: if ( backtracking==0 ) list_packageDefinition.add(packageDefinition1.tree); Upon success, antlr still rewinds the input and then does the same parse again "with feeling". Clearly you don't want actions executed when that alt ultimately doesn't succeed. Similarly, when the alt does succeed, you do not want actions executed twice. This all makes sense. The problem arises when you want actions to execute during backtracking so that semantic predicates make sense during backtracking. If you are combining backtracking (syntactic predicates) and semantic predicates for tough languages like C++ then you must execute actions during the backtrack but then avoid them during the parse. To be finished when I know how to solve... **パーサのように単語切り出しではなぜ自分のヘッダは表示されないのか? [#bd885005] Actions are specific to one grammar. When using a combined parser/lexer grammar, use // applies only to the parser: @header {package foo;} // applies only to the lexer: @lexer::header {package foo;} not just the @header. When using a separate (non-combined) parser, @header applies to the parser. Likewise, when using a separate (non-combined) lexer, @header applies to the lexer (it is not necessary to use @lexer::header in this case). *コマンドラインオプション [#oc6ff390] **ANTLR はどこにファイルを出力するのか? [#g089524f] Added by Terence Parr, last edited by Terence Parr on Oct 18, 2009 (view change) ANTLR writes files to the current directory by default. But, the output filename is sensitive to the output directory and the directory where the grammar file was found. If you reference a grammar with a (relative or absolute) path, ANTLR will pull the grammar from that directory and write the output to that directory: $ cd ~parrt $ java org.antlr.Tool T.g # write to ~parrt/TParser.java $ java org.antlr.Tool /foo/T.g # write to /foo/TParser.java If you specify an output directory with -o then ANTLR will put the output files in that directory or underneath if you have a relative path on the grammar file: $ java org.antlr.Tool -o /tmp T.g # write to /tmp/TParser.java $ java org.antlr.Tool -o /tmp sub/T.g # write to /tmp/sub/TParser.java The output directory -o value takes precedence over the grammar's path when the output directory is absolute. $ java org.antlr.Tool -o /tmp /usr/lib/T.g # write to /tmp/TParser.java $ java org.antlr.Tool -o ick /usr/lib/T.g # write to ick/TParser.java $ java org.antlr.Tool -o . /usr/lib/T.g # write to TParser.java Use -fo option to force output to go explicitly into a directory, ignoring any path on the input grammar name. $ java org.antlr.Tool -fo /tmp T.g # write to /tmp/TParser.java $ java org.antlr.Tool -fo /tmp sub/T.g # write to /tmp/TParser.java $ java org.antlr.Tool -fo /tmp /usr/lib/T.g # write to /tmp/TParser.java Note: If the outputDir set by -o is not present it will be created. *デバック [#z9788b07] **How do I broadcast debug events to multiple listeners? [#q2666873] **How do I debug a tree grammar using AntlrWorks? [#bba41dd9] **How do I set up remote debugging anyway? [#m82e3b97] **When do I need to use remote debugging? [#dcb2784f] *FAQ - Error handling [#y78c9c70] **How can I print out the text of the line where an error occurs? [#vba5a23f] *FAQ - General [#o3146b26] **How do I make ANTLRWorks and Visual Studio work together? (CSharp as target language) [#h7b40890] **How do I rebuild ANTLR v3? [#t1a7569f] **How do I turn off the warnings that antlr generated classes show? [#qa226a3c] **What is ANTLR? [#u802a2de] **ANTLR v2 と v3ではどこがちがうのか? [#k0b9ae8b] Added by Terence Parr, last edited by Terence Parr on May 05, 2007 (view change) [See also Migrating from ANTLR 2 to ANTLR 3#NewinANTLR3] There are number of things have changed for the better in v3 including: a brand-new very powerful extension to LL(k) called LL(*) an auto backtracking mode partial parsing result memoization to increase the speed of backtracking a really nice AST rewrite rule mechanism integration of the StringTemplate template engine for generating structured text improved error reporting and recovery a truly retargetable code generator that makes it easy to build backends ("targets"); currently we have the following Code Generation Targets: Java, C#, C, Objective-C, Python with others in development BSD license Perhaps most importantly, Jean Bovet built the amazing ANTLRWorks grammar development environment. ***参考ANTLRWorks [#x5cea315] http://www.antlr.org/works/index.html For ANTLR v3 I decided to make the most common tasks easy by default rather. This means that some of the basic objects are heavier weight than some speed demons would like, but they are free to pare it down leaving most programmers the luxury of having it "just work." For example, to read in some input, tweak it, and write it back out preserving whitespace, is easy in v3. ***LL(*) parsing [#j5c59951] ANTLR v3 does not require you to specify a lookahead depth (k option in v2). ANTLR's new LL(*) algorithm allows parser lookahead to roam arbitrarily far ahead looking for a token or sequence that disambiguates a decision. LL(k) can only look a fixed k symbols ahead. It is the difference between using a cyclic DFA and an acyclic DFA to make lookahead decisions. method : type ID '(' arg* ')' ';' | type ID '(' arg* ')' '{' body '}' ; This is not LL(k) for any finite k. From the left edge, lookahead unbounded to see the ';' vs '{'. We need arbitrary lookahead because of the arg*. If you have actions after ID, you can't easily refactor the rule. ANTLR v3 handles is no problem as long as rule arg is not recursive. ANTLR builds a tight little DFA to scan ahead looking for ';' vs '{'. ***Auto-backtracking [#oc815bd7] Sometimes even LL(*) will not be powerful enough to handle a particular decision or multiple decisions within a grammar. Rather than have to add a bunch of syntactic predicates in those decisions as you would in v2, you can turn on the auto backtracking feature (set option backtrack=true). This feature essentially tells ANTLR that if it fails to analyze a decision, simply figure it out at run time by backtracking across the alternatives within that decision. Take the method rule from the previous section. If rule arg is now recursive (as it is in C), ANTLR will fail to build a DFA because DFA have no stacks. A full parser is required to match the argument list. Just turn on the auto backtracking feature and ANTLR will gladly accept just about any non-left-recursive grammar. grammar C; options { backtrack=true; } method : type ID '(' arg* ')' ';' | type ID '(' arg* ')' '{' body '}' ; ***AST rewrite rules [#kbea4417] v3 introduces a really nice way to build ASTs. The following example demonstrates the AST rewrite mechanism. Anything after -> is considered a tree grammar. ANTLR figures out how to map the parser grammar to tree grammar. packageDefinition : 'package' classname ';' -> ^('package' classname) ; This builds a tree with 'package' at the root and classname as its first child. Here's another example: formalArgs : typename declarator (',' typename declarator )* -> ^(ARG typename declarator)+ ; This builds tree sequences like: ^(ARG int v1) ^(ARG int v2) ***StringTemplate integration [#vc64048b] ANTLR v3 tightly integrates the StringTemplate template engine, which is useful for generating any kind of structure text such as source code or XML. In the following grammar, the rule matches a simple assignment statement and implicitly returns a template. The template is an instance of the assign template pulled from a group of templates (set by you in your main()). The arguments to the template are a series of template attribute assignments. This is the interface between the template mechanism and the parser attribute mechanism. assign_statement : ID '=' INT ';' -> assign(x={$ID.text},y={$INT.text}) ; Here's a rule that creates a template called 'import' for each import definition found in the input stream: grammar Java; options { output=template; } ... importDefinition : 'import' identifierStar SEMI -> import(name={$identifierStar.st}, begin={$identifierStar.start}, end={$identifierStar.stop}) ; The attributes are set via assignments in the argument list. The arguments are actions with arbitrary expressions in the target language. The .st label property is the result template from a rule reference. There is a nice shorthand in actions too: -%foo(a={},b={},...) ctor -%({name-expr})(a={},...) indirect template ctor reference -%{string-expr} anonymous template from string expr -%{expr}.y = z; template attribute y of StringTemplate-typed expr to z -%x.y = z; set template attribute y of x (always set never get attr) to z [languages like python without ';' must still use the ';' which the code generator is free to remove during code gen] Same as '(x).setAttribute("y", z);' See Template construction for more information. ***参考 String Template Engine [#fda0fefc] http://www.stringtemplate.org/ ***5分でわかるString Template Engine [#s211241c] http://www.antlr.org/wiki/display/ST/Five+minute+Introduction ***Integrated lexers and parsers [#c2412b18] Lexers are much easier due to the LL(*)algorithm as well. Previously these two lexer rules would cause trouble because ANTLR couldn't distinguish between them with finite lookahead to see the decimal point: INT : ('0'..'9')+ ; FLOAT : INT '.' INT ; The syntax is almost identical for features in common, but you should note that labels are always '=' not ':'. So do id=ID not id:ID. You can do combined lexer/parser grammars again (ala PCCTS) both lexer and parser rules are defined in the same file. See the examples. Really nice. You can reference strings and characters in the grammar and ANTLR will generate the lexer for you. Semantic predicates hoisting Introduced in ANTLR v1, semantic predicates hoisting is back in v3 (it was absent in v2). Attributes The attribute structure has been enhanced. Rules may have multiple return values, for example. Further, there are dynamically scoped attributes whereby a rule may define a value usable by any rule it invokes directly or indirectly w/o having to pass a parameter all the way down. finally block Code in the finally {...} action executes in the finally block (java target) after all other stuff like rule memoization. Example: foo : FOO ; finally { System.out.println("on the way out of foo"); } Source code The ANTLR source code is much prettier and there are about 800 unit tests so far. You'll also note that the run-time classes are conveniently encapsulated in the org.antlr.runtime package. *FAQ - Getting Started [#a0d52fb0] **Building ANTLR Projects with Maven [#m33a9d37] **How do I install this damn thing? [#hda5b545] **How do I use ANTLR v3 from the command line? [#heaf3e8d] **How do I use ANTLR v3 generated Lexer and Parser from Java? [#a8d757a8] **Where do I find this damn thing? [#ucbd9175] *FAQ - Grammar analysis [#o6a33d38] **How to get a list of all valid options for the next token? [#dbd7e97b] *FAQ - Lexical analysis [#k4f3d557] **Can I see a more complete example? [#o5cdb466] **How can I allow keywords as identifiers? [#n777cd1a] **How can I emit an error token upon lexical error? [#e32abb11] **How can I emit more than a single token per lexer rule? [#eafdf499] **How can I make the lexer exit upon first lexical error? [#zd5bc450] **How do I access hidden tokens from parser? [#g94d7060] **How do I combine fuzzy parsing and stream rewriting? [#wb654b09] **How do I fetch tokens on demand not all at once up front? [#fa057070] **How do I get case insensitivity? [#u749917c] **How do I handle abbreviated keywords? [#bcd6c74b] **How do I implement include files? [#mc566574] **How do I match multi-line comments? [#r7f8d718] **How do I selectively ignore tokens depending on parser context? [#nc4d0971] **How do I strip quotes? [#u3c48f61] **How do I use a custom token object? [#u06377d2] **Lexing floating point numbers, dot opertor and range operator [#qede6c33] **What is the intended behavior of the lexer? [#zed1a9d6] *FAQ - Parsing [#r8756d7f] **Why the generated parser code tolerates illegal expression? [#f7aef04a] *FAQ - Runtime libraries [#ee111233] *FAQ - Translation [#ff7e7983] *FAQ - Tree construction [#oc31046e] **Can you explain ANTLR's tree construction facilities? [#t2a7a7ca] **How can I build a different AST node type for each token type? [#a13ff0db] **How can I build parse trees not ASTs? [#aa59485a] **How do I display ASTs graphically [#je7ab3f0] **How do I track whitespace, comments, and other hidden channels during AST construction? [#kdf99171] **What does the error 'cannot find tokenRefBangTrack.st' mean? [#xffffead] *FAQ - Tree Parsing [#yd27090a] **How do I get detailed tree parser error messages? [#aea0df7c] **Tree Parsing in the Eclipse Modeling Framework with Ecore Metamodel [#g7f30f3a] **Why do I get a ClassCastException when parsing a tree? [#v368c4ab] **Why do I get a null pointer exception when I try to reference text attributes in my tree parser? [#i020785b]
spamではない場合はチェックをいれてください。
タイムスタンプを変更しない
[[構文解析の記事一覧]] *趣旨 [#u4d72e52] 以下のページのタイトルだけでも日本語だったらうれしいとおもったから、和訳に挑戦 http://www.antlr.org/wiki/display/ANTLR3/ANTLR+v3+FAQ *目次 [#j89dd342] #contents *言語ごとのAPI資料 [#i58b97e0] **Java API [#l3924bc8] http://www.antlr.org/api/Java/index.html **C API [#r9793ced] http://www.antlr.org/api/C/index.html **Python API [#ub8f87d9] http://www.antlr.org/api/Python/index.html **C# API [#uad56972] リンク切れ **ActionScript API [#y89f68eb] http://www.antlr.org/api/ActionScript/index.html *ダウンロード可能なサンプル [#y6af65a1] 以下のサイトから Examples と書いてある箇所をさがす http://www.antlr.org/download.html *FAQ - アクション[#v4884d08] **バックトラック中のアクション実行について [#fb0b539f] ANTLR must parse ahead to see if something matches. If it fails, then ANTLR tries the next viable alt. Upon failure, it's pretty hard to undo actions in general so ANTLR gates actions out with something like this: if ( backtracking==0 ) { SymbolTable.getPredefinedType("void"), symtab.getDefaultPkg()); } Labels are still defined, because semantic preds might need them: packageDefinition1=packageDefinition(); AST actions are off during backtracking: if ( backtracking==0 ) list_packageDefinition.add(packageDefinition1.tree); Upon success, antlr still rewinds the input and then does the same parse again "with feeling". Clearly you don't want actions executed when that alt ultimately doesn't succeed. Similarly, when the alt does succeed, you do not want actions executed twice. This all makes sense. The problem arises when you want actions to execute during backtracking so that semantic predicates make sense during backtracking. If you are combining backtracking (syntactic predicates) and semantic predicates for tough languages like C++ then you must execute actions during the backtrack but then avoid them during the parse. To be finished when I know how to solve... **パーサのように単語切り出しではなぜ自分のヘッダは表示されないのか? [#bd885005] Actions are specific to one grammar. When using a combined parser/lexer grammar, use // applies only to the parser: @header {package foo;} // applies only to the lexer: @lexer::header {package foo;} not just the @header. When using a separate (non-combined) parser, @header applies to the parser. Likewise, when using a separate (non-combined) lexer, @header applies to the lexer (it is not necessary to use @lexer::header in this case). *コマンドラインオプション [#oc6ff390] **ANTLR はどこにファイルを出力するのか? [#g089524f] Added by Terence Parr, last edited by Terence Parr on Oct 18, 2009 (view change) ANTLR writes files to the current directory by default. But, the output filename is sensitive to the output directory and the directory where the grammar file was found. If you reference a grammar with a (relative or absolute) path, ANTLR will pull the grammar from that directory and write the output to that directory: $ cd ~parrt $ java org.antlr.Tool T.g # write to ~parrt/TParser.java $ java org.antlr.Tool /foo/T.g # write to /foo/TParser.java If you specify an output directory with -o then ANTLR will put the output files in that directory or underneath if you have a relative path on the grammar file: $ java org.antlr.Tool -o /tmp T.g # write to /tmp/TParser.java $ java org.antlr.Tool -o /tmp sub/T.g # write to /tmp/sub/TParser.java The output directory -o value takes precedence over the grammar's path when the output directory is absolute. $ java org.antlr.Tool -o /tmp /usr/lib/T.g # write to /tmp/TParser.java $ java org.antlr.Tool -o ick /usr/lib/T.g # write to ick/TParser.java $ java org.antlr.Tool -o . /usr/lib/T.g # write to TParser.java Use -fo option to force output to go explicitly into a directory, ignoring any path on the input grammar name. $ java org.antlr.Tool -fo /tmp T.g # write to /tmp/TParser.java $ java org.antlr.Tool -fo /tmp sub/T.g # write to /tmp/TParser.java $ java org.antlr.Tool -fo /tmp /usr/lib/T.g # write to /tmp/TParser.java Note: If the outputDir set by -o is not present it will be created. *デバック [#z9788b07] **How do I broadcast debug events to multiple listeners? [#q2666873] **How do I debug a tree grammar using AntlrWorks? [#bba41dd9] **How do I set up remote debugging anyway? [#m82e3b97] **When do I need to use remote debugging? [#dcb2784f] *FAQ - Error handling [#y78c9c70] **How can I print out the text of the line where an error occurs? [#vba5a23f] *FAQ - General [#o3146b26] **How do I make ANTLRWorks and Visual Studio work together? (CSharp as target language) [#h7b40890] **How do I rebuild ANTLR v3? [#t1a7569f] **How do I turn off the warnings that antlr generated classes show? [#qa226a3c] **What is ANTLR? [#u802a2de] **ANTLR v2 と v3ではどこがちがうのか? [#k0b9ae8b] Added by Terence Parr, last edited by Terence Parr on May 05, 2007 (view change) [See also Migrating from ANTLR 2 to ANTLR 3#NewinANTLR3] There are number of things have changed for the better in v3 including: a brand-new very powerful extension to LL(k) called LL(*) an auto backtracking mode partial parsing result memoization to increase the speed of backtracking a really nice AST rewrite rule mechanism integration of the StringTemplate template engine for generating structured text improved error reporting and recovery a truly retargetable code generator that makes it easy to build backends ("targets"); currently we have the following Code Generation Targets: Java, C#, C, Objective-C, Python with others in development BSD license Perhaps most importantly, Jean Bovet built the amazing ANTLRWorks grammar development environment. ***参考ANTLRWorks [#x5cea315] http://www.antlr.org/works/index.html For ANTLR v3 I decided to make the most common tasks easy by default rather. This means that some of the basic objects are heavier weight than some speed demons would like, but they are free to pare it down leaving most programmers the luxury of having it "just work." For example, to read in some input, tweak it, and write it back out preserving whitespace, is easy in v3. ***LL(*) parsing [#j5c59951] ANTLR v3 does not require you to specify a lookahead depth (k option in v2). ANTLR's new LL(*) algorithm allows parser lookahead to roam arbitrarily far ahead looking for a token or sequence that disambiguates a decision. LL(k) can only look a fixed k symbols ahead. It is the difference between using a cyclic DFA and an acyclic DFA to make lookahead decisions. method : type ID '(' arg* ')' ';' | type ID '(' arg* ')' '{' body '}' ; This is not LL(k) for any finite k. From the left edge, lookahead unbounded to see the ';' vs '{'. We need arbitrary lookahead because of the arg*. If you have actions after ID, you can't easily refactor the rule. ANTLR v3 handles is no problem as long as rule arg is not recursive. ANTLR builds a tight little DFA to scan ahead looking for ';' vs '{'. ***Auto-backtracking [#oc815bd7] Sometimes even LL(*) will not be powerful enough to handle a particular decision or multiple decisions within a grammar. Rather than have to add a bunch of syntactic predicates in those decisions as you would in v2, you can turn on the auto backtracking feature (set option backtrack=true). This feature essentially tells ANTLR that if it fails to analyze a decision, simply figure it out at run time by backtracking across the alternatives within that decision. Take the method rule from the previous section. If rule arg is now recursive (as it is in C), ANTLR will fail to build a DFA because DFA have no stacks. A full parser is required to match the argument list. Just turn on the auto backtracking feature and ANTLR will gladly accept just about any non-left-recursive grammar. grammar C; options { backtrack=true; } method : type ID '(' arg* ')' ';' | type ID '(' arg* ')' '{' body '}' ; ***AST rewrite rules [#kbea4417] v3 introduces a really nice way to build ASTs. The following example demonstrates the AST rewrite mechanism. Anything after -> is considered a tree grammar. ANTLR figures out how to map the parser grammar to tree grammar. packageDefinition : 'package' classname ';' -> ^('package' classname) ; This builds a tree with 'package' at the root and classname as its first child. Here's another example: formalArgs : typename declarator (',' typename declarator )* -> ^(ARG typename declarator)+ ; This builds tree sequences like: ^(ARG int v1) ^(ARG int v2) ***StringTemplate integration [#vc64048b] ANTLR v3 tightly integrates the StringTemplate template engine, which is useful for generating any kind of structure text such as source code or XML. In the following grammar, the rule matches a simple assignment statement and implicitly returns a template. The template is an instance of the assign template pulled from a group of templates (set by you in your main()). The arguments to the template are a series of template attribute assignments. This is the interface between the template mechanism and the parser attribute mechanism. assign_statement : ID '=' INT ';' -> assign(x={$ID.text},y={$INT.text}) ; Here's a rule that creates a template called 'import' for each import definition found in the input stream: grammar Java; options { output=template; } ... importDefinition : 'import' identifierStar SEMI -> import(name={$identifierStar.st}, begin={$identifierStar.start}, end={$identifierStar.stop}) ; The attributes are set via assignments in the argument list. The arguments are actions with arbitrary expressions in the target language. The .st label property is the result template from a rule reference. There is a nice shorthand in actions too: -%foo(a={},b={},...) ctor -%({name-expr})(a={},...) indirect template ctor reference -%{string-expr} anonymous template from string expr -%{expr}.y = z; template attribute y of StringTemplate-typed expr to z -%x.y = z; set template attribute y of x (always set never get attr) to z [languages like python without ';' must still use the ';' which the code generator is free to remove during code gen] Same as '(x).setAttribute("y", z);' See Template construction for more information. ***参考 String Template Engine [#fda0fefc] http://www.stringtemplate.org/ ***5分でわかるString Template Engine [#s211241c] http://www.antlr.org/wiki/display/ST/Five+minute+Introduction ***Integrated lexers and parsers [#c2412b18] Lexers are much easier due to the LL(*)algorithm as well. Previously these two lexer rules would cause trouble because ANTLR couldn't distinguish between them with finite lookahead to see the decimal point: INT : ('0'..'9')+ ; FLOAT : INT '.' INT ; The syntax is almost identical for features in common, but you should note that labels are always '=' not ':'. So do id=ID not id:ID. You can do combined lexer/parser grammars again (ala PCCTS) both lexer and parser rules are defined in the same file. See the examples. Really nice. You can reference strings and characters in the grammar and ANTLR will generate the lexer for you. Semantic predicates hoisting Introduced in ANTLR v1, semantic predicates hoisting is back in v3 (it was absent in v2). Attributes The attribute structure has been enhanced. Rules may have multiple return values, for example. Further, there are dynamically scoped attributes whereby a rule may define a value usable by any rule it invokes directly or indirectly w/o having to pass a parameter all the way down. finally block Code in the finally {...} action executes in the finally block (java target) after all other stuff like rule memoization. Example: foo : FOO ; finally { System.out.println("on the way out of foo"); } Source code The ANTLR source code is much prettier and there are about 800 unit tests so far. You'll also note that the run-time classes are conveniently encapsulated in the org.antlr.runtime package. *FAQ - Getting Started [#a0d52fb0] **Building ANTLR Projects with Maven [#m33a9d37] **How do I install this damn thing? [#hda5b545] **How do I use ANTLR v3 from the command line? [#heaf3e8d] **How do I use ANTLR v3 generated Lexer and Parser from Java? [#a8d757a8] **Where do I find this damn thing? [#ucbd9175] *FAQ - Grammar analysis [#o6a33d38] **How to get a list of all valid options for the next token? [#dbd7e97b] *FAQ - Lexical analysis [#k4f3d557] **Can I see a more complete example? [#o5cdb466] **How can I allow keywords as identifiers? [#n777cd1a] **How can I emit an error token upon lexical error? [#e32abb11] **How can I emit more than a single token per lexer rule? [#eafdf499] **How can I make the lexer exit upon first lexical error? [#zd5bc450] **How do I access hidden tokens from parser? [#g94d7060] **How do I combine fuzzy parsing and stream rewriting? [#wb654b09] **How do I fetch tokens on demand not all at once up front? [#fa057070] **How do I get case insensitivity? [#u749917c] **How do I handle abbreviated keywords? [#bcd6c74b] **How do I implement include files? [#mc566574] **How do I match multi-line comments? [#r7f8d718] **How do I selectively ignore tokens depending on parser context? [#nc4d0971] **How do I strip quotes? [#u3c48f61] **How do I use a custom token object? [#u06377d2] **Lexing floating point numbers, dot opertor and range operator [#qede6c33] **What is the intended behavior of the lexer? [#zed1a9d6] *FAQ - Parsing [#r8756d7f] **Why the generated parser code tolerates illegal expression? [#f7aef04a] *FAQ - Runtime libraries [#ee111233] *FAQ - Translation [#ff7e7983] *FAQ - Tree construction [#oc31046e] **Can you explain ANTLR's tree construction facilities? [#t2a7a7ca] **How can I build a different AST node type for each token type? [#a13ff0db] **How can I build parse trees not ASTs? [#aa59485a] **How do I display ASTs graphically [#je7ab3f0] **How do I track whitespace, comments, and other hidden channels during AST construction? [#kdf99171] **What does the error 'cannot find tokenRefBangTrack.st' mean? [#xffffead] *FAQ - Tree Parsing [#yd27090a] **How do I get detailed tree parser error messages? [#aea0df7c] **Tree Parsing in the Eclipse Modeling Framework with Ecore Metamodel [#g7f30f3a] **Why do I get a ClassCastException when parsing a tree? [#v368c4ab] **Why do I get a null pointer exception when I try to reference text attributes in my tree parser? [#i020785b]
テキスト整形のルールを表示する