ANTLR v3 FAQ よくある質問
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
[[構文解析の記事一覧]]
*趣旨 [#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...
if ( backtracking==0 ) {
SymbolTable.getPredefinedType("void"), symtab.getDef...
}
Labels are still defined, because semantic preds might ne...
packageDefinition1=packageDefinition();
AST actions are off during backtracking:
if ( backtracking==0 ) list_packageDefinition.add(packag...
Upon success, antlr still rewinds the input and then does...
Clearly you don't want actions executed when that alt ult...
The problem arises when you want actions to execute durin...
To be finished when I know how to solve...
**パーサのように単語切り出しではなぜ自分のヘッダは表示さ...
Actions are specific to one grammar. When using a combine...
// 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 appl...
*コマンドラインオプション [#oc6ff390]
**ANTLR はどこにファイルを出力するのか? [#g089524f]
Added by Terence Parr, last edited by Terence Parr on Oct...
ANTLR writes files to the current directory by default. B...
ANTLR will pull the grammar from that directory and write...
$ cd ~parrt
$ java org.antlr.Tool T.g # write to ~parrt/TParse...
$ java org.antlr.Tool /foo/T.g # write to /foo/TParser....
If you specify an output directory with -o then ANTLR wil...
$ java org.antlr.Tool -o /tmp T.g # write to /tmp/T...
$ java org.antlr.Tool -o /tmp sub/T.g # write to /tmp/s...
The output directory -o value takes precedence over the g...
$ java org.antlr.Tool -o /tmp /usr/lib/T.g # write to /...
$ java org.antlr.Tool -o ick /usr/lib/T.g # write to i...
$ java org.antlr.Tool -o . /usr/lib/T.g # write to T...
Use -fo option to force output to go explicitly into a di...
$ java org.antlr.Tool -fo /tmp T.g # write to ...
$ java org.antlr.Tool -fo /tmp sub/T.g # write to ...
$ java org.antlr.Tool -fo /tmp /usr/lib/T.g # write to ...
Note: If the outputDir set by -o is not present it will b...
*デバック [#z9788b07]
**How do I broadcast debug events to multiple listeners? ...
**How do I debug a tree grammar using AntlrWorks? [#bba41...
**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...
*FAQ - General [#o3146b26]
**How do I make ANTLRWorks and Visual Studio work togethe...
**How do I rebuild ANTLR v3? [#t1a7569f]
**How do I turn off the warnings that antlr generated cla...
**What is ANTLR? [#u802a2de]
**ANTLR v2 と v3ではどこがちがうのか? [#k0b9ae8b]
Added by Terence Parr, last edited by Terence Parr on May...
[See also Migrating from ANTLR 2 to ANTLR 3#NewinANTLR3]
There are number of things have changed for the better in...
a brand-new very powerful extension to LL(k) called LL(*)
an auto backtracking mode
partial parsing result memoization to increase the speed ...
a really nice AST rewrite rule mechanism
integration of the StringTemplate template engine for gen...
improved error reporting and recovery
a truly retargetable code generator that makes it easy to...
BSD license
Perhaps most importantly, Jean Bovet built the amazing AN...
***参考ANTLRWorks [#x5cea315]
http://www.antlr.org/works/index.html
For ANTLR v3 I decided to make the most common tasks easy...
***LL(*) parsing [#j5c59951]
ANTLR v3 does not require you to specify a lookahead dept...
method : type ID '(' arg* ')' ';'
| type ID '(' arg* ')' '{' body '}'
;
This is not LL(k) for any finite k. From the left edge, l...
***Auto-backtracking [#oc815bd7]
Sometimes even LL(*) will not be powerful enough to handl...
Take the method rule from the previous section. If rule a...
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 follow...
packageDefinition
: 'package' classname ';' -> ^('package' classname)
;
This builds a tree with 'package' at the root and classna...
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 e...
The template is an instance of the assign template pulled...
assign_statement : ID '=' INT ';' -> assign(x={$ID.text}...
Here's a rule that creates a template called 'import' for...
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 li...
-%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-ty...
-%x.y = z; set template attribute y of x (always set neve...
to z [languages like python without ';' must still use the
';' which the code generator is free to remove during cod...
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+Introduc...
***Integrated lexers and parsers [#c2412b18]
Lexers are much easier due to the LL(*)algorithm as well....
INT : ('0'..'9')+ ;
FLOAT : INT '.' INT ;
The syntax is almost identical for features in common, bu...
You can do combined lexer/parser grammars again (ala PCCT...
Semantic predicates hoisting
Introduced in ANTLR v1, semantic predicates hoisting is b...
Attributes
The attribute structure has been enhanced. Rules may have...
finally block
Code in the finally {...} action executes in the finally ...
foo : FOO ;
finally { System.out.println("on the way out of foo")...
Source code
The ANTLR source code is much prettier and there are abou...
You'll also note that the run-time classes are convenient...
*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 J...
**Where do I find this damn thing? [#ucbd9175]
*FAQ - Grammar analysis [#o6a33d38]
**How to get a list of all valid options for the next tok...
*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? [#e32...
**How can I emit more than a single token per lexer rule?...
**How can I make the lexer exit upon first lexical error?...
**How do I access hidden tokens from parser? [#g94d7060]
**How do I combine fuzzy parsing and stream rewriting? [#...
**How do I fetch tokens on demand not all at once up fron...
**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 ...
**How do I strip quotes? [#u3c48f61]
**How do I use a custom token object? [#u06377d2]
**Lexing floating point numbers, dot opertor and range op...
**What is the intended behavior of the lexer? [#zed1a9d6]
*FAQ - Parsing [#r8756d7f]
**Why the generated parser code tolerates illegal express...
*FAQ - Runtime libraries [#ee111233]
*FAQ - Translation [#ff7e7983]
*FAQ - Tree construction [#oc31046e]
**Can you explain ANTLR's tree construction facilities? [...
**How can I build a different AST node type for each toke...
**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 c...
**What does the error 'cannot find tokenRefBangTrack.st' ...
*FAQ - Tree Parsing [#yd27090a]
**How do I get detailed tree parser error messages? [#aea...
**Tree Parsing in the Eclipse Modeling Framework with Eco...
**Why do I get a ClassCastException when parsing a tree? ...
**Why do I get a null pointer exception when I try to ref...
終了行:
[[構文解析の記事一覧]]
*趣旨 [#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...
if ( backtracking==0 ) {
SymbolTable.getPredefinedType("void"), symtab.getDef...
}
Labels are still defined, because semantic preds might ne...
packageDefinition1=packageDefinition();
AST actions are off during backtracking:
if ( backtracking==0 ) list_packageDefinition.add(packag...
Upon success, antlr still rewinds the input and then does...
Clearly you don't want actions executed when that alt ult...
The problem arises when you want actions to execute durin...
To be finished when I know how to solve...
**パーサのように単語切り出しではなぜ自分のヘッダは表示さ...
Actions are specific to one grammar. When using a combine...
// 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 appl...
*コマンドラインオプション [#oc6ff390]
**ANTLR はどこにファイルを出力するのか? [#g089524f]
Added by Terence Parr, last edited by Terence Parr on Oct...
ANTLR writes files to the current directory by default. B...
ANTLR will pull the grammar from that directory and write...
$ cd ~parrt
$ java org.antlr.Tool T.g # write to ~parrt/TParse...
$ java org.antlr.Tool /foo/T.g # write to /foo/TParser....
If you specify an output directory with -o then ANTLR wil...
$ java org.antlr.Tool -o /tmp T.g # write to /tmp/T...
$ java org.antlr.Tool -o /tmp sub/T.g # write to /tmp/s...
The output directory -o value takes precedence over the g...
$ java org.antlr.Tool -o /tmp /usr/lib/T.g # write to /...
$ java org.antlr.Tool -o ick /usr/lib/T.g # write to i...
$ java org.antlr.Tool -o . /usr/lib/T.g # write to T...
Use -fo option to force output to go explicitly into a di...
$ java org.antlr.Tool -fo /tmp T.g # write to ...
$ java org.antlr.Tool -fo /tmp sub/T.g # write to ...
$ java org.antlr.Tool -fo /tmp /usr/lib/T.g # write to ...
Note: If the outputDir set by -o is not present it will b...
*デバック [#z9788b07]
**How do I broadcast debug events to multiple listeners? ...
**How do I debug a tree grammar using AntlrWorks? [#bba41...
**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...
*FAQ - General [#o3146b26]
**How do I make ANTLRWorks and Visual Studio work togethe...
**How do I rebuild ANTLR v3? [#t1a7569f]
**How do I turn off the warnings that antlr generated cla...
**What is ANTLR? [#u802a2de]
**ANTLR v2 と v3ではどこがちがうのか? [#k0b9ae8b]
Added by Terence Parr, last edited by Terence Parr on May...
[See also Migrating from ANTLR 2 to ANTLR 3#NewinANTLR3]
There are number of things have changed for the better in...
a brand-new very powerful extension to LL(k) called LL(*)
an auto backtracking mode
partial parsing result memoization to increase the speed ...
a really nice AST rewrite rule mechanism
integration of the StringTemplate template engine for gen...
improved error reporting and recovery
a truly retargetable code generator that makes it easy to...
BSD license
Perhaps most importantly, Jean Bovet built the amazing AN...
***参考ANTLRWorks [#x5cea315]
http://www.antlr.org/works/index.html
For ANTLR v3 I decided to make the most common tasks easy...
***LL(*) parsing [#j5c59951]
ANTLR v3 does not require you to specify a lookahead dept...
method : type ID '(' arg* ')' ';'
| type ID '(' arg* ')' '{' body '}'
;
This is not LL(k) for any finite k. From the left edge, l...
***Auto-backtracking [#oc815bd7]
Sometimes even LL(*) will not be powerful enough to handl...
Take the method rule from the previous section. If rule a...
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 follow...
packageDefinition
: 'package' classname ';' -> ^('package' classname)
;
This builds a tree with 'package' at the root and classna...
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 e...
The template is an instance of the assign template pulled...
assign_statement : ID '=' INT ';' -> assign(x={$ID.text}...
Here's a rule that creates a template called 'import' for...
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 li...
-%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-ty...
-%x.y = z; set template attribute y of x (always set neve...
to z [languages like python without ';' must still use the
';' which the code generator is free to remove during cod...
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+Introduc...
***Integrated lexers and parsers [#c2412b18]
Lexers are much easier due to the LL(*)algorithm as well....
INT : ('0'..'9')+ ;
FLOAT : INT '.' INT ;
The syntax is almost identical for features in common, bu...
You can do combined lexer/parser grammars again (ala PCCT...
Semantic predicates hoisting
Introduced in ANTLR v1, semantic predicates hoisting is b...
Attributes
The attribute structure has been enhanced. Rules may have...
finally block
Code in the finally {...} action executes in the finally ...
foo : FOO ;
finally { System.out.println("on the way out of foo")...
Source code
The ANTLR source code is much prettier and there are abou...
You'll also note that the run-time classes are convenient...
*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 J...
**Where do I find this damn thing? [#ucbd9175]
*FAQ - Grammar analysis [#o6a33d38]
**How to get a list of all valid options for the next tok...
*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? [#e32...
**How can I emit more than a single token per lexer rule?...
**How can I make the lexer exit upon first lexical error?...
**How do I access hidden tokens from parser? [#g94d7060]
**How do I combine fuzzy parsing and stream rewriting? [#...
**How do I fetch tokens on demand not all at once up fron...
**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 ...
**How do I strip quotes? [#u3c48f61]
**How do I use a custom token object? [#u06377d2]
**Lexing floating point numbers, dot opertor and range op...
**What is the intended behavior of the lexer? [#zed1a9d6]
*FAQ - Parsing [#r8756d7f]
**Why the generated parser code tolerates illegal express...
*FAQ - Runtime libraries [#ee111233]
*FAQ - Translation [#ff7e7983]
*FAQ - Tree construction [#oc31046e]
**Can you explain ANTLR's tree construction facilities? [...
**How can I build a different AST node type for each toke...
**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 c...
**What does the error 'cannot find tokenRefBangTrack.st' ...
*FAQ - Tree Parsing [#yd27090a]
**How do I get detailed tree parser error messages? [#aea...
**Tree Parsing in the Eclipse Modeling Framework with Eco...
**Why do I get a ClassCastException when parsing a tree? ...
**Why do I get a null pointer exception when I try to ref...
ページ名: