[il-antlr-interest: 31235] [antlr-interest] Use of multimap in grammar file.

2011-01-26 Thread Alfredo Perez J.
Hello.

I am trying to make a not too complicated translator using ANTLR, the
aproach I'm taking makes use of Multimaps in the grammar file.
However I'm having some trouble initializing them, here's how I do it:

grammar FSM;

options {output=template;}

@header {
import org.antlr.stringtemplate.*;
import org.antlr.misc.MultiMap;

}
model
scope{
   Multimap Integer, String CMap;
   Multimap Integer, String UMap;
}

@init {
  $model::UMap = HashMultimap.create();
  $model::CMap = HashMultimap.create();

}

 : RULES
  - RewriteRule
;

...

When I try to debug that in ANTLWorks, or try to build project in NetBeans I
get the following error:

error(104):  cannot find an attribute name in attribute declaration
java.lang.StringIndexOutOfBoundsException: String index out of range: -1

Which seems to be a problem with the angled brackets or something. Because
If I comment out /*Multimap Integer, String CMap*/ the error goes away.
What would be a correct way to initialize a Multimap visible to that scope?

For your time, thank you.

 - APJ

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
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.



[il-antlr-interest: 31236] Re: [antlr-interest] Use of multimap in grammar file.

2011-01-26 Thread Alfredo Perez J.
Nevermind that previous post (accidentally doubled btw). My mind  after many
hours couldn't see an extra ; that was  there which caused the error.

Now I have a different quesiton if you mind.

I have some expression like this:

TRANSITION IDENTIFIER TO IDENTIFIER transFlags

Now what I want in this step is store IDENTIFIER.text from the left side and
IDENTIFIER.text from the right side, but how can I tell one from the other?
Tried something like this:

TRANSITION IDENTIFIER {Auxiliar = {$IDENTIFIER.text}} TO IDENTIFIER
transFlags

Auxiliar beign a String but I get the error: IDENTIFIER is a non-unique
reference.
I can't define some sort of LeftIdentifier because it's the same rule and
it won't be matched.

Any idea how can I differenciate these Identifiers?

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
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.



[il-antlr-interest: 31237] Re: [antlr-interest] Use of multimap in grammar file.

2011-01-26 Thread Gordon Tyler
rule: TRANSITION id1=IDENTIFIER TO id2=IDENTIFIER transFlags

Then you can use id1 and id2 as references to their respective tokens in the 
post-rule code block.

 -Original Message-
 From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-
 boun...@antlr.org] On Behalf Of Alfredo Perez J.
 Sent: Wednesday, January 26, 2011 12:41 PM
 To: antlr-interest@antlr.org
 Subject: Re: [antlr-interest] Use of multimap in grammar file.
 
 Nevermind that previous post (accidentally doubled btw). My mind  after
 many
 hours couldn't see an extra ; that was  there which caused the error.
 
 Now I have a different quesiton if you mind.
 
 I have some expression like this:
 
 TRANSITION IDENTIFIER TO IDENTIFIER transFlags
 
 Now what I want in this step is store IDENTIFIER.text from the left
 side and
 IDENTIFIER.text from the right side, but how can I tell one from the
 other?
 Tried something like this:
 
 TRANSITION IDENTIFIER {Auxiliar = {$IDENTIFIER.text}} TO IDENTIFIER
 transFlags
 
 Auxiliar beign a String but I get the error: IDENTIFIER is a non-unique
 reference.
 I can't define some sort of LeftIdentifier because it's the same rule
 and
 it won't be matched.
 
 Any idea how can I differenciate these Identifiers?
 
 List: http://www.antlr.org/mailman/listinfo/antlr-interest
 Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
 email-address

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
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.



[il-antlr-interest: 31238] [antlr-interest] Many unused variables in the generated parser c file

2011-01-26 Thread Sunil Sawkar
Hi,

Any suggestions as to how I can prevent unused variable declarations within 
the generated parser c file ? 

Thanks,
-Sunil Sawkar

Following is an example warning from compiler, and the related source in the c 
file:

compiler warning:

algoexprParser.c:5462: warning: unused variable ‘LA2_2’
algoexprParser.c:5476: warning: unused variable ‘LA2_3’

source:
for (;;)
{
int alt2=2;
switch ( LA(1) ) 
{
case VARIABLE:
case LABEL_NOT_VAR:
{
{
   /* 
dfaLoopbackState(k,edges,eotPredictsAlt,description,stateNumber,semPredState)
*/
int LA2_2 = LA(2);
if ( (synpred2_algoexpr(ctx)) ) 
{
alt2=1;
}

}
}
break;
case 72:
{
{
   /* 
dfaLoopbackState(k,edges,eotPredictsAlt,description,stateNumber,semPredState)
*/
int LA2_3 = LA(2);
if ( (synpred2_algoexpr(ctx)) ) 
{
alt2=1;
}

}
}
break;
.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
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.



[il-antlr-interest: 31240] [antlr-interest] org.antlr.runtime.CommonToken cannot be cast to org.antlr.runtime.tree.Tree

2011-01-26 Thread Ching
Can anyone tell me why I got this exception? My output is AST. Thanks.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
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.



[il-antlr-interest: 31241] Re: [antlr-interest] org.antlr.runtime.CommonToken cannot be cast to org.antlr.runtime.tree.Tree

2011-01-26 Thread Bart Kiers
On Wed, Jan 26, 2011 at 10:40 PM, Ching zchin...@gmail.com wrote:

 Can anyone tell me why I got this exception? My output is AST. Thanks.


Err, that error is pretty self-explanatory: you're trying to cast
a org.antlr.runtime.CommonToken to a org.antlr.runtime.tree.Tree, which is
illegal. As you can see from ANTLR's class hierarchy:
http://www.antlr.org/api/Java/hierarchy.html
the two can't be cast (either CommonToken-Tree or Tree-CommonToken).

Perhaps you don't understand where this happens in your grammar? In that
case, please show your grammar as well.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
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.



[il-antlr-interest: 31242] Re: [antlr-interest] org.antlr.runtime.CommonToken cannot be cast to org.antlr.runtime.tree.Tree

2011-01-26 Thread Piotr Kaleta
You might need to introduce the Tree adaptor if you're using the custom type
of tree nodes. It's described here:
http://www.antlr.org/wiki/display/ANTLR3/Tree+construction

On Thu, Jan 27, 2011 at 8:57 AM, Bart Kiers bki...@gmail.com wrote:

 On Wed, Jan 26, 2011 at 10:40 PM, Ching zchin...@gmail.com wrote:

  Can anyone tell me why I got this exception? My output is AST. Thanks.
 
 
 Err, that error is pretty self-explanatory: you're trying to cast
 a org.antlr.runtime.CommonToken to a org.antlr.runtime.tree.Tree, which is
 illegal. As you can see from ANTLR's class hierarchy:
 http://www.antlr.org/api/Java/hierarchy.html
 the two can't be cast (either CommonToken-Tree or Tree-CommonToken).

 Perhaps you don't understand where this happens in your grammar? In that
 case, please show your grammar as well.

 Regards,

 Bart.

 List: http://www.antlr.org/mailman/listinfo/antlr-interest
 Unsubscribe:
 http://www.antlr.org/mailman/options/antlr-interest/your-email-address




-- 
Piotr Kaleta

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
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.



[il-antlr-interest: 31243] [antlr-interest] best practice for unwanted input before EOF

2011-01-26 Thread Michael Bedward
Hi folks,

I have a grammar with the following start rule...

prog: (init_block)? statement+ EOF ;

The purpose of the EOF token is to detect unwanted input after
statements. I'm unclear on the best way to respond to input that is
unwanted but, because it is defined in the grammar, does not provoke a
NoViableAlt exception such as an init_block following rather than
preceding the statements.

At the moment I'm doing this in the @members section of my grammar...

@Override
protected Object recoverFromMismatchedToken(IntStream input, int
ttype, BitSet follow) throws RecognitionException {
if (ttype == Token.EOF) {
throw new UnexpectedInputException(Invalid input before end of file);
}
return super.recoverFromMismatchedToken(input, ttype, follow);
}

It works, but it seems like a clunky solution.

I've searched the list archives and scanned the Definitive Reference
and Patterns books without success, although I suspect I must be
missing something obvious.

I'd be grateful for any examples or pointers to docs.

Michael

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
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.



[il-antlr-interest: 31244] [antlr-interest] Set line/col of synthetic token from non-token

2011-01-26 Thread Bill Andersen
Folks,

I have this production

formula
  : outer_formula nle?
- ^(STMT[???,STMT] 
  ;

where STMT is a synthetic token.  Question is how to pass info for line/col 
from whatever matches 'outer_formula' to where the STMT synthetic token is 
created in adaptor.create(...).  I get a tree for outer_formula, not a token.  
I know how to do this with tokens.

Any help appreciated.

.bill

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
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.