ANTLR 3.2 Release Sep 21, 2009 Terence Parr, parrt at cs usfca edu ANTLR project lead and supreme dictator for life University of San Francisco CHANGES September 22, 2009 -- ANTLR v3.2 September 21, 2009 [Jim Idle] * Added new options for tool invocation to control the points at which the code generator tells the target code to use its equivalent of switch() instead of inline ifs. -Xmaxswitchcaselabels m don't generate switch() statements for dfas bigger than m [300] -Xminswitchalts m don't generate switch() statements for dfas smaller than m [3] * Upgraded -X help output to include new optins and provide the default settings, as well as provide units for those settings that need them. * Change the C Target to overide the deafults for the new settings to generate the most optimizable C code from the modern C compiler point of view. This is essentially to always use swtich statements unless there is absolutely no other option. C defaults are to use 1 for minimum and 3000 for maximum number of alts that trigger switch(). This results in object code that is 30% smaller and up to 20% faster. April 23, 2009 * Added reset to TreeNodeStream interface. April 22, 2009 * Fixed ANTLR-374. Was caused by moved of grammars. %foo() stuff didn't work April 9, 2009 * .g and .g3 file extensions work again. * introduced bug in 3.1.3: gives exception not error msg upon missing .g file March 26, 2009 * Made ctor in TreeRewriter and TreeFilter call this not super. March 21, 2009 * Added ctor to RecognizerSharedState to allow cloning it. March 17, 2009 -- ANTLR v3.1.3 * improved ANTLRv3.g to handle <...> element options March 15, 2009 * Fixed ANTLR-389. Strip didn't ignore options in subrules; also seemed to demand stdin. March 15, 2009 * ANTLR always sorts incoming grammar list by dependency. For example, If W.g depends on tokens from P.g then P.g is done first even if W.g mentioned first on command line. It does not ignore any files you specify the commandline. If you do *.g and that includes some imported grammars, it will run antlr on them. * -make option prevents ANTLR from running on P.g if P older than generated files. * Added org.antlr.tool.GrammarSpelunker to build a faster dependency checker (what grammars depend on etc...). Totally independent of any ANTLR code; easy to pull into other tools. * Added org.antlr.misc.Graph, a general graph with nodes containing an Object payload. It knows how to do a topological sort on the nodes. March 10, 2009 * Added associativity token option to support upcoming special expression parsing. Added rule option strategy=precedence also March 1, 2009 * Changed ANTLRWorks debug port from 49153 to 49100. Apparently we change the port in ANTLRWorks to 49100 in 1.2 but forgot to do so in the ANTLR targets. START CHANGES FOR TREE FILTER MODE (pulled from dev branch) This feature will be announced in 3.2, but I am integrating from my development branch now into the mainline so target developers have a chance to implement. We might release 3.1.3 bug fix release before 3.2. * CommonTreeNodeStream -> BufferedTreeNodeStream. Now, CommonTreeNodeStream is completely unbuffered unless you are backtracking. No longer making a list of all nodes before tree parsing. * Added tree grammar filter=true mode. Altered templates: Java.stg: added filterMode to genericParser and treeParser. This required a change to ANTLRCore.sti Defined a default parameter in treeParser to set the superclass to TreeFilter for tree grammar with filter=true. It sets superclass to TreeRewriter if filter=true and output=AST. Other them that, I only had to change ANTLR itself a little bit. Made filter mode valid for tree grammars and have it automatically set the necessary elements: @synpredgate, backtrack=true, rewrite=true (if output=AST). Added error message for detecting conflicting options. * Added misc.FastQueue and TestFastQueue: A queue that can dequeue and get(i) in O(1) and grow arbitrarily large. A linked list is fast at dequeue but slow at get(i). An array is the reverse. This is O(1) for both operations. * Added tree.TreeIterator, a generator that walks a doubly linked tree. The nodes must know what index they are. It's an Iterator but remove() is not supported. Returns navigation nodes always: UP, DOWN, EOF. * Added misc.LookaheadStream: A lookahead queue that knows how to mark/release locations in the buffer for backtracking purposes. I hope to use for both tree nodes and tokens. Just implement nextElement() to say how to get next node or token. END CHANGES FOR TREE FILTER MODE February 23, 2009 -- ANTLR v3.1.2 February 18, 2009 * Added org.antlr.tool.Strip (reads from file arg or stdin, emits to stdout) to strip actions from a grammar. February 4, 2009 * Added CommonTree.setUnknownTokenBoundaries(). Sometimes we build trees in a grammar and some of the token boundaries are not set properly. This only matters if you want to print out the original text associated with a subtree. Check this out rule: postfixExpression : primary ('.'^ ID)* ; For a.b.c, we get a '.' that does not have the token boundaries set. ANTLR only sets token boundaries for subtrees returned from a rule. SO, the overall '.' operator has the token boundaries set from 'a' to 'c' tokens, but the lower '.' subtree does not get the boundaries set (they are -1,-1). Calling setUnknownTokenBoundaries() on the returned tree sets the boundaries appropriately according to the children's token boundaries. January 22, 2009 * fixed to be listeners.add(listener); in addListener() of DebugEventHub.java January 20, 2009 * Removed runtime method: mismatch in BaseRecognizer and TreeParser. Seems to be unused. Had to override method recoverFromMismatchedToken() in TreeParser to get rid of single token insertion and deletion for tree parsing because it makes no sense with all of the up-and-down nodes. * Changed JIRA port number from 8888 to no port spec (aka port 80) and all refs to it in this file. * Changed BaseTree to Tree typecase in getChild and toStringTree() and deleteChild() to make more generic. December 16, 2008 * Added -verbose cmd-line option and turned off standard header and list of read files. Silent now without -verbose. November 24, 2008 * null-ptr protected getParent and a few others. * Added new ctor to CommonTreeNodeStream for walking subtrees. Avoids having to make new serialized stream as it can reuse overall node stream buffer. November 20, 2008 * Updated BaseTest to isolate tests better. November 17, 2008 * BaseTreeAdaptor.getType() was hosed; always gave 0. Thanks to Sam Harwell. November 8, 2008 * Added methods to BaseRecognizer: public void setBacktrackingLevel(int n) { state.backtracking = n; } /** Return whether or not a backtracking attempt failed. */ public boolean failed() { return state.failed; } November 5, 2008 * Tweaked traceIn/Out to say "fail/succeeded" * Bug in code gen for tree grammar wildcard list label x+=. * Use of backtrack=true anywhere in grammar causes backtracking sensitive code to be generated. Actions are gated etc... Previously, that only happened when a syntactic predicate appeared in a DFA. But, we need to gate actions when backtracking option is set even if no decision is generated to support filtering of trees. October 25, 2008 * Fixed debug event socket protocol to allow spaces in filenames. * Added TreeVisitor and TreeVisitorAction to org.antlr.runtime.tree. October 22, 2008 * Added inContext() to TreeParser. Very useful for predicating tree grammar productions according to context (their parent list). Added new TestTreeContext unit tests (15). /** Check if current node in input has a context. Context means sequence * of nodes towards root of tree. For example, you might say context * is "MULT" which means my parent must be MULT. "CLASS VARDEF" says * current node must be child of a VARDEF and whose parent is a CLASS node. * You can use "..." to mean zero-or-more nodes. "METHOD ... VARDEF" * means my parent is VARDEF and somewhere above that is a METHOD node. * The first node in the context is not necessarily the root. The context * matcher stops matching and returns true when it runs out of context. * There is no way to force the first node to be the root. */ public boolean inContext(String context) {...} * Added 3 methods to Tree interface [BREAKS BACKWARD COMPATIBILITY] /** Is there is a node above with token type ttype? */ public boolean hasAncestor(int ttype); /** Walk upwards and get first ancestor with this token type. */ public Tree getAncestor(int ttype); /** Return a list of all ancestors of this node. The first node of * list is the root and the last is the parent of this node. */ public List getAncestors(); October 21, 2008 * Updated unit tests to be correct for \uFFFE->\uFFFF change * Made . in tree grammar look like ^(. .*) to analysis, though ^(. foo) is illegal (can't have . at root). Wildcard is subtree or node. Fixed bugs: http://www.antlr.org/browse/ANTLR-248 http://www.antlr.org/browse/ANTLR-344 October 1, 2008 -- ANTLR v3.1.1 September 8, 2008 * Labels on tokens, rules carry into synpreds now so semantic predicates work. This didn't work since labels were stripped in the synpred and they weren't defined in the generated method. a : x=A z=a {$x.text.equals($z.text)}? A | y=A a A A ; September 3, 2008 * Made a REV static variable in Tool so that we can change the rev for daily builds. * Made \uFFFF a valid character. Token types are 32-bit clean using -1 not 0x0000FFFF as -1 so it should be okay. Label.java: public static final int MIN_CHAR_VALUE = '\u0000'; public static final int MAX_CHAR_VALUE = '\uFFFF'; August 30, 2008 * Changed messages in en.stg so that TOKEN_NONDETERMINISM correctly indicates when actions hid semantic predicates. August 15, 2008 * Tweaked build properties and build.xml August 13, 2008 * Fixed ANTLR-314; 3.1 introduced a problem with list labels += August 12, 2008 -- ANTLR v3.1 * Added JavaScript target August 7, 2008 * an NFA target of EOF predicate transition in DFA cause an exception in getPredicatesPerNonDeterministicAlt(). * Kay Roepke found a nasty bug when debugging AST-constructing composite recognizers. If the input state was null to the constructor, super class constructor created a new parser state object. Later, though we passed the argument state not this.state to the delegate constructors, forcing them to share a different state objects! Changed state to this.state in Dbg.stg constructors. * Ack. messed up debug/AST. Have to set proxy's tree adaptor; it's a circular ref. Just an ASTDbg.stg change. August 4, 2008 * superClass works now for lexers * Made Grammar.defineNamedAction propogate header actions down to all delegates if root grammar; regardless of lexer/parser scope. * Rejiggered AST templates to propogate changes to tree adaptor for delegate grammars. Fixes ANTLR-302 August 4, 2008 * FOLLOW set computations altered constant FOLLOW bit sets. * Added (...) are all predicate evaluations. * Extra init code for tree parser nonrewrite mode removed. * Added empty child list check in becomeRoot August 3, 2008 * Was using RuleReturnScope not Rulename_return for list labels in tree parser. * Didn't set _last in tree parser for rule ref track stuff (rewrite=true) August 2, 2008 * Benjamin found another rewrite engine bug. July 30, 2008 * CommonTreeNodeStream / CommonTokenStream did not reset properly. July 29, 2008 * Fixed another bug in TokenRewriteStream; didn't like inserts after end. July 28, 2008 * Fixed bug in TokenRewriteStream.toString(start,stop); it ignored parameters. ;) July 17, 2008 * allow qualified type names in hetero <...> options like T July 5, 2008 * treeLevel not set for setBlock alts; added unit test July 3, 2008 * Fixed ANTLR-267. parse tree added nodes during backtracking and cyclic DFAs. tracks hidden tokens too now. Added toInputString() to get text back including hidden tokens. Shows for rules that match nothing. June 26, 2008 * Added gParent ptr that points to immediate parent grammar. E.g., // delegators public MParser gM; public M_S gS; public M_S gParent = gS; // NEW * Grammar imports didn't set all the delegate pointers...lots of imported grammars would cause a null ptr exception. Fixes ANTLR-292. June 25, 2008 * List labels in tree construction didn't always track the tree; sometimes had a rule result structure. June 4, 2008 * Improved unit testing so that each test suite executes and builds grammars in a separate temporary directory. This means they can execute concurrently. Also seem to be a problem with my class path during execution. Moved tmpdir for ahead of standard CLASSPATH. * By virtue of an improvement to StringTemplate, output newlines in generated files should be normalized to whatever your host uses. June 3, 2008 * Restrict legality of grammar options; for example you cannot use output option in lexer anymore. June 2, 2008 * Throw illegal arg exception upon invalid TokenRewriteStream ops. Rewrote core of engine. Slightly different operation. Added many more unit tests. 3.1b1 - May 20, 2008 May 11, 2008 * rewrite=true, output=AST for tree grammar was not working. Altered trees were not propagated back up the rule reference chain. Required a number of mods to ASTTreeParser.stg. Added unit tests. May 10, 2008 * [BACKWARD INCOMPATIBLE if you override match()] I had turned off single token insertion and deletion because I could not figure out how to work with trees and actions. Figure that out and so I turned it back on. match() returns Object matched now (parser, tree parser) so we can set labels on token refs properly after single token ins/del error recovery. Allows actions and tree construction to proceed normally even though we recover in the middle of an alternative. Added methods for conjuring up missing symbols: getMissingSymbol(). * refactored BaseRecognizer error handling routines * Single token error recovery was not properly taking into consideration EOF. * ANTLR no longer tries to recover in tree parsers inline using single node deletion or insertion; throw exception. Trees should be well formed as they are not created by users. * Added empty constructors to the exception classes that did not have them so that ANTLRWorks can create the exceptions. * Made debug tree adaptor deal with tokens conjured up during error recovery. * Removed extra location() debug element that was emitted. May 8, 2008 * ANTLR didn't update line/col to DFA map for AW. May 6-7, 2008 * Insufficiently covered (with semantic predicates) alt warnings are now emitted before nondeterminisms so it's clear the nondeterminism is a result of insufficient preds. * Improved insufficiently covered alt warnings from: warning(203): T.g:2:3: The following alternatives are insufficiently covered with predicates: 1 to: warning(203): T.g:2:3: Input B is insufficiently covered with predicates at loca tions: alt 1: line 3:15, alt 2: line 2:9 * Improved nondeterminism warning to have: Semantic predicates were present but were hidden by actions. parser grammar U; a : (A B)? ; b : X a {p1}? A B | Y a {a1} {p2}? A B | Z a ; To create the prediction DFA for the optional sub rule in 'a', ANTLR must find all references to 'a' to determine what can follow. A B can follow 'a' in the first two alts rule 'b'. To resolve the conflict between matching A B immediately in the sub rule and exiting rule 'a' to match it in 'b', ANTLR looks for predicates. In this case, there are two predicates that indicate the semantic context in which the surrounding alternatives are valid. The problem is that one of the predicates is hidden by an action. It took me 1.5 days, but I've finally have gotten ANTLR to properly track the insufficiently covered alternatives. Further, I have gotten it to tell you precisely where the uncovered predicates are even if they are simply hidden by actions. I have also updated all of the nondeterminism warnings so that it tells you if there was a predicate but one hidden by an action (this could be a separate condition from insufficiently covered predicates). here are your messages from ANTLR: ANTLR Parser Generator Version 3.1b1 (??) 1989-2007 warning(203): U.g:2:5: Input such as "A B" is insufficiently covered with predicates at locations: alt 2: line 3:38 at B Semantic predicates were present but were hidden by actions. warning(200): U.g:2:5: Decision can match input such as "A B" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input Semantic predicates were present but were hidden by actions. * Fixed issue where r41 : (INT -> INT) ( ('+' i=INT) -> ^($i $r41) )* ';' ; still warned about $r41 being ambig. * actions are now added to the NFA. * Fixed ANTLR-222. ANTLR now ignores preds after actions. May 5, 2008 * Fixed ANTLR-235 by backing out a change from 12-31-07. * Fixed ANTLR-249; I include semantic context again in closure busy signal. May 3, 2008 * Fixed ANTLR-208. Looks in library or in -o output path. antlr -o foo T.g U.g where U needs T.tokens won't work unless we look in foo too. fixed. * Refactored assign.types.g to move methods to a class called AssignTokenTypesBehavior. * Fixed ANTLR-207. Lexers importing vocabs didn't see ';'=4 type aliases in .tokens. * Fixed ANTLR-228. Couldn't use wildcard in alts with AST rewrites. May 2, 2008 * Fixed ANTLR-230; can use \' now in action. * Scope attributes no longer have a stack depth check on front. If you ref $r::a when r has not invoked you, then you get an exception not a default value. Back to the way 3.0.1 worked. * $channel was a global variable in 3.0.1 unlike $type which did not affect an invoking lexer rule. Now it's local too. Only $type and $channel are ever set with regularity. Setting those should not affect an invoking lexer rule as in the following should work: X : ID WS? '=' ID ; // result is X on normal channel WS : ' '+ {$channel = HIDDEN; } ; STRING : '"' (ESC|.)* '"' ; // result is STRING not ESC FLOAT : INT '.' INT? ; // should be FLOAT INT : Digit+ ; fragment Digit : '0'..'9' ; * Fixed bug in interpreter regarding (...)* loops May 1, 2008 * Fixed ANTLR-202. These now give warnings about ambig ref to $a. a : ID a -> $a | INT ; and a : A a {$a.text} | B ; April 30, 2008 * Fixed ANTLR-237. updated -depend to know about imported grammars. $ java org.antlr.Tool -depend -lib foo T.g ANTLR Parser Generator Version 3.1b1 (??) 1989-2007 T.g: foo/Java.g TParser.java : T.g T.tokens : T.g TLexer.java : T.g T_Java : T.g April 29, 2008 * Fixed ANTLR-217; scope A,B,C; didn't work * Fixed ANTLR-224; ! or ^ on item in alt with rewrite gave exception * Added token options to terminals: ID etc... node is default so you can do ID for hetero tree types. most common. April 17, 2008 * Use default msg if unknown recog type in getErrorMessage(): String msg = e.getMessage(); April 14, 2008 * %x.y = foo; was not working in @members section March 29, 2008 * Import couldn't handle A imports B imports C. March 27, 2008 * Added get/setInputStream to Token interface and affected classes. February 26, 2008 * made fillBuffer public in CommonTreeNodeStream so we can add trees to stream for interactive interpreters. February 14, 2008 * Fixed a bug in the code generation where tree level 0 was used no matter what to rewrite trees in tree grammars. added unit test * Fixed ANTLR-221. exceptions were generated when using AST construction operators and no output=AST option. February 13, 2008 * Improved error msgs for unreachable alts and tokens. February 11-12, 2008 * Fixed ANTLR-219. It looks like the AST construction code for sets was totally messed up. This was for not only the new tree parser AST construction, but also the regular tree construction for parsers. I had to introduce templates in the ASTTreeParser.stg file to deal with this. added unit tests: TestTreeGrammarRewriteAST.testSetMatchNoRewrite(), testSetMatchNoRewriteLevel2(), testSetMatchNoRewriteLevel2Root(). Had to add template matchRuleBlockSet() to differentiate between a regular set in one that is an entire rule. If it is an entire rule, it has to set the return value, retval.tree. * Fixed ANTLR-220. Made TreeAdaptor dupNode and dupTree events emit debugging events so AW could see tree node duplications. February 4, 2008 * BACKWARD INCOMPATIBILITY Added getSourceName to IntStream and TokenSource interfaces and also the BaseRecognizer. Have to know where char come from for error messages. Widespread change, but a trivial one. January 17, 2008 * Interpreter throws FailedPredicateException now when it sees a predicate; before it was silently failing. I'll make it work one of these days. ;) January 12, 2008 * Copy ctor not copying start and stop for common token. Fixes ANTLR-212 * Removed single token insertion and deletion for tokens, sets. Required a change to the code generation for matchSet() template and a tweak inside the BaseRecognizer. To engage this again is easy, just override mismatch() to call mismatchRecover(). I changed it to simply throw an exception. * Added syntaxError recognizer state var so you can easily tell if a recognizer failed. Added getNumberOfSyntaxErrors() to recognizers. * Added doc for the error node stuff: http://www.antlr.org/wiki/display/ANTLR3/Tree+construction * Fixed ANTLR-193 * Added recognizer methods to answer questions about current mismatched token error. Useful now since i don't automatically recover inline to such errors (I throw exception): mismatchIsUnwantedToken(IntStream input, int ttype) mismatchIsMissingToken(IntStream input, BitSet follow) * Added UnwantedTokenException and MissingTokenException to make match() problems more precise in case you want to catch differently. Updated getErrorMessage() to be more precise. Says: line 2:9 missing EQ at '0' now instead of line 2:9 mismatched input '0' expecting EQ Input "x=9 9;" gives line 3:8 extraneous input '9' expecting ';' When very confused, "x=9 for;", you still get old mismatched message: line 3:8 extraneous input 'for' expecting ';' line 3:11 mismatched input ';' expecting '(' * Added unit tests to TestAutoAST and copied to TestRewriteAST with suitable rewrites to ensure basic error node insertion works. January 11, 2008 * Adding errorNode to TreeAdaptor and various debug events/listeners. Had to add new class runtime.tree.CommonErrorNode to hold all the goodies: input stream, start/stop objects. * Tweaked CommonTree.getType() to return INVALID_TOKEN_TYPE instead of literal 0 (same thing at moment though). * Updated ANTLRWorks to show error nodes in tree as much as I could; Jean will get to rest of it. January 9-10, 2008 * Continued work on debugging/profiling composite grammars. * Updated debug protocol for debugging composite grammars. enter/exit rule needs grammar to know when to flip display in AW. * Fixed ANTLR-209. ANTLR consumed 2 not 1 char to recover in lexer. * Added two faqs instead of making changes to antlr runtime about lexer error handling: http://www.antlr.org/wiki/pages/viewpage.action?pageId=5341230 http://www.antlr.org/wiki/pages/viewpage.action?pageId=5341217 January 1-8, 2008 * Making debugging/profiling work with composite grammars. * Updated ANTLRWorks so it works still for noncomposite grammars. * two new examples: import and composite-java (the java example grammar broken up into multiple pieces using import). * Worked on composite grammars. Had to refactor a lot of code to make ANTLR deal with one meta grammar made up of multiple grammars. I thought I had it sort of working back in August. Yes, but barely. Lots of work to do it seemed. Lots of clean up work. Many new unit tests in TestCompositeGrammars. Had to add new error messages warning about conflicting tokens inherited from multiple grammars etc... TOKEN_ALIAS_CONFLICT(arg,arg2) ::= "cannot alias ; string already assigned to " TOKEN_ALIAS_REASSIGNMENT(arg,arg2) ::= "cannot alias ; token name already assigned to " TOKEN_VOCAB_IN_DELEGATE(arg,arg2) ::= "tokenVocab option ignored in imported grammar " INVALID_IMPORT(arg,arg2) ::= " grammar cannot import grammar " IMPORTED_TOKENS_RULE_EMPTY(arg,arg2) ::= "no lexer rules contributed to from imported grammar " IMPORT_NAME_CLASH(arg,arg2) ::= "combined grammar and imported grammar both generate ; import ignored" This stuff got really really complicated. Syntactic predicate names even had to be scoped per grammar so they don't conflict. * When using subrules like (atom->atom) to set result tree, it was not properly setting result (early enough). Future code got null for $rule.tree. December 31, 2007 * Added the start of a semantic predicate computation for LL(1) to solve a problem with slow grammar analysis even with k=1 due to predicates. Then I realized the problem with that grammar was elsewhere. Semantic context really shouldn't be used when preventing closure recomputation (May 2008 I discovered I was wrong--you do need it). The predicates became huge even though the reduced value would be no different. The analyzer seems faster now that I am not testing predicate values all the time. Further it may terminate sooner just due to reduced closure recursion. * Moved FIRST/FOLLOW computations to a separate class LL1Analyzer to tidy up. * ANTLR lexer allowed octal escapes, but they didn't work. ;) Rather than fix, I'm removing. Use '\uxxxx' to get even 8 bit char values: \u00xx. December 29, 2007 * Fixed ANTLR-206. I wasn't avoiding analyzing decisions in left-recursive rules. * Had to add hetero arg to all tokenRef*() templates. Added _last local var to track last child so we can do replaceChildren() during AST rewrite mode for tree grammars. Should be useful later for .text property. Ack, hetero arg is on lots of templates. :( Moved ruleCleanUp() template into ASTTreeParser and ASTParser groups. * added noRewrite() template (to Java.stg) so we can insert code during rewrite mode to return original tree if no rewrite. Might be useful for token rewrites later. For templates too? * Had to add if !rewriteMode around tree construction in tree parser templates. * Harald Muller pointed out that we need to use in our tests for null token/rule property references. For int types we need 0 not null. (p!=null?p.line:0). Changed scopeAttributeRef, ruleLabelRef. Also changed the known typed attributes like lexerRuleLabelPropertyRef_line to yield 0 upon null rule ref to be consistent with case when we don't know the type. Fixes ANTLR-195. Added testTypeOfGuardedAttributeRefIsCorrect test and reset expected output for 13 tests that now "fail". December 28, 2007 * added polydiff example (Java target) * added "int" property for token and lexer rule refs. super convenient. E.g., a : b=INT {int x = $b.int;} ; December 27, 2007 * Changed -Xnoinlinedfa to -Xmaxinlinedfastates m where m is maximum number of states a DFA can have before ANTLR avoids inlining it. Instead, you get a table-based DFA. This affectively avoids some acyclic DFA that still have many states with multiple incident edges. The combinatorial explosion smacks of infinite loop. Fixes ANTLR-130. * [...] are allowed in args now but ] must be escaped as \]. E.g., a[String[\] ick, int i] : ... ; And calling a rule: foo[x[i\], 34] Fixes ANTLR-140. * Fixed ANTLR-105. Target.getTargetStringLiteralFromANTLRStringLiteral() escaped " that were already escaped. * target's can now specify how to encode int as char escape. Moved DFA.encodeIntAsCharEscape to Target. * Bug in runtime.DFA. If a special state (one with predicate) failed, it tried to continue (causing out of range exception due to state = -1) instead of reporting error. * If -dfa with combined grammar T.g, builds T.dec-*.dot and TLexer.dec-*.dot * Fix ANTLR-165. Generate TParser.java and TLexer.java from T.g if combined, else use T.java as output regardless of type. BACKWARD INCOMPATIBILITY since file names change. I changed the examples-v3/java to be consistent. Required XML.g -> XMLLexer.java and fuzzy/Main.java change. * Fix ANTLR-169. Deletes tmp lexer grammar file. December 25, 2007 * Fixed ANTLR-111. More unit tests in TestAttributes. December 25, 2007 * Dangling states ("decision cannot distinguish between alternatives for at least one input sequence") is now an error not a warning. * Added sample input sequence that leads to dangling DFA state, one that cannot reach an accept state. ANTLR ran into a case where the same input sequence reaches multiple locations in the NFA (and so not nondeterministic), but analysis ran out of further NFA states to look for more input. Commonly at EOF target states. Now says: error(202): CS.g:248:95: the decision cannot distinguish between alternative(s) 1,2 for input such as "DOT IDENTIFIER EOF" Also fixed bug where dangling states did not resolve to stop states. * Fixed ANTLR-123 December 17-21, 2007 * k=1 doesn't prevent backtracking anymore as in (options {k=1;}:'else' statement)? if backtrack=true for overall grammar. Set to false in subrule. * Optimized the analysis engine for LL(1). Doesn't attempt LL(*) unless LL(1) fails. If not LL(1) but autobacktracking but no other kind of predicate, it also avoids LL(*). This is only important for really big 4000 line grammars etc... * Lots of code clean up December 16, 2007 * Yet more Kay pair programming. Saved yet more RAM; 15% by wacking NFA configurations etc in each DFA state after DFA construction. * Overall we drop from 2m49s to 1m11s for a huge 4000 line TSQL grammar with k=*. Only needs -Xconversiontimeout 2000 now not -Xconversiontimeout 5000 too. With k=1, it's 1m30s down to 40s. December 15, 2007 * Working with Kay Roepke, we got about 15% speed improvement in overall ANTLR exec time. Memory footprint seems to be about 50% smaller. December 13-14, 2007 * I abort entire DFA construction now when I see recursion in > 1 alt. Decision is non-LL(*) even if some pieces are LL(*). Safer to bail out and try with fixed k. If user set fixed k then it continues because analysis will eventually terminate for sure. If a pred is encountered and k=* and it's non-LL(*), it aborts and retries at k=1 but does NOT emit an error. * Decided that recursion overflow while computing a lookahead DFA is serious enough that I should bail out of entire DFA computation. Previously analysis tried to keep going and made the rules about how analysis worked more complicated. Better to simply abort when decision can't be computed with current max stack (-Xm option). User can adjust or add predicate etc... This is now an error not a warning. * Recursion overflow and unreachable alt is now a fatal error; no code gen. The decision will literally not work. * Cleaned up how DFA construction/analysis aborts due to non-LL(*) and overflow etc... Throws exceptions now, which cleans up a bunch of IF checks etc... Very nice now. Exceptions: analysis/AnalysisRecursionOverflowException.java analysis/AnalysisTimeoutException.java analysis/NonLLStarDecisionException.java * ErrorManager.grammarWarning() counted them as errors not warnings. * Unreachable alt warnings are now errors. * The upshot of these changes is that I fixed ANTLR-178 and did lots of refactoring of code handling analysis failure. December 11, 2007 * Could not deal with spaces, oddly enough in arg lists: grammar Bad; a : A b["foo", $A.text] ; b[String x, String y] : C ; October 28, 2007 * Made ANTLR emit a better error message when it cannot write the implicit lexer file from a combined grammar. Used to say "cannot open file", now says "cannot write file" and gives backtrace. September 15, 2007 add getCharStream to Lexer. September 10, 2007 * Added {{...}} forced action executed even during backtracking. September 9, 2007 * r='string' in lexer got a duplicate label definition. August 21, 2007 * $scope::variable refs now check for empty stack so that expr == null if $scope has an empty stack. Works for $scope[...]::variable too. Nice! August 20, 2007 * Added reset() to CommonTreeNodeStream, token stream too * Made refs to rule/token properties use ?: to avoid null ptr exception. $label.st now is label!=null?label.st:null. Updated TestAttributes. This is useful not only for optional rule/token refs, but also during error recovery. If ID is not matched, $ID.text won't cause a null ptr. August 20, 2007 * Fixed ANTLR-177: hashCode/equals not consistent for label Fixed bug where Rule was compared to string; introduced from dev branch August 15, 2007 -- Got rough draft of the grammar import working. Submit to dev and then integrate into mainline. All file changes/additions: README.txt # edit CHANGES.txt # add Factored out the changes from the readme. runtime/Java/src/org/antlr/runtime/BaseRecognizer.java # edit runtime/Java/src/org/antlr/runtime/DFA.java # edit runtime/Java/src/org/antlr/runtime/Lexer.java # edit runtime/Java/src/org/antlr/runtime/Parser.java # edit runtime/Java/src/org/antlr/runtime/debug/DebugParser.java # edit runtime/Java/src/org/antlr/runtime/tree/TreeParser.java # edit Factored state fields into RecognizerSharedState object. You will see a lot of things like state.errorRecovery = false; runtime/Java/src/org/antlr/runtime/RecognizerSharedState.java # add Shares all recognizer state variables including lexer even though these are superfluous to parsers and tree parsers. There was a casting issue that I could not resolve. src/org/antlr/Tool.java # edit Broke a part Grammar.setGrammarContent() into parseAndBuildAST() and analyzeGrammar() to make the grammar import work. I needed to be able to look at the trees for imported grammars before analyzing them and building DFA. Added use of the CompositeGrammar object and handling of multiple delegate grammars. Changed decision DFA DOT file names to include the grammar name. src/org/antlr/analysis/DFA.java # edit Just tweaked to use generics, updated a comment. src/org/antlr/analysis/DecisionProbe.java # edit Just tweaked to use generics. src/org/antlr/analysis/NFA.java # edit NFA now span multiple grammars and so I moved the NFAs state tracking to the composite grammar object. src/org/antlr/analysis/NFAState.java # edit Added some null checking and made a field public. src/org/antlr/analysis/NFAToDFAConverter.java # edit Changed a method call to directly access a field. src/org/antlr/analysis/RuleClosureTransition.java # edit Instead of using a rule index, which does not span multiple grammars, the transition object now attracts a pointer to the actual Rule definition object. src/org/antlr/analysis/SemanticContext.java # edit Tweaked to use a field instead of a method src/org/antlr/codegen/ActionTranslator.g # edit src/org/antlr/codegen/ActionTranslatorLexer.java # edit Tweaked to use new runtime and they changed method name. src/org/antlr/codegen/CodeGenerator.java # edit Tweaked comments. src/org/antlr/codegen/codegen.g # edit Added import grammar syntax and altered rule atom to pass a scope around so that grammar.rule works. Caution this feature is used internally by ANTLR and is not meant to be used by users at this point. src/org/antlr/codegen/templates/ANTLRCore.sti # edit Added scope to all ruleref template interfaces. src/org/antlr/codegen/templates/Java/Java.stg # edit Grammars can now import other grammars, which I implemented using a delegation pointer to the other grammar(s). So if grammar A imports grammars B and C, then the generated recognizer for A must have delegation pointers to BParser and CParser objects. These are now fields: // delegates Lexer ;}; separator="\n"> Also, B and C must have back pointers to the delegator so that they can refer to rules that have been overridden. This is a mechanism akin to static inheritance: // delegators Lexer ;}; separator="\n"> This file also has a lot of changes so that state variables now are state.backtracking instead of the implied this.backtracking. The file also refers to grammar.delegatedRules attribute which is the list of Rule objects for which you must generate manual delegation. This amounts to a stub whereby rule foo's method foo() simply calls X.foo() if foo is not defined inside the delegator. You will notice that the ruleref templates now take a scope so that I can have implicit rule Tokens referred to delegate.Tokens rule in a delegate grammar. This is the way I do lexer grammar imports. I added a template called delegateName which uses the grammar name to compute a delegate name if the user does not specify a label in the import statement such as: import x=X; Oh, note that rule reference templates all receive a Rule object now instead of the simple rule name as the 'rule' attribute. You will see me doing instead of now. src/org/antlr/codegen/templates/Java/Dbg.stg # edit Changes mirroring the constructor and field stuff from Java.stg. Part of this is a cut and paste because of a bug in ST. src/org/antlr/codegen/templates/Java/AST.stg # edit src/org/antlr/codegen/templates/Java/ASTParser.stg # edit src/org/antlr/codegen/templates/Java/ASTTreeParser.stg # edit Just added the scope attribute. src/org/antlr/test/BaseTest.java # edit Added functionality to support testing composite grammars. execLexer() src/org/antlr/test/TestAttributes.java # edit Tweak to deal with shared recognizer state. src/org/antlr/test/TestCompositeGrammars.java # add Start of my unit tests. src/org/antlr/tool/CompositeGrammar.java # add src/org/antlr/tool/CompositeGrammarTree.java # add Tracks main grammar and all delegate grammars. Tracks unique NFA state numbers and unique token types. This keeps a tree of grammars computed from the import/delegation chain. When you want to look up a rule, it starts at the root of the tree and does a pre-order search to find the rule. src/org/antlr/tool/ActionAnalysis.g # edit src/org/antlr/tool/ActionAnalysisLexer.java # edit src/org/antlr/tool/AttributeScope.java # edit Updated to use generics in one place. src/org/antlr/tool/DOTGenerator.java # edit Updated to indicate when nonlocal rules are referenced. src/org/antlr/tool/ErrorManager.java # edit Added some error messages for import grammars; I need more. src/org/antlr/tool/FASerializer.java # edit Tweaked to use a field not method. src/org/antlr/tool/Grammar.java # edit This is where most of the meat is for the grammar import stuff as you can imagine. I factored out the token type tracking into the CompositeGrammar object. I added code to the addArtificialMatchTokensRule method so that it includes references to all delegate lexer Tokens rules. Altered the rule lookup stuff so that it knows about delegate grammars. src/org/antlr/tool/GrammarAST.java # edit src/org/antlr/tool/GrammarAnalysisAbortedMessage.java # edit src/org/antlr/tool/GrammarReport.java # edit src/org/antlr/tool/NonRegularDecisionMessage.java # edit Made enclosing rule visible as field. src/org/antlr/tool/GrammarSanity.java # edit General cleanup and addition of generics. src/org/antlr/tool/Interpreter.java # edit Reference fields instead of methods. src/org/antlr/tool/NFAFactory.java # edit General cleanup and use of Rule object instead of rule index. src/org/antlr/tool/NameSpaceChecker.java # edit A little bit of cleanup and changes to use either the local or globally visible rule. Added code to check that scopes are valid on scoped rule references. again this is an internal feature, not to be used by users. src/org/antlr/tool/RandomPhrase.java # edit Tweaked. src/org/antlr/tool/Rule.java # edit Added field imported. Removed some unused methods by commenting them out. Made toString() more expressive. src/org/antlr/tool/antlr.g # edit src/org/antlr/tool/antlr.print.g # edit src/org/antlr/tool/assign.types.g # edit src/org/antlr/tool/buildnfa.g # edit src/org/antlr/tool/define.g # edit Added syntax for import statement. assign.types.g is the grammar that invokes Grammar.importGrammar(). src/org/antlr/tool/templates/messages/languages/en.stg # edit Added error messages. Added CHANGES.txt runtime/Java/src/org/antlr/runtime/RecognizerSharedState.java src/org/antlr/test/TestCompositeGrammars.java src/org/antlr/tool/CompositeGrammar.java src/org/antlr/tool/CompositeGrammarTree.java