Hello,

still new ANTLR I ran into a simple return value problem. I would like  
to parse a token sequence and return the matched string.

For example I would like to match the characters "hello" in  "11 hello  
22" and return it as a string. I used $var.getText() and matched with  
something like var=CHAR+.

Unfortunately I was only able to retrieve the last character e.g. "o"  
in "hello"

My full code is attached below.

For any help I would be very thankful.

Toby

sample input:           MYTYPES: name1, name2
sample output:          Type = S
                                          param = 1
                                          param = 2

grammar parse;

@members {
String type;
ArrayList<String> list = new ArrayList<String>();
}

in              :  typeExpression
                {
                  System.out.println("Type = "+type);
                  for(String p:list) {
                    System.out.println(" param = "+p);
                  }
                };
typeExpression  :  '@' var=(CHAR|DIGIT)+ ':' DELIM* param (DELIM* ','  
DELIM* param)*
                {
                   type=$var.getText();
                };
param           :  var=(CHAR|DIGIT)+
                {
                  list.add($var.getText());
                }
                ;

CHAR    :       'a'..'z';
DIGIT   :       '0'..'9';
DELIM   :       ' '|'\t'|'\n';

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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to