<br><font size=2 face="sans-serif">Thanks for the reply but I work in fact
on a grammar where the address *must* be exactly 12 chars :o(</font>
<br>
<br><font size=2 face="sans-serif">I'll try with a global parser attribute.</font>
<br>
<br><font size=2 face="sans-serif">Thanks,</font>
<br><font size=2 face="sans-serif">Loïc</font>
<br>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=34%><font size=4 face="helv"><b>Internet </b></font>
<br><font size=1 face="sans-serif"><b>david-sarah@jacaranda.org</b></font>
<p><font size=1 face="sans-serif"><b>Envoyé par : antlr-interest-bounces@antlr.org</b></font>
<p><font size=1 face="sans-serif">03/12/2009 22:33</font>
<td width=65%>
<table width=100%>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">Pour</font></div>
<td><font size=1 face="sans-serif">antlr-interest@antlr.org</font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">Objet</font></div>
<td><font size=1 face="sans-serif">Re: [antlr-interest] Known bug for antlr
v3.2?</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><font size=2><tt>loic.lefevre@bnpparibas.com wrote:<br>
> Hello,<br>
> while testing some gated semantic predicate:<br>
> <br>
> address<br>
> @init{int n=1;}:<br>
> ( {n<=12}?=> c=CHAR {n++;} )+<br>
> {<br>
> // check for address validity<br>
> final String t = $address.text;<br>
> if( t.length() != 12 ) {<br>
> throw new
InvalidSWIFTBlock1AddressException( t, <br>
> $c.getLine(), $c.getCharPositionInLine() );<br>
> }<br>
> }<br>
> ;<br>
> catch[MismatchedTokenException mte] {
throw new <br>
> InvalidSWIFTBlock1AddressException( mte.token.getText(), mte.line,
<br>
> mte.charPositionInLine ); }<br>
> <br>
> <br>
> I encoutered problem after Java source generation:<br>
[...]<br>
> SWIFTMTParser.java:865: cannot find<br>
> symbol<br>
> symbol : variable n<br>
> location: class <br>
> com.bnpparibas.acetp.foxhound.spec2009.parser.SWIFTMTParser.DFA1<br>
>
else if ( (LA1_23==12) && ((n<=12))) {s = 14;}<br>
<br>
This happens when a predicate referring to a local variable is hoisted<br>
into a DFA class. You can work around it by making 'n' a field of the<br>
parser class (preferably with a more distinct name); then, the DFA1<br>
instance will be able to refer to it because DFA1 is an inner class<br>
of the parser.<br>
<br>
Note that in general this might not work if there are recursive<br>
invocations of the same rule, although that shouldn't be a problem<br>
in this particular case (since <address> only refers to <CHAR>).
There<br>
are similar hazards if you reuse the field across rules.<br>
<br>
Incidentally, for this example it *might* be simpler to eliminate n<br>
and rely on the length check in the action -- this may consume<br>
additional CHARs, but that's not necessarily a problem, given that<br>
the producer of the input may have intended those CHARs to be part<br>
of the address.<br>
<br>
-- <br>
David-Sarah Hopwood ⚥ http://davidsarah.livejournal.com<br>
<br>
<br>
List: http://www.antlr.org/mailman/listinfo/antlr-interest<br>
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address<br>
</tt></font>
<br>
<pre>
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.
</pre>