Thanks for the reply but I work in fact on a grammar where the address *must* be exactly 12 chars :o(
I'll try with a global parser attribute. Thanks, Loïc Internet david-sa...@jacaranda.org Envoyé par : antlr-interest-boun...@antlr.org 03/12/2009 22:33 Pour antlr-interest@antlr.org cc Objet Re: [antlr-interest] Known bug for antlr v3.2? loic.lefe...@bnpparibas.com wrote: > Hello, > while testing some gated semantic predicate: > > address > @init{int n=1;}: > ( {n<=12}?=> c=CHAR {n++;} )+ > { > // check for address validity > final String t = $address.text; > if( t.length() != 12 ) { > throw new InvalidSWIFTBlock1AddressException( t, > $c.getLine(), $c.getCharPositionInLine() ); > } > } > ; > catch[MismatchedTokenException mte] { throw new > InvalidSWIFTBlock1AddressException( mte.token.getText(), mte.line, > mte.charPositionInLine ); } > > > I encoutered problem after Java source generation: [...] > SWIFTMTParser.java:865: cannot find > symbol > symbol : variable n > location: class > com.bnpparibas.acetp.foxhound.spec2009.parser.SWIFTMTParser.DFA1 > else if ( (LA1_23==12) && ((n<=12))) {s = 14;} This happens when a predicate referring to a local variable is hoisted into a DFA class. You can work around it by making 'n' a field of the parser class (preferably with a more distinct name); then, the DFA1 instance will be able to refer to it because DFA1 is an inner class of the parser. Note that in general this might not work if there are recursive invocations of the same rule, although that shouldn't be a problem in this particular case (since <address> only refers to <CHAR>). There are similar hazards if you reuse the field across rules. Incidentally, for this example it *might* be simpler to eliminate n and rely on the length check in the action -- this may consume additional CHARs, but that's not necessarily a problem, given that the producer of the input may have intended those CHARs to be part of the address. -- David-Sarah Hopwood ⚥ http://davidsarah.livejournal.com List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address This message and any attachments (the "message") is intended solely for the addressees and is confidential. If you receive this message in error, please delete it and immediately notify the sender. Any use not in accord with its purpose, any dissemination or disclosure, either whole or partial, is prohibited except formal approval. The internet can not guarantee the integrity of this message. BNP PARIBAS (and its subsidiaries) shall (will) not therefore be liable for the message if modified. Do not print this message unless it is necessary, consider the environment. --------------------------------------------- Ce message et toutes les pieces jointes (ci-apres le "message") sont etablis a l'intention exclusive de ses destinataires et sont confidentiels. Si vous recevez ce message par erreur, merci de le detruire et d'en avertir immediatement l'expediteur. Toute utilisation de ce message non conforme a sa destination, toute diffusion ou toute publication, totale ou partielle, est interdite, sauf autorisation expresse. L'internet ne permettant pas d'assurer l'integrite de ce message, BNP PARIBAS (et ses filiales) decline(nt) toute responsabilite au titre de ce message, dans l'hypothese ou il aurait ete modifie. N'imprimez ce message que si necessaire, pensez a l'environnement. -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to il-antlr-inter...@googlegroups.com. To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
signature.asc
Description: Binary data