By Developers, For Developers
PDF Pg | Paper Pg | Type | Description | Fixed on | Comments |
---|---|---|---|---|---|
viii | TYPO | The following: | 2012-09-29 | ||
6 | ERROR | The command: | 2012-09-29 | ||
256 | TYPO | There should be a space between ‘and’ and ‘Tools’ in: | 2012-10-02 | ||
000 | TYPO | For example, {(}) is ungrammatical because of the token order and (1+2 drives us crazy looking the matching ). Terence Parr. The Definitive ANTLR 4 Reference, B1.0 (Steve Eckhardt) (Kindle Locations 1965-1966). The Pragmatic Bookshelf (374823). | 2012-09-29 | ||
000 | TYPO | Just like writing software, we have to figure out: which rules we need, Terence Parr. The Definitive ANTLR 4 Reference, B1.0 (Steve Eckhardt) (Kindle Location 1987). The Pragmatic Bookshelf (374823). | 2012-09-29 | ||
13 | TYPO | Towards the end of the second paragraph, the sentence is missing couple things: “but it’s helpful have a basic understanding of decision-making so debugging generated parsers is easier.” should be “but it’s helpful to have a basic understanding of the decision-making so debugging generated parsers is easier.” | 2012-09-29 | ||
24 | TYPO | “To learn more about what how the parser recognized the input” has an extra “what” | 2012-09-29 | ||
54 | TYPO | The code listing only has “-> skip” but the paragraph right after the listing mentions “-> channel(HIDDEN)”. | 2012-09-29 | ||
127 | TYPO | The first line in the chapter is missing a “to” in “Now that we know how trigger application code” | 2012-09-29 | ||
91 | OK | The two code listings at the top of the page have their formatting messed up. | 2012-09-29 | Hi Medhat, The format was okay to me. It should be a column of character escapes taken literally from the JSON webpage. | |
166 | TYPO | The first paragraph is missing either “in” or “and” in “If we recover without consuming a token and get back to the same location ?? the parser, we will recover again without consuming a token.” | 2012-09-29 | ||
169 | TYPO | The second paragraph has “everything” repeated twice. | 2012-09-29 | ||
32 | TYPO | The paragraph starting “Once we can translate…” has “the the” towards the end. | 2012-09-29 | ||
156 | TYPO | The last paragraph has “the the” in the middle. | 2012-09-29 | ||
34 | ERROR | In the 3rd complete paragraph, grun is defined on p.6, not p. 23. Suggest deleting “that we defined in Testing the Generated Parser, on page 23” and adding at the end of paragraph 1, p.31, “Make sure you have antlr4 and grun aliases or scripts defined, as explained on pages 5 and 6.” | 2012-09-29 | ||
190 | TYPO | The paragraph starting “The Java language…” has “was was” in it. | 2012-09-29 | ||
5 | ERROR | Hello.g4 WS : [ \\t\ | 2012-09-29 | ||
6 | TYPO | $ grun Hello r -print should be -tree instead of -print | 2012-09-29 | ||
000 | TYPO | Unfortunately, that assumption is too restrictive because R functions and other expressions to span multiple lines. Terence Parr. The Definitive ANTLR 4 Reference, B1.0 (Steve Eckhardt) (Kindle Locations 3473-3474). The Pragmatic Bookshelf (374823). | 2012-09-29 | ||
000 | TYPO | Interface ParseTreeListener is in the ANTLR runtime library and dictates that every listener must know response to events visitTerminal, Terence Parr. The Definitive ANTLR 4 Reference, B1.0 (Steve Eckhardt) (Kindle Locations 3662-3663). The Pragmatic Bookshelf (374823). | 2012-09-29 | ||
000 | TYPO | For example, visitAdd would return the result of adding to subexpressions. Terence Parr. The Definitive ANTLR 4 Reference, B1.0 (Steve Eckhardt) (Kindle Locations 3874-3875). The Pragmatic Bookshelf (374823). | 2012-09-29 | ||
187 | ERROR | Keywords code example doesn’t work. It fails to generate the lexer class. | 2012-11-05 | I have changed the example to be: \nsetType(keywords.get(getText())); \nthanks. | |
192 | ERROR | Missing TestEnum.java in javac command. Also it seems that when actions or predicates are used in a grammar, the parser complains about I’m using patch jar antlr4-complete.jar | 2012-11-05 | very strange about the EOF. We just did a big fix regarding that so hopefully the next beta of v4 ANTLR fixes this. seems okay for me. | |
104 | ERROR | Here is a much better operator precedence table to start with. See the book R in a Nutshell (2nd edition): ( { Function calls and grouping expressions (respectively)
| 2012-11-05 | ||
218 | ERROR | antlr4 unexpected error: attribute references not allowed in lexer actions: $type | 2012-11-05 | ||
218 | ERROR | antlr4 unexpected error: attribute references not allowed in lexer actions: $type grun doesn’t give the parse trees shown on p219. grun doesn’t give the parse trees shown on p219. | 2012-11-05 | Hi Luke, I have updated the Java.g4 to use setType() not $type = ... then everything should work fine. | |
71 | TYPO | In par beginning “Readers familiar with ANTLR v3…”, in the phrase “(It’s also just right recursive because …)”, the word “just” is an extra word. | 2012-11-04 | ||
73 | TYPO | In par beginning “As another example …”, “the same” is duplicated in the phrase “… more | 2012-11-04 | ||
91 | TYPO | The code example problems that Medhat was referring to are the extracts from examples/JSON.g4. In the first, everything following the middle double-quote has a different color and seems to be in italics, "\\\\])* ‘"’ ; In the second, everything after the first double-quote continuing to the end of the extract has the same problem. You can see that the first line has “fragment” in a different color than the next two lines. | 2012-11-04 | ||
75 | TYPO | The example about 3/4 of the way down the page that defines the ESC rule has the same problem that Medhat Assaad and I commented about on p.91. Interestingly, the reformatting seems to not be caused by a double-quote inside single-quotes ‘"’, but only by a double-quote appearing as one of a list of characters. Apparently, this is part of an attempt to pretty-print character strings that goes awry when a single double-quote appears. There may be other places in the book where this happens, but searching for a double-quote turned up too many false-positives and I abandoned the search. | 2012-11-04 | Yeah, not much I can do about that. Apparently the syntax highlighter is already pretty complicated; I don't think the publisher wants to spend the time to fix that. | |
75 | TYPO | The par beginning “Set [btnr”\\\\] matches literally of those character except …" is ungrammatical. Perhaps, “Set [btnr”\\\\] matches EACH of those characterS except …" | 2012-11-05 | ||
85 | TYPO | Top of page, “Rule rowThe is the same …” should be perhaps “The row rule is the same …” | 2012-11-05 | ||
85 | SUGGEST | In par beginning “The token definitions …”, in the sentence “We can use a special escaped \\” in Or just omit the whole sentence since you fully explain how the CSV format handles double-quotes a few sentences later. | 2012-11-05 | ||
85 | ERROR | In the extract from CSV.g4 that defines TEXT and STRING, Any STRING would also match the TEXT rule. Apparently the ambiguity is resolved in favor of STRING, as indicated in the test at the bottom of the page, but this contradicts the only rule that we know for ambiguity resolution at this point, which is that the first rule takes precedence. Later we learn about maximal munch, but that doesn’t explain this behavior either. | 2012-11-05 | Yup. thanks. fixed that \nTEXT : ~[,\\n\\r"]+ ; \n | |
192 | ERROR | On the top of the page it says: | 2012-11-05 | ||
192 | ERROR | On the top of the page it says: | 2012-11-05 | ||
25 | TYPO | In the example where we run Test without a curly brace, the javac ArrayInit*.java Test.java Instead it should read like: | 2012-11-04 | ||
27 | SUGGEST | In the ShortToUnicodeString.java code it would be nice but not necessary to add the @override in front of the enterInit, exitInit, and enterValue methods. This would make it clearer that we are overriding the implemented methods in the ArrayInitBaseListener. | 2012-11-04 | ||
5 | SUGGEST | In page 5 of the book where the antlr4 script is described, it would be nice for the readers of the electronic version of the book to know that you can click on the text with the filename (install/antlr4) to grab the script. I didn’t find out about this useful feature until later reading of the book. | 2012-11-04 | ||
28 | TYPO | In the text: I would change it to the following: This way this stays consistent with the previous examples. | 2012-11-04 | ||
31 | SUGGEST | The link that is on the book for the source code is: http_bypassfilter://pragprog.com/titles/tpantlr2 It would be better if it was: | 2012-11-04 | ||
35 | ERROR | When using the testrig with the -gui option, if you click OK, the window closes down correctly. However when you press the red X on the top right of the window to close the window, the application is still running (disposed of the window, but does not exit). I am running in windows 7 when bringing up the window. | 2012-11-04 | ||
37 | TYPO | After running the ExprJoyRide the output I received was: | 2012-11-04 | ||
- | - | SUGGEST | I strongly suggest you add a section detailing the differences (the ones relevant to this book) between ANTLR 3 and ANTLR 4. ANTLR grammars tend to be quite hard to debug anyway, and not understanding that something one’s doing might just be wrong for version 3, if that’s what one is using, would be extremely frustrating. I’m sure people will be using version 3 for quite some time to come, since it’s likely to be a long time until version 4 appears in systems such as CentOS. | 2012-11-04 | |
53 | SUGGEST | The first sentence in the first paragraph of page 53 reads: The key is the TokenStreamRewriter object that knows how to give altered views of a token stream without actually modifying the stream. New version: The key is that the TokenStreamRewriter object knows how to give altered views of a token stream without actually modifying the stream. | 2012-11-04 | ||
14 | ERROR | The two alternatives of rule ‘stat’ are for an expression or a function call. So the descriptions of the two interpretations should be: f(); as expression f(); as function call or f(); as expression alt f(); as function call alt Rather than: f(): as expr f(); as stat Many thanks; a fine follow-on from “The Definitive ANTLR Reference”. David Turland | 2012-11-04 | ||
27 | TYPO | missing last ‘u’ in first, comment, line in bigpic/ShortToUnicodeString.java / Convert short array inits like {1,2,3} to “\\u0001\\u0002\\0003” */ should be: | | 2012-11-04 | ||
53 | TYPO | Just to anti-errata(?) the errata: The Author is also introducing the TokenStreamRewriter, so the original text is correct, ie: “The key is the TokenStreamRewriter object that knows how to give altered views of a token stream…” hth. | 2012-11-04 | ||
6 | SUGGEST | Tiny detail : the full ls output is : Hello.g4\t\tHelloBaseListener.java\tHelloLexer.tokens\tHelloParser.java | 2012-11-04 | ||
25 | TYPO | Yes, the very last line of the page (re-compiles instead of execute). | 2012-11-04 | ||
36 | ERROR | Not the same output : if $ cat t.expr then the output is : (prog (stat (expr 193) \ To obtain (prog I had to add a blank line at the beginning of t.expr : $ cat myt.expr 193 $ java ExprJoyRide myt.expr | 2012-11-04 | ||
86 | TYPO | Paragrap 4 starting with “The root node”, line 3 : Isn’t it rather with the -gui option ? With | 2012-11-05 | ||
88 | SUGGEST | The link points to the same page. (You’ll surely change it in the final version, sounds funny.) | 2012-11-05 | change to "As described in the sidebar entitled" | |
86 | TYPO | Not the same output. The gui tree, left under file, displays “header” instead of “hdr”, and in the second row, third field, “\\”zippo\\“” instead of “”“zippo”“”. | 2012-11-05 | ||
99 | TYPO | Not the same output. Top of page, graphic tree, right branch under file, should be functionDecl instead of methodDecl. | 2012-11-05 | ||
122 | TYPO | In the middle of the page : If we assume, for the moment, that each parse tree node (each rule context object) has a field called value. Then, exitAdd() would look like this: Expecting a comma after value : … has a field called value, then exitAdd() would look like this: | 2012-11-05 | ||
123 | TYPO | First line. Let’s build another a calculator version … | 2012-11-05 | ||
135 | TYPO | Last paragraph, 3rd line : -> for <- each ??? | 2012-11-05 | ||
140 | TYPO | Paragraph 4 (counting the code snippet), line 2 : I would expect a new sentence starting with F : | 2012-11-05 | ||
141 | TYPO | Second paragraph of text, line 4 : GlobalScope, FunctionScope, and LocalScope Should be FunctionSymbol instead of FunctionScope : public class FunctionSymbol in file code/listeners/FunctionSymbol.java. | 2012-11-05 | ||
148 | TYPO | Bottom, second command (compilation), must be javac S*.java instead of | 2012-11-05 | ||
150 | ERROR | Middle of the page, first execution of grun Simple prog | 2012-11-05 | ||
165 | TYPO | Not same output. Top of page, execution of instead of line 1:9 rule ints: exceeded max 4 | 2012-11-05 | ||
170 | ERROR | Compilation errors. Last code snippet errors/TestBail.java public static class BailELexer extends ELexer { …… must be changed to and the last line javac E*.java TestBail.java …… must be changed to | 2012-11-05 | ||
171 | ERROR | Top of page, list of error messages. As a consequence of replacing E by Simple, the last line of the call stack at EParser.prog(EParser.java:46) ….. becomes | 2012-11-05 | ||
171 | SUGGEST | Please check. I have created a MyErrorStrategy.java file with the code snippet shown public class MyErrorStrategy extends DefaultErrorStrategy { and changed TestBail.java to use it : parser.setErrorHandler(new MyErrorStrategy()); Compiling MyErrorStrategy.java ==> error cannot find symbol BaseRecognizer A Spotlight search found it in antlr-3.2. Replaced by Parser : public class MyErrorStrategy … Compilation OK, test OK. | 2012-11-05 | thanks! added a version that compiles correctly. | |
171 | TYPO | Last paragraph, second line go, we can specify an ANTLRErrorListener as we did in Section 6.2 … Isn’t rather Section 8.2 Altering and redirecting ANTLR Error Messages ? (first occurrence of ANTLRErrorListener) | 2012-11-05 | fixed link | |
178 | TYPO | Last paragraph (before code snippet) : Turning to rule e now, let’s see how what it looks like … what superfluous ??? | 2012-11-05 | ||
198 | TYPO | First paragraph, line 6 : If T it is a type name …….. should be : | 2012-11-05 | ||
201 | TYPO | Second to last line : going solve some very difficult recognition >>> going to solve ??? | 2012-11-05 | ||
215 | SUGGEST | To be perfect, please align the vertical bars in the code snippet. | 2012-11-05 | ||
235 | SUGGEST | Chapter 12 Exploring the runtime API Please check the link at the bottom of the page. Seams 3.4. | 2012-11-05 | when I update the website, that will change :) | |
238 | ERROR | Before section 12.3 : And here’s the build and test sequence: 1) If we compile with javac *.java we have errors : cannot find symbol CSVLexer. … javac Simple*.java 2) Then we have SimpleLexer.java:17: SimpleLexer is not abstract and does not override abstract method getTokenFactory() … Tried with antlr-4.0ea-complete.jar. Pain! Pain! Explosion of errors starting with : SimpleParser.java:14: cannot find symbol 3) Back to 4.0b2. Finally the problem was solved by adding these two lines at the end of SimpleLexer.java : @Override | 2012-11-05 | ||
241 | ERROR | Commands in paragraph 4. Again, as there are more than one example in the same directory, we cannot compile with javac *.java. Instead use : javac MyToken*.java TestSimpleMyToken.java | 2012-11-05 | ||
248 | SUGGEST | Last paragraph starting with unary prefix. I would say there is a discrepancy between the sentence : Any alternative of the form elements expr. and the use of rule expression in the rule expr : expr: … Seems not to be tail recursive. Idem for unary suffix on page 249 | 2012-11-05 | ||
251 | TYPO | Third paragraph of text starting with “The second tree illustrates”, line 3 call to expr[4] matches the 2 and then evaluates {4 >= $4}? As $_p has value 4, it should be {4 >= 4}? (without $), similar to {4>=0}? in the second line of the next paragraph. Idem for “Predicate {3 >= $5}? deactivates” in the next paragraph, line 6, which should read {3 >= 5}?. | 2012-11-05 | wow! good catches. | |
251 | TYPO | Fourth paragraph of text starting with “The third parse tree”, line 4 inside the call to expr[5], The parser >>>>> (not a new sentence) | 2012-11-05 | ||
256 | SUGGEST | Among the commands at the bottom of the page : $ svn add T.g4 Why add to subversion ? —> -bash: svn: command not found. | 2012-11-05 | ||
257 | SUGGEST | Please take note that no error is indicated by ANTLR for @lexer::member {String txt;} (members without s). “String txt;” is just not generated in the lexer and only the compiler complains. | 2012-11-05 | that's a feature unfortunately. code generators for different targets will be able to add whatever named actions they want. I should probably add a table of valid action names per target language. | |
274 | TYPO | Paragraph before the code snippet “reference/Nongreedy.g4” When ANTLR sees an alternatives —> sees alternatives or sees an alternative ??? | 2012-11-05 | ||
275 | SUGGEST | I don’t understand the third paragraph of text : Note that this version is looser due to the wildcard. It allows improperly I see no difference between the 2 grammars, both accept improperly nested actions such as { { } : $ grun Action tokens -tokens $ grun ActionWild tokens -tokens | 2012-11-05 | I have gutted this entire section and rebuilt it. | |
179 | TYPO | In the listing for EContext near the bottom of the page, the 4th component, EContext b, has a comment that refers to “label a” instead of “label b”. | 2012-11-05 | ||
275 | TYPO | Bottom of the page before parser grammar P : A parser grammar cannot reference literal ‘&’, but it can reference the name the tokens | 2012-11-05 | ||
276 | TYPO | Top of the page after the second command antlr4 P.g4 error(126): P.g4:3:4: cannot create …… instead of | 2012-11-05 | ||
170 | TYPO | In listing of errors/BailErrorStrategy.java continued from previous page, the first line of the Javadoc comment: recommend deleting word “wrote” and uncapitalizing “Re-throw” yielding “Instead of recovering from exception e, re-throw it wrapped”. Changes need to be made in both the code and the text, of course. | 2012-11-05 | ||
185 | TYPO | First line : | 2012-11-05 | ||
185 | ERROR | Not the same output. Paragraph 6 : I have $ grun CSV file users.csv instead of : $ grun CSV file users.csv To remove empty values after processing hdr, we can change the @after action to : if ($values != null && ! $values.isEmpty()) System.out.println(“values = ” + $values); | 2012-11-05 | ||
185 | TYPO | First paragraph of § 9.3, line 3 : run to run). This not as unusual as this sounds. I’m not Anglophone, but I would rather expect : This is not as unusual as it sounds. | 2012-11-05 | ||
188 | ERROR | Not the same output. I hate to bother you, but I’m eagle-eyed. Top of page, first line of output : line 1:3 extraneous input ‘=’ expecting INT I have : line 1:3 extraneous input ‘=’ expecting {CHAR, INT} | 2012-11-05 | ||
193 | SUGGEST | Top of page. $ java TestEnum -java5 Adding EOF to prog removes that ‘ prog: ( stat $ antlr4 -no-listener Enum.g4 | 2012-11-05 | this also works for me now in v4. We took an implicit EOF out of the grammar in this last version so I think we're okay. | |
194 | TYPO | Second paragraph of text ending with : token. (More on this inThe reference chapter: Section 14.5, Semantic Predi- cates, on page 278.) | 2012-11-05 | ||
194 | ERROR | Bottom of the page. Oops ! Forgot to compile TestEnum2.java ➾ $ javac Enum2*.java . . . . . . . . . . . . . . . . .instead of | 2012-11-05 | ||
195 | ERROR | Sorry, sorry, not the same output. Top of the page : $ java TestEnum2 instead of $ java TestEnum2 It is as if it has resynchronized on ID HOT, skipping the {. Is it the case, as explained at the bottom of page 156 ? “Here is how ANTLR uses those ideas together in a nutshell: parsers perform single-token insertion and single-token deletion upon mismatched token errors if possible. If not, parsers gobble up tokens until they find a token that could reasonably follow the current rule and then return, continuing as if nothing had happened.” | 2012-11-05 | I'm not sure about the difference here. When I step through the code, I see the missing { error message hushed because it did not properly resynchronize yet. I just checked on my os x box and I get the output in the book. | |
195 | SUGGEST | Middle of the page. ID : [a-zA-Z]+ {if (java5 && getText().equals(“enum”)) setType(ENUM);} ; Enum2Lexer.java:78: cannot find symbol Solution : tokens {ENUM} . . . . . . at the top of the grammar, and ENUM qualified by the name of the parser : | 2012-11-05 | ||
196 | SUGGEST | Link in the middle of the page. Same remark as page 88 : Language Ambiguities are Bad, Umkay, on page 196.) . . . . >>>> | 2012-11-05 | ||
199 | TYPO | Last sentence : The following parse trees (created using grun-ps option) See also page 86. On Mountain Lion, the command $ grun PredCppStat stat -ps xx displays an icon in the dock, the same cup of coffee as antlrworks2, which disappears after two seconds. To obtain a visible, stable parse tree, I have to use the -gui option : $ grun PredCppStat stat -gui | 2012-11-05 | ||
210 | TYPO | Last line. The command must be | 2012-11-05 | ||
22 | SUGGEST | Lack of definition of the token type. I have a grammar that recognizes statements written in capitals. I try to adapt it to recognize lower-case letters, as a modern compiler can do. So the grammar must be case insensitive. A statement looked like this : statement I have experimented all sorts of transformations, such as : statement ID : [a-zA-Z]+ {setText(getText().toUpperCase());} line 4:9 no viable alternative at input ‘PUT SKIP’ It would be good to reproduce part of the section 2.6 of the previous book (starting at page 27, PDF P4.0 page 44) : It would also be good to emphasize that a parser rule containing ‘token’ strings as in stat: ‘while’ ‘(’ expr ‘)’ stat creates hidden tokens (I suppose), as if we had explicit lexer rules : IF : ‘if’ ; and, most important, these rules have precedence over the ID rule which is usually near the end of the grammar. (The order is mentioned once on page 194 for explicit lexer rule : ENUM: ‘enum’ {java5}? ; // must be before ID). And also that the parser matches by token type, not string content … Well, I should know that, I have written a PL/I parser by hand. But it was five years ago. | 2012-11-04 | thanks. added a bunch of that content into the big picture chapter. | |
218 | TYPO | Top of page. The first command antlr4 SimplyPy.g4 . . . . . must be | 2012-11-05 | ||
218 | ERROR | Not the same output. [ I did some research : @lexer::members { LPAREN : ‘(’ {nesting; System.out.println(“nesting now ” + nesting);} ; RPAREN : ‘)’ {nesting—; System.out.println(“nesting now ” + nesting);} ; IGNORE_NEWLINE NEWLINE i nesting=0 There are still two extra \ | 2012-11-05 | I had the wrong output. The correct output is:
\n
\n[@0,8:8='\\n',<11>,1:8]
\n[@1,9:9='f',<4>,2:0]
\n[@2,10:10='(',<6>,2:1]
\n[@3,11:11='1',<5>,2:2]
\n[@4,12:12=',',<1>,2:3]
\n[@5,29:29='2',<5>,4:2]
\n[@6,30:30=',',<1>,4:3]
\n[@7,80:80='3',<5>,6:2]
\n[@8,81:81=')',<7>,6:3]
\n[@9,94:94='\\n',<11>,6:16]
\n[@10,95:95='\\n',<11>,7:0]
\n[@11,96:96='g',<4>,8:0]
\n[@12,97:97='(',<6>,8:1]
\n[@13,98:98=')',<7>,8:2]
\n[@14,108:108='\\n',<11>,8:12]
\n[@15,109:109='\\n',<11>,9:0]
\n[@16,110:110='1',<5>,10:0]
\n[@17,111:111='+',<2>,10:1]
\n[@18,114:114='2',<5>,11:0]
\n[@19,115:115='+',<2>,11:1]
\n[@20,118:118='3',<5>,12:0]
\n[@21,119:119='\\n',<11>,12:1]
\n[@22,120:119=' | |
72 | SUGGEST | During the first reading, I had noted things to revisit. If you put this piece of code directly into a grammar : grammar Decl; and execute it with an input file t.decl containing *(*a)[][] (only one line, no newline), then : $ grun Decl decl t.decl A look in DeclParser.java shows the argument : public final DeclContext decl(int _p) throws RecognitionException { Introducing a start rule solves the problem : grammar Decl; Now the parser : public final StartContext start() throws RecognitionException { Re-reading § 13.2 makes it clear, the parameter _p is added by the transformation : $ antlr4 -Xlog Decl.g4 It also shows that there is already a loop to process the multiple []. I had tried with : decl which ended up with : Exception in thread “main” java.lang.reflect.InvocationTargetException | 2012-11-04 | ||
198 | SUGGEST | How to interpret the diagnostics message ? Given a simple input : DECLARE MONTHS (12) CHAR (9) INIT (‘January’, ‘February’, …); the -gui option (a very powerful tool, indeed) shows that it is correctly parsed. But the -diagnostics option displays various messages : line 2:45 reportAttemptingFullContext d=123, input=‘’January’,’ On contrary to the example given on this page, the alternative chosen by the parser is not displayed. Is it an indication that something is wrong in the grammar ? | 2012-11-05 | Hi. not sure where that input comes from, but I have added a paragraph describing what the attempting full context message means. | |
198 | SUGGEST | Solved. Found an ambiguity with STRING, keyword of the statement PUT STRING (= C sprint()) and the usual STRING : factor keywordOrID keywords DECLARE SEPARATOR CHAR (10) INIT (‘==’); -> initial attribute statementNames statementKeywords | 2012-11-05 | ||
73 | SUGGEST | Renaming a parser rule from keywordOrID to IDorKeyword, because it sounds better, can have quite brutal effects : $ antlr4 Pl1.g4 Forewarned is forearmed. | 2012-11-04 | ||
227 | SUGGEST | Paragraph after the code snippet lexmagic/XMLLexer.g4, line 4. Please note a tiny discrepancy between : notation declarations of the form: < and the fact that the second exclamation point does not appear neither in the comment nor in the DTD rule. / Scarf all DTD stuff, Entity Declarations like <!ENTITY …>, | 2012-11-05 | ||
230 | SUGGEST | Command above the graphic : $ grun XML document -ps /tmp/t.ps XML-inputs/entity.xml As already noted on pages 86 and 199, you probably use the -ps option to produce the file that will create, with some other tool, the graphic incorporated into the PDF. For us reader wanting to see the output of the command as in the book, we need the -gui option : grun XML document -gui XML-inputs/entity.xml | 2012-11-05 | ||
230 | SUGGEST | Also note that, in order to obtain the same output, the reader must edit the file and remove the copyright notice. ! Excerpted from “The Definitive ANTLR 4 Reference”, It would be good not to insert the copyright notice in data files serving as input to run the examples, as it already happens for some of them (e.g. in examples). | 2012-11-05 | yeah, this is a hassle; made a note in the preface. The publisher can't change the way they zip things up. | |
183 | TYPO | 3rd Par beginning “Let’s break that …”, next to last line has “Java Stringsplit()” with missing period. Should be “Java String.split”. | 2012-11-05 | ||
268 | TYPO | Paragraph 7 : $r and $rl evaluate to ParserRuleContext objects of type RRuleContext for rule name r and rule label rl. $rll evaluates to List Considering that (from CSV.g4) file generates \tpublic static class FileContext extends ParserRuleContext If italic R stands for the rule name, RContext is better than RRuleContext, hence : $r and $rl evaluate to ParserRuleContext objects of type RContext for rule name r and rule label rl. $rll evaluates to List | 2012-11-05 | ||
22 | SUGGEST | Well, concerning “parser rule containing ‘token’ strings” I must have missed section 4.5 page 73 third paragraph from bottom : For keywords, operators, and punctuation, we don’t need lexer rules because we can directly reference them in parser rules in single quotes like ‘while’, ‘*’, and ‘’. | 2012-11-04 | ||
73 | SUGGEST | Third paragraph from bottom : For keywords, operators, and punctuation … in single quotes like ‘while’, ‘*’, Did I miss something ? Or it should be emphasized that such a standalone token must not appear in another token rule. Given the input file ri.java : $ cat ri.java public interface RenameListener extends ParseTreeListener the following grammar does not work because the dot in RenameListenerParser.StmtContext (line 5) is not matched by the one in SPECIAL (type=6) of rule rest, but by the ‘.’ (type=2) appearing first in rule xpackage. grammar ExtractImport; file : line* EOF ; line: ‘import’ xpackage ‘;’ NL xpackage : ID ( ‘.’ ( ID | ’’ ) ) ; rest : ( ID | SPECIAL | TAB)+ ; ID : LETTER ( LETTER | DIGIT | ‘_’ )* ; fragment LETTER : [a-zA-Z] ; SPECIAL : ( ‘(’ | ‘)’ | ‘-’ | ‘_’ | ‘.’ | ‘>’ | ‘<’ | ‘{’ | ‘}’)+ ; NL : ‘\\r’? ‘\ == $ grun ExtractImport file -tokens ri.java == With : xpackage : ID ( DOT ( ID | ‘’ ) ) ; DOT has type=6 and the dot in RenameListenerParser.StmtContext is matched by SPECIAL (type=5). [ So the rule rest matches the line. OK, but now : line 1:10 mismatched input ‘.’ expecting {’;‘, ’.‘} The dot in the import statement is captured by SPECIAL (type=5), and the rule xpackage, which needs a DOT of type 6 no longer matches : [ === The solution is to have the dot in the form of a standalone token ‘.’ or as a DOT lexer rule, repeated if necessary as in rest, but never embedded in another token rule : xpackage : ID ( ‘.’ ( ID | ‘’ ) ) ; | 2012-11-04 | That's correct. '.' in the parser is not matching a character, which is also matched in your SPECIAL rule. it's matching a token type. | |
291 | SUGGEST | Bottom, Keywords. It seems that Java does not like if a rule is named package : line: ‘import’ package ‘;’ NL package : ID ( DOT ( ID | ’’ ) ) ; (same grammar as my post page 73) $ antlr4 ExtractImport.g4 | 2012-11-05 | rules and tokens should not be valid keywords in the target language I'm afraid because the generated code will freak the compiler out. | |
249 | TYPO | First complete par beginning “unary suffix” also refers to rule “expression” but should be “expr”. | 2012-11-05 | ||
291 | SUGGEST | As well as any other Java reserved word … stat : ( classDef | methodDef | if | unless | ‘begin’ ) if : ‘if’ expr ( ‘then’ | ‘:’ ) statement ( ‘else’ statement )? ===> extract_listenerParser.java:344: | 2012-11-05 | ||
85 | SUGGEST | George, it has been a mystery for me too. Now I think I have understood. If you change the field rule to : field you get : Mid Bonus is a TEXT as you guessed from the token type <4>. Now change data.csv to put a dot instead of the comma in the amount field : Mid Bonus,June,“$2.000” and run again : Mid Bonus is a TEXT I would add, in page 15, that ambiguity is resolved in favour of the first rule as long as the input flow satisfies both rules until the right edge of the lexer rule / implicit token, as in the case of ‘begin’/ID with a `begin`input, or TEXT/STRING with a `“$2.000”` (with a dot) input. In the case of `“$2,000”` with a comma, the input is ambiguous only in the first three characters `"$2`, the lexer has the choice. Then comes the comma and the TEXT rule is out because it negates the comma. The only remaining choice is STRING, which is greedy at this position and loops until the next quote. | 2012-11-10 | ||
187 | SUGGEST | I suggest to add a section regarding large grammars (many keywords and many parser rules) and suggestions on how to create it to avoid exceeding the method limit size in java. The following sections describe some approaches, but there might be other approaches not listed. The approaches should have a note stating whether they result in smaller code (to not exceed the java limit) or they improve readability or both. | 2012-12-02 | Hi. We will be fixing the code generator so that it does something more reasonable. | |
0 | ERROR | The grammar for Java 6 provided with the book’s example programs, tour/java.g4, incorrectly lists the ^ operator as being right-associative. In Java ^ is a bitwise and logical operator, not an exponent operator. The Java 7 Language Reference says on page 518 (or see docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.22), speaking of the bitwise and logical operators &, , and |, “Each of these operators is syntactically left-associative (each groups left-to-right)”. (The java.g4 file correctly makes the= assignment operator right-associative.) | 2012-12-02 | whooops! thanks. | |
110 | SUGGEST | It doesn’t concern this page, but code/extras/CPPBaseLexer.g4 $ antlr4 CPPBaseLexer.g4 I couldn’t get rid of that error, even after adding a ? after ~[\\r\ OTHER_CMD : ‘#’ ~[\\r\ | 2012-12-02 | Hi. The issue was in: \n \nSTRING : '"' .*? '"' ; \n \nI added that ? there. | |
26 | ERROR | The command “javac *.java” cannot work as is, without specifying a CLASSPATH for the ANTLR jar file. | 2012-12-02 | I added something to remind users to set their class path. | |
80 | TYPO | Extremely minor typo: At the bottom of the page, the “fragment ESC” the “]” in <[btrn“\\\\]> is italicized, when it shouldn’t be. Ditto for the following ”;" Also, the comment (“// \\b, |t, \ See, I told you it was extremely minor. | 2012-12-02 | unfortunately that is an error in the syntax highlighter that is very difficult to correct so we decided to leave it. | |
1 | ERROR | Sorry for posting this here, rather than some other place. The only other I found was on groups.google.com that required me to register, which I didn’t want to do. So here it is. Ignore the “PDF Page # 1” I had to put in. Putting “options { language = CSharp2; }” into a .g4 file, and using 4.0b3, blows up on a NullPointerException. The traceback is as follows… error(31): ANTLR cannot generate CSharp2 code as of version 4.0b3 | 2012-12-02 | Thanks. latest code does this: \nerror(31): ANTLR cannot generate CSharp2 code as of version 4.0b4 \n | |
25 | TYPO | “At this point, we’re just trying to get the gist of the development process… ” should be “At this point, we’re just trying to get the list of the development process…” | 2012-12-02 | actually gist is correct :) | |
80 | SUGGEST | It seems that all texts, brackets, braces, colons, semi-colons, \ page 6 : r : ‘hello’ ID ; I stop the inventory on page 67 because there are too many. Also outside grammars as on page 71 : | 2012-12-02 | Hi. yes, the publisher has set things up that way. syntax highlighting inside code fragments appears differently than snippets inside text. | |
24 | SUGGEST | § 3.1 second paragraph “The first step”, second line : compares the input against a language’s syntactic rules. Not sure about a — > rule_S_ ] Could be : compares the input against a SET OF language’s syntactic rules. | 2012-12-07 | ||
xvi | SUGGEST | second line : of you reading this electronically, you can click on the gray box Hmm, it’s gray in the printed book, lime green in the PDF. | 2012-12-06 | ||
6 | SUGGEST | Middle of the page, paragraph Running the ANTLR tool on Hello.g4 generates an executable recognizer embodied by HelloParser.java and HelloLexer, To be coherent —> and HelloLexer.java | 2012-12-07 | ||
7 | SUGGEST | First line
“had rule r” sounds strange | 2012-12-07 | ||
8 | TYPO | First line : missing (s) in [input-filename] $ grun | 2012-12-07 | ||
25 | SUGGEST | In the directory code/starter there is a file build.properties that may have been dropped accidentally here. | 2012-12-07 | ||
36 | SUGGEST | Line 4 The “and” disturbs me in natives on lines 11 and 12 that recursively invoke expr and on the left edge. I would expect either of recursively invoke expr on the left edge. By the way, what is an edge ? First occurrence here, next (right edge) on page 41, then can be deduced from the explanation on page 73, first paragraph. | 2012-12-07 | ||
39 | SUGGEST | Middle of the page : javac *.java For people working directly in the tour directory, this will compile everything (all other examples). It would be preferable to compile only LibExpr : javac LibExpr*.java | 2012-12-07 | ||
29 | ERROR | Second execution of java Test, not the same output. I have double-checked that I have the latest version, downloaded from Github on Monday 3 December and rebuilt. $ alias $ antlr4 ArrayInit.g4 | 2012-12-07 | ||
39 | ERROR | Bottom, not the same output. $ antlr4 Expr.g4 | 2012-12-07 | ||
35 | SUGGEST | Small difference between the file code/tour/Expr.g4 and the book : ID : [a-zA-Z]+ ; // match identifiers | 2012-12-07 | ||
37 | SUGGEST | Near bottom. Small difference between the file code/tour/ExprJoyRide.java and the book : ParseTree tree = parser.prog(); // parse; start at prog ParseTree tree = parser.prog(); // parse; start at prog | 2012-12-07 | Those are for book build system and removed. | |
51 | TYPO | Third paragraph from bottom. Visually, the internal grammar representation of rule group <—— Isn’t it rather rule sequence ? Also in the picture. | 2012-12-07 | ||
34 | SUGGEST | End of third paragraph : For example, we might want to turn the enum keyword on and off in a Java grammar to parse different versions of the language. This may not be noticed by most readers, but the beginning of this chapter | 2012-12-07 | ||
53 | TYPO | File code/tour/XML.g4 contains : lexer grammar XMLLexer; Hence : $ antlr4 XML.g4 Should be lexer grammar XML; | 2012-12-07 | ||
65 | SUGGEST | First line : sequence with Terminator and sequence with separator. Is there a reason for capital T (erminator) and not S (eparator) ? | 2012-12-07 | ||
82 | SUGGEST | Third line from bottom : STRING: ‘"’ .* ‘"’ ; Shouldn’t it be STRING: ‘"’ .*? ‘"’ ; to avoid the warning warning(131): Log.g4:6:13: greedy block ()* contains wildcard; the non-greedy syntax ()*? may be preferred | 2012-12-07 | ||
83 | SUGGEST | Also in gramar snippet STRING: ‘"’ .* ‘"’ ; | 2012-12-07 | ||
110 | SUGGEST | Chapter 6 finished without using code/examples/Hello.g4 (already used in code/install). | 2012-12-07 | ||
133 | SUGGEST | Third line, what is this comment after ?
In the beginning of file code/listeners/JSON2XML.java :
and the execution shows nothing : $ java JSON2XML t.json | 2012-12-07 | ||
168 | SUGGEST | Bottom after the grammar snippet : Given one too many integers, as in the following session, we see an error message and get error recovery that throws out the extra comma and integer. Is one correct ? (there are two integers and one comma too many). At the end of the sentence —-> integers in plural ? | 2012-12-07 | ||
169 | SUGGEST | End of second to last paragraph “A word of caution” : it’s not a good idea use a semantic predicate. My English may be old fashioned, but I would say “to use …” it’s not a good idea TO use a semantic predicate. | 2012-12-07 | ||
176 | SUGGEST | Have finished chapter 9 without using code/errors/Enum.g4 (which will be used in chapter 11 and can be found in code/predicates). | 2012-12-07 | ||
190 | SUGGEST | Finished chapter 10 without using code/action/TestFuzzyJava.java. | 2012-12-07 | ||
192 | SUGGEST | Middle of the page : enum Temp { HOT, COLD } . . . . . . . . . // in file Temp.java There is no such file in code/predicates. | 2012-12-07 | ||
193 | ERROR | Middle of the page, first enumDecl There is no name=, hence {System.out.println(“enum ”+$name.text);} would fail. | 2012-12-07 | ||
197 | TYPO | Paragraph 4, truncated sentence : In this case, ANTLR’s error recovery realizes it doesn’t have a valid assignment and scarfs tokens until it finds something that can | 2012-12-07 | ||
202 | SUGGEST | Messages have disappeared. It works in 4.0b3 : $ alias I have just downloaded and rebuilt, copied dist/antlr-4.0b4-complete.jar to /usr/local/lib, renamed to antlr-4.0b4-5dec-complete.jar : $ echo $CLASSPATH | 2012-12-07 | good catch | |
214 | ERROR | First execution of grun Java tokens -tokens. Using code/tour/Java.g4, I have more tokens (spaces) than in the book : [ | 2012-12-07 | ||
220 | ERROR | The graphic at the bottom is not up-to-date, there are now two more stat — \ | 2012-12-07 | ||
221 | SUGGEST | Second line : The other three newlines terminate statements. should be adapted : 3 NL terminate expr, and 2 additional NL are empty lines. | 2012-12-07 | ||
240 | ERROR | The TestSimple runs in 4.0b3, but no longer with the latest release : $ alias | 2012-12-07 | We changed factory but works for me... | |
248 | TYPO | Orphaned closing parenthesis at the end of the first sentence : These unbuffered streams are useful when efficiency is the top concern. You can even combine them with the technique from the previous section). | 2012-12-07 | ||
251 | SUGGEST | End of second paragraph “Any other alternative” : ANTLR collects them and deals with them properly. The sentence Assume sounds strange, suspended without link. properly and assumes ? or Let’s assume? | 2012-12-07 | ||
260 | SUGGEST | I have an EOF in the message : line 3:0 extraneous input ‘;’ expecting { instead of line 3:0 extraneous input ‘;’ expecting {INT, ID} | 2012-12-07 | should be
\n
\nline 3:0 extraneous input ';' expecting { | |
260 | SUGGEST | Bottom, just to keep the same rhythm and music : Parsers can import parsers. should be Parser grammars can import parsers. or even (more verbose but more accurate, closer to “Not every kind of grammar can import every other kind of grammar:”) • Lexer grammars can import lexer grammars. | 2012-12-07 | ||
262 | SUGGEST | After the grammar reference/foo/Count.g4 The grammar itself then should be then sounds superfluous. | 2012-12-07 | ||
263 | TYPO | Last line : public interface AListener extends ParseTreeListener { does not correspond to grammar T. In b2 it was T : public interface TListener extends ParseTreeListener | 2012-12-07 | ||
263 | SUGGEST | EDIT There is a file reference/A.g4 which corresponds to grammar T in the book. So just change grammar T to grammar A | 2012-12-07 | ||
264 | SUGGEST | Bottom. But A.g4 is correct and does not produce these errors : $ antlr4 A.g4 I suggest file AE.g4 grammar AE; $ antlr4 AE.g4 | 2012-12-07 | i renamed as Conflict.g4 | |
265 | TYPO | Paragraph 5 : ANTLR also provide —-> provides ??? [ Incredible, a few of these typos were already in previous release(s) :) Nobody’s perfect.] | 2012-12-07 | ||
268 | TYPO | Middle of the page : You can suffix the ?, , and + subrule operators with the nongreedy operator, which is also a question mark: ??, ?, and +?. Should be ? instead of ?. | 2012-12-07 | man, you are good! | |
270 | SUGGEST | Explanation of FailedPredicateException : after reading several times, I understand that “This predicate” refers to FailedPredicateException, not NoViableAltException. Confusing because This usually refers to the closest thing talked about. Suggestion : replace “This predicate” by its name FailedPredicateException. | 2012-12-07 | ||
283 | SUGGEST | Middle of the page : more Match this rule but continue looking for a token. The text for the token that matches next <——- I suppose it refers to nextToken(). The whole sentence is difficult to understand. | 2012-12-07 | ||
287 | ERROR | The message now displays a \ $ grun Actions tokens -tokens $ grun Actions tokens -tokens | 2012-12-07 | ||
190 | SUGGEST | Note : FuzzyJava is demonstrated in § 15.6. | 2012-12-07 | ||
294 | ERROR | There is no Hi.g4 in code/reference. Created. | 2012-12-07 | ||
294 | SUGGEST | Middle of the page : superClass Set the superclass of the generated parser or lexer <———- But the lexer does not seam affected : $ antlr4 -DsuperClass=XX Hi.g4 | 2012-12-07 | ||
295 | SUGGEST | To test tokenVocab, I had to create a file code/reference/SomeLexer.g4 and a R.g4 to test instead of P.g4 which already exists and is different. | 2012-12-07 | ||
248 | SUGGEST | Chapter 13 finished without using code/api/L.g4 and P.g4. | 2012-12-07 | ||
234 | SUGGEST | Chapter 12 finished apparently without using code/lexmagic/JavaLiterals.tokens, T.java and Tf.java. | 2012-12-07 | ||
204 | SUGGEST | Chapter 11 finished apparently without using code/predicates/CDecl.g4 and CExpr.g4. | 2012-12-07 | ||
33 | SUGGEST | EDIT page 34 Please ignore next comment on page 34, it’s OK like this (semantic predicate used to make part of the grammar disappear). | 2012-12-07 | ||
295 | SUGGEST | Well, T2.g4 does not exist either, but the reader can create it. | 2012-12-07 | ||
15 | TYPO | The parser does detects an ambiguous phrase —> | 2012-12-12 | ||
29 | TYPO | our next goal is to translate not just recognize initializers —> or | 2012-12-12 | Actually, I think that a comma is not warranted unless there is a subject they are, just like after "but". | |
33 | TYPO | For those with experience using a previous versions of ANTLR —> | 2012-12-12 | ||
38 | TYPO | replace the lexical rules from original grammar —> | 2012-12-12 | ||
60 | TYPO | grammar rules comprised of —> | 2012-12-12 | ||
83 | TYPO | First line includes “we can make parser rules that matches the | 2012-12-12 | ||
119 | SUGGEST | The token definitions for Expr.g4 should be included in what is printed in the book because ExprParser.MULT is used in the following code snippet of TestEvaluater.java. In that case, it would also make sense to use MULT and ADD in the grammar rules, for consistency. | 2012-12-12 | altered as suggested. | |
113 | SUGGEST | Maybe use ‘and override’ rather than ‘and implement’ here: “The process is simply to extend the parser class generated And similarly here: /DT/ | 2012-12-12 | ||
47 | ERROR | A line of Java code “tokens.getText(ctx.type());”… there does not appear to be a TokenStream.getText(Token) method in the current version of v4. | 2014-09-06 | Does it compile? TypeContext is the type not Token | |
137 | TYPO | Missing the word “to” in “Finally, we need annotate the root of the parse tree” | 2014-09-06 | ||
36 | SUGGEST | You run TestRig with an input file (not the keyboard) for the first time on this page. You might want to mention that the input goes in t.expr. | 2014-09-06 | actually 2 pages earlier is but i added to parse input file | |
159 | TYPO | Change “in” to “and” in “counting from 0 in treating tabs as one character” | 2014-09-06 | ||
117 | TYPO | This page has the wrong code fragment below the sentence “As a convenience, ANTLR also generates class PropertyFileBaseListener …”. It appears to be a copy-and-paste from 7.3. | 2014-09-06 | ||
68 | TYPO | In the 3rd example the comments suggest some matches that do not match the “expr” definition given here, or you would have to assume that 2*b is a valid ID. expr: ID ‘[’ expr ‘]’ // a[1], a[b[1]], a[(2*b[1])] | 2014-09-06 | ||
34 | SUGGEST | “OK. Let’s take grammar Expr out for a joy ride. Download it […]” It’s a book with paper, not pdf nor epub! | 2014-09-06 | right before it says: \n"You can also grab the full source code bundle on the book’s website.[3]" | |
79 | 64 | TYPO | There is an error with the rule at the end of the page: In the comment beside the rule it is described as recognizing [1] or [1 2] or [1 2 3], and so on. But the space between the numbers is not included in the rule. | 2014-09-06 | spaces matched by lexer not parser. |
92 | ERROR | The first clause for NUMBER in the JSON grammar seems to have an error because it does not allow a zero directly after the point as in the following number | 2014-09-06 | ||
60 | TYPO | In the Java pseudo-grammar here is typo in this code: The ‘super’ keyword is not allowed to use in this context, there is should be ‘extends’ keyword instead. The following is correct one: | 2014-09-06 | ||
206 | SUGGEST | Input “exmagic/t.cym” doesn’t have syntax highlighting, whereas the output has it. Not exactly dramatic, but this inconsistency looks a bit weird. | 2014-09-06 | ||
134 | SUGGEST | There is a reference to JSON2XML_ST.java source which uses StringTemplate for XML translation. But in the source code itself there is reference to the XML.stg file which absent in the book source archive. JSON2XML_ST.java (line 45): It would be nice if you put it to archive, since (IMHO) it’s not very easy to find it elsewhere. | 2014-09-06 | ||
21 | TYPO | The footnote contains a broken link. Searching mefeedia.com for “terence parr” or “jvm” both find nothing. | 2014-09-06 | Sorry about that. it died. try http://parrt.cs.usfca.edu/doc/impl-parsers-in-java.pdf | |
30 | ERROR | Running Translate on {99, 3, 451} as shown in the book works slick. But try {{1}} and Translate blows up with a NullPointerException in ShortToUnicodeString.enterValue. I’m guessing this is because the value in this case is not an integer but is a sublist {1}. | 2014-09-06 | Code says: \n// Assumes no nested array initializers | |
6-7 | ERROR | After creating the Hello.g4 sample grammar, then generating and compiling the Java, running grun leads to an error on Windows: “Can’t load Hello as lexer or parser” In addition, running grun with no parameters, does more than what you say in the book: It prints the usage messages and a NullPointerException stack trace TestRig.main -> Here are the files in the local directory: Hello.g4 Here is the Hello.g4 file: grammar hello;\t// define a grammar called Hello I’m running on Windows 7 Ultimate x86, 4GB RAM, 8 cores. | 2014-09-06 | add '.' to your classpath. Book says "It’s critical to have the dot, the current directory identifier, somewhere in the CLASSPATH." | |
65 | TYPO | expr: ID ‘(’ exprList? ‘)’ // use token ID and not rule expr to build a function call | 2014-09-06 | ||
61 | TYPO | Both stat examples are missing ‘while’ ‘(’ expr ‘)’ in the second choice. | 2014-09-06 | i have no idea where you are looking. sorry. oh page 66 not 61? still don't know what you mean. | |
113 | ERROR | The text discusses the class PropertyFileBaseListener but instead of presenting the code for PropertyFileBaseListener, the code of the class PropertyFileBaseVisitor is presented. | 2014-09-06 | ||
92 | ERROR | Number in JSON.g4 grammar is defined wrongly. First alternative is wrong. It doesn’t accept floating point numbers that contain zero after period char. For e.g. number: 1.01 would be parsed as two number tokens: 1.0 and 1. It’s very easy to verify this running grun JSON value -tokens. | 2014-09-06 | ||
90 | TYPO | The parse tree diagram for JSON should have “pair” nodes instead of “element” nodes. | 2014-09-06 | ||
247 | ERROR | Section 13.7 (“Maximizing Parser Speed”) in the new ANTLR version 4 book says to use the code parser.getInterpreter().setSLL(true); to use the SLL parsing strategy, but there seems to be no such method on the class returned by parser.getInterpreter(). What seems to work instead is the following: parser.getInterpreter().setPredictionMode( PredictionMode.SLL ); | 2014-09-07 | ||
10 | TYPO | Diagram at the bottom of the page: Not a typo per se, but the tokens in the diagram are not in the gray boxes which can be confusing at first sight. | 2014-09-06 | ||
60 | ERROR | In grammar fragment for Java, “superclassSpec” should be “extendsClause”, defined as:- extendsClause : ‘extends’ Identifier ; | 2014-09-06 | ||
100 | SUGGEST | In the definition of the “expr” @ array choice I read "| expr ‘[’ expr ‘]’. This will though allow for constructs like 3[1] to be recognized by the parser which are meaningless. I believe the construct should be “| [-]? ID ‘[’ expr ‘]’” which should restrict the parser interpretation. In which case the grun result is: Catches the error as expected. | 2014-09-06 | ||
49 | TYPO | locals [int i = 1;] <- semicolon is error | 2014-09-06 | ||
243 | ERROR | As well as changing | 2014-09-07 | ||
258 | SUGGEST | In the summary bullet points at the bottom of the page, make it clear that combined grammars can import combined grammars, e.g.,
| 2014-09-07 | good addition. | |
243 | 243 | ERROR | The exception that is actually thrown by the SLL parser is org.antlr.v4.runtime.misc.ParseCancellationException. Therefore, in the if statement of the catch clause, we must say | 2014-09-07 | great catch. whole example was borked up. should be: \n \n catch (ParseCancellationException ex) { \n tokens.reset(); // rewind input stream \n parser.reset(); \n // back to standard listeners/handlers \n parser.addErrorListener(ConsoleErrorListener.INSTANCE); \n parser.setErrorHandler(new DefaultErrorStrategy()); \n parser.getInterpreter().setPredictionMode(PredictionMode.LL); \n \n parser.prog(); \n // if we parse ok, it's LL not SLL \n if ( parser.getNumberOfSyntaxErrors()==0 ) { \n LL_required++; \n } \n } \n |
94 | TYPO | Reference 7 for the primary DOT language reference seems to be at h**p://www.graphviz.org/content/dot-language. | 2014-09-06 | ||
81 | TYPO | “Stepping up our processing needs a little bit,” … of foo? | 2014-09-06 | ||
63 | SUGGEST | Antlr4 Page 63, 64, 66 about the | symbol. In case I am not correct, please explain better how to use it. In the examples it seems almost that the newline is also involved in grouping the symbols. | 2014-09-06 | ||
63 | SUGGEST | Please ignore #52317 | 2014-09-06 | ||
167 | 167 | ERROR | The second paragraph from the bottom of the page should begin “The fail option takes either a string literal in single quotes or an action …”, that is, “single quotes” not “double quotes”. Double quotes are only allowed inside action braces. | 2014-09-06 | |
16 | TYPO | “TokenStream” is not coloured properly. Please see this private gist: gist.github.com/mahata/abd583dc67ff40f46e5b | 2014-09-06 | ||
221 | ERROR | Hello, thanks for the excellent software and book. It seems that the following example from page 221 does not work ~ BAD_COMMENT2: fails with the following message: >action in lexer rule ‘BAD_COMMENT1’ must be last element of single outermost alt. I tried the example after failing to both set a semantic predicate value (as in page 217, lexmagic/SimplePy.g4) and at the same time switch context (as in page 222, lexmagic/ModeTagsLexer.g4). | 2014-09-07 | Sorry about that. It was fixed in 4.2 I think so should work now with any ANTLR you download. | |
40 | ERROR | The EvalVisitor class is defined: public class EvalVisitor extends LabeledExprBaseVisitor LabedExprBaseVisitor is an interface, not a class — this cannot be valid Java. | 2014-09-06 | LabedExprBaseVisitor is class. LabedExprVisitor interface. | |
92 | ERROR | In your JSON.g4 grammar, if I wanted to match the number 2.01 I could not do it. The “INT” allows no leading zero, so the 2nd “INT” can’t match the “01” after the dot. | 2014-09-06 | ||
92 | ERROR | In your JSON.g4 grammar, if I wanted to match the number 2.01 I could not do it. The “INT” allows no leading zeroes, so the 2nd “INT” can’t match the “01” after the dot. | 2014-09-06 | ||
49 | TYPO | In the tour/Data.g4 example, there’s the following piece of code: sequence[int n] Doesn’t work for me the way it’s described in the book. The tree is wrong, grouping n+1 characters instead of n. Looks like $i<=$n should be $i<$n - exit condition is 1 character too long in the book/examples. | |||
49 | TYPO | Hi, sequence[int n] It seems that the initialisation of the local variable i fails. Instead of being initialised to 42, the variable i always starts out at 0. This seems to be more of a bug in Antlr than a bug of the book. | |||
74 | SUGGEST | On page 73 at the bottom of the page, the link to the java grammar | |||
102 | ERROR | On page 102 the rule for `expr` is stated as follows: ~ The part about array indexing seems to be wrong since, as given, the rule does not permit | expr ‘[’ expr ‘]’ Regards, | |||
70 | ERROR | Chapter 5.4: the right association examples uses the old syntax: running the example in the book: In ANTLR 4.2, the position of the assoc element option was moved from the operator terminal(s) to the alternative itself. This warning is reported when an assoc element option is specified on a grammar element that is not recognized by the current version of ANTLR, and as a result will simply be ignored. The following rule produces this warning. x : ‘x’ | |||
152 | ERROR | When I run antlr4 on Simple.g4 I get the error message: error(65): Simple.g4:18:52: unknown attribute text for rule stat in $stat.text | |||
157 | TYPO | The examples errors/TestE_Dialog.java and errors/TestE_Listener2.java do not compile because of the import directive import com.sun.istack.internal.Nullable; They do compile after this import directive is changed to import org.antlr.v4.runtime.misc.Nullable; | |||
87 | SUGGEST | In the example “examples/CSV.g4”, the syntax highlight seems to be incorrect, i.e. the second line is highlighted as if it was a string, but in fact it is a lexer rule. Similar problems are elsewhere in the book, from the top of my head is in “examples/JSON.g4” on PDF page 93. | |||
79 | ERROR | This rule (near the top of the page(: assign : ID (WS|COMMENT)? ‘=’ (WS|COMMENT)? expr (WS|COMMENT)? ; should be: assign : ID (WS|COMMENT)* ‘=’ (WS|COMMENT)* expr (WS|COMMENT)* ; | |||
40 | ERROR | The source for tour/EvalVisitor.java is no longer valid for Antlr 4.4. Where are the modified sources? | |||
52 | TYPO | “mode” should be purple-boldfaced to represent it as a keyword. | |||
86 | TYPO | [final sentence of the page, the word “of” is missing, I suspect:] “… on the right side OF rule ‘file’.” | |||
36 | TYPO | Throughout the book, cross-reference links to other pages are missing a space between the comma and the words “on page NN”. Presumably, this is a mistake in a repeating template of some kind. I’m on page 36 and mention this because I’ve seen it so often it has become an irritant by now. This particular case is: “Chapter 5, Designing Grammars,on page 59.” | |||
237 | ERROR | In method consume() the assignment charPositionInLine = 0 should be charPositionInLine = –1. This will correct the erroneous output of TestSimpleMyToken on page 241 where the last four tokens have wrong coordinates for the character position: ‘abc’ 2:1 should be 2:0, etc. | |||
175 | ERROR | The sample errors/TestBail.java contains | |||
59 | TYPO | Ultimately, we need the ability There is a difference between godlike and splitting a language. | |||
68 | ERROR | Section 4.5 Cool Lexical Features Last paragraph on page 68: >>Each line of that output represents a token and contains the token index, the start and stop character, the token text, the token type, and finally the line and character position within the line. Should probably be “the start and stop character position”. | |||
68 | SUGGEST | Would be clearer to either change “grun XML” to “grun XMLLexer”, or to clarify that the suffix “Lexer” is implicit in TestRig: >>Here’s how to do a build and launch the test rig: i.e. state that both “grun XML” and “grun XMLLexer” work since you have the option of omitting “Lexer”. -RedTailedHawk | |||
89 | TYPO | Reference to bad URL on antlr.org in footnote #3: Note: I couldn’t enter the full URL due to spam prevention | |||
113 | TYPO | There is a code snippet on this page for the section 7.2-Implementing Applications with Parse-Tree Listeners. The method named “PropertyFileBaseVisitor” should probably be named “PropertyFileBaseListener”. The code is also incorrect as it should implement PropertyFileListener, not PropertyFileVisitor. I’m guessing what happened is that section 7.3-Implementing Applications with Visitors was written first, and the source code snippet was copied to 7.2, and didn’t get corrected. | |||
5 | ERROR | The Windows commands to run ANTLR on this page are not correct. Below I have some example commands that I’ve tested in Windows. I kept the paths the same to be consistent with the book, but you may have to adjust the minor version number of the ANTLR 4.x *.jar files. There should also be some code to set the CLASSPATH environment variable either from the command line or via Control Panel for the Windows instructions, since the commands assume it is set. set CLASSPATH=“C:\\jars\\antlr-runtime-4.4.jar;C:\\jars\\antlr-4.4-complete.jar;” doskey antlr4=java -jar C:\\libraries\\antlr-4.4-complete.jar $* doskey grun=java org.antlr.v4.runtime.misc.TestRig $* | |||
39 | SUGGEST | I found that you cannot have a label on a rule containing a single condition (no alternatives). I found that it’s helpful for debugging purposes to use labels when troubleshooting a grammar when giving source code as input to the generated parser. I have been using them for a reference when validating entry and exit events for grammar unit tests. As a trick/tip to the reader, it might be worth mentioning that you must have at least two alternatives to use these labels. | |||
145 | SUGGEST | In DefPhase.java, the statement: There is no explanation of what the “start” field is. I found an explanation at www.antlr.org/api/Java/org/antlr/v4/runtime/ParserRuleContext.html. Reading that web page, it seems like “getStart()” would be a better way to access the initial token in the context. Suggestion: mention that “getStart()” returns the initial token in the context. | |||
77 | TYPO | In the subsection “Matching Numbers” there is a parenthetical note “(See Section 6.5, Parsing R, on page 104 for lexical rules that match full floating-point numbers and even complex numbers like 3.2i.)” Nowhere in section 6.5 are lexical rules to match floating-point numbers discussed. There are rules for matching (complex) floating-point numbers in the source code file code/examples/R.g4 I suggest removing the parenthetical note. | |||
281 | ERROR | Lexer Rule Elements section: The ESC rule is documented as ‘\\\\’ . ; It took me a while to figure this out because the Antlr4 plugin (latest in IntelliJ) provides a misleading error about ‘no viable input alternative’. Suggest removing the latter, and putting a separate para below the lexical rules that states how to quote what, and where backslash quoting is needed. | |||
123 | SUGGEST | In this example code you’re using the Java Stack class. As per the Java documentation, this is deprecated and the ArrayDeque class should be used instead. It makes no practical difference, but books shouldn’t be recommending APIs that are deprecated for a good reason. | |||
6 | ERROR | Configuration: Scenario: | |||
162 | TYPO | In the diagram, under “Good Syntax”, the expression is [i^2]. I believe it should be [1^2]. | |||
158 | ERROR | In source code example for “underlineError”, if the string to be parsed is short enough and just one line long, and an error occurs in that one line, the string placed in “errorLine” is not null-terminated. Then, when “errorLine” is printed, garbage characters are displayed. | |||
16 | SUGGEST | In the picture breaking down parse tree into RuleNodes, TerminalNodes, TokenStream and CharStream, the highlighting of the TokenStream was probably intended to line up with the characters in “sp = 100;” The highlighting serves to show what parts of the string belong to each token. However, the highlighting is much wider than the rendered string. It is probably a font-related problem. | |||
179 | ERROR | if you test the expression “3*(4+5)”, you will get the result 0; | |||
4 | SUGGEST | The sentence beginning “At version 4.0, ANTLR is still written in ANTLR3, so…” caused me a lot of human backtracking to parse. I would suggest this could be rephrased for clarity. Changing the “At” to “As of” might have worked for me. | |||
89 | ERROR | The book and sample JSON grammar seems to introduce an unnecessary restriction by adding a rule named ‘json’, which not present in either the json.org syntax diagrams, or the formal ECMA standard. The correct starting rule for JSON is ‘value’, this is made clear from paragraph 4 of the ECMA standard, which starts out saying: A JSON text is a sequence of tokens formed from Unicode code points that conforms to the JSON value grammar. | |||
46 | ERROR | correct warning when running> antlr4 java.4g copying solution from stackoverflow since url not allowed here: The It must be placed always right to the surrounding |: to correct the java.4g file: | expression ‘&&’ expression | |||
168 | ERROR | Line 17 says {if ($v.int==0) notifyListeners(“values must be > 0”);} I think we should change “notifyListeners” into “notifyErrorListeners” b/c in the Parser class, we only have notifyErrorListeners method! | |||
150 | ERROR | When I run antlr4 on Simple.g4 I get the error message: error(65): Simple.g4:18:49: unknown attribute text for rule stat in $stat.text I guess it is due to ambiguity, as rule stat has two alternatives. How to fix it? Easy. Try the following: stat: expr ‘;’ This will make the code work. | |||
82 | ERROR | Section 5.6 just after 192.168.209.85 “GET /download/foo.html HTTP/1.0” 200 The rule | |||
256 | ERROR | The page has the following code | |||
156 | ERROR | Your UnderlineListener will throw java.lang.ArrayIndexOutOfBoundsException for the following input: class T {int f(x) { a = 3; } How to fix it? You need to add another line of code: if (line <= lines.length) and put the following code inside this if: String errorLine = lines[line - 1]; | |||
179 | SUGGEST | You said we will get the result 0 when we test the expression “3*(4+5)”. Then you suggested the following change: But I found this change is NOT necessary, the code just runs fine w/o any change! | |||
87 | TYPO | examples/CSV.g4 Should be: | |||
14 | TYPO | In Chapter 2. The Big Picture • 14, the comment on the first line for instanciation rule is wrong: The rule stat can’t match “f();” | |||
28/29 | ERROR | By fill in: {99,99,3,{451,99,3},451,451,8} throws an changing from to / Translate integers to 4-digit hexadecimal strings prefixed with \\\\u */ works fine. | |||
28 | ERROR | The Test.java example in Section 3.3 uses ANTLRInputStream. Using IdeaJ to compile things, this primitive shows as deprecated. I’m new to Java so I might have misconfigured stuff, but… | |||
108 | 94 | ERROR | The EXP token rule fragment incorrectly uses INT for the exponent value; leading zeros are actually allowed by the specification, here (e.g., 1.1e009 is valid). The book grammar should use [0-9]+, instead. | ||
158 | ERROR | The implementation of underlineError() IMHO bears a potential IndexOutOfBoundsException: /* … */ If the last character of a parsed file is a newline, and the parser issues a parse error past that last newline character, lines[line - 1] will issue an out of bounds exception, since “Trailing empty strings are therefore not included in the resulting array.” according to the documentation of String.split() | |||
118 | 104 | ERROR | The link in footnote #10, to the R Language Overview (www.stat.wisc.edu/~deepayan/SIBS2005/slides/language-overview.pdf) is broken. | ||
28 | ERROR | Under Section 3.3 Integrating a Generated Parser into a Java Program, // import ANTLR’s runtime libraries public class Test { \t\t// create a lexer that feeds off of input CharStream \t\t// create a buffer of tokens pulled from the lexer \t\t// create a paerser that feeds off the tokens buffer \t\tParseTree tree = parser.init(); // begin parsing at init rule | |||
167 | ERROR | In the sentence “The parser gobbles up y;;; until it sees the start of another member (set © earlier) and then loops back to member.”, set © should be set(a). This sentence describes the parser behavior as described by set(a) in the previous page and not set© as mentioned within the parentheses in the sentence. | |||
113 | TYPO | Code: This subsection is introducing Listener patter, according to the context, i think “PropertyFileBaseVisitor” should be “PropertyFileBaseListener” (and also “AbstractParseTreeVisitor”, “PropertyFileVisitor”). | |||
43 | ERROR | ctx.op.getType() no longer exists in antlr4. Use this instead: and: if(ctx.MUL() != null ) |