[il-antlr-interest: 23721] Re: [antlr-interest] Modifying tree based on semantic content

2009-05-15 Thread Tilman Bender
Hi David,

I think this is possible with rewrite rules, but it depends on how you  
structure you grammar:

e.g. Have lexer rules for STRING, INT, FLOAT so you could do things like

expr:
a=STRING '+' b=STRING -> ^(CONCATENATE a b)
|   a=number '+' b=number -> ^(PLUS a b)
;

number:
INT
|   FLOAT
;

This is just a quick brain-dump but might give you hints in the right  
direction.

Tilman Bender
Student des Software Engineering
Hochschule Heilbronn
tben...@stud.hs-heilbronn.de



Am 15.05.2009 um 05:38 schrieb David Jameson:

> Is there any way to control the built-in tree generation (from an
> initial parse phase) based on semantics of what is being parsed?
>
> As a simple example,if   I see the expression
>a + b
>
> then I want to produce
> (PLUS a b)
> or
>(CONCATENATE a b)
>
> depending on whether a and b are numeric or string.
>
>
> How can I do this with rewrite rules (for example)?   Or do I have to
> construct my own trees?
>
>
> Thanks,
> D
>
> 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-interest@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


[il-antlr-interest: 23722] Re: [antlr-interest] How do I throw exception on ERROR "no viable alternative at character "

2009-05-15 Thread Tilman Bender
Hi,

Please have a look at the error reporting and recovery page on the wiki:

http://www.antlr.org/wiki/display/ANTLR3/Error+reporting+and+recovery

Maybe you could also override this:
http://www.antlr.org/api/Java/classorg_1_1antlr_1_1runtime_1_1_base_recognizer.html#6c32f5b03a9049357f3ddfbccee9a5e0

Allthough I am not sure this is a good idea.

HTH

Tilman Bender
Student des Software Engineering
Hochschule Heilbronn
tben...@stud.hs-heilbronn.de



Am 15.05.2009 um 06:51 schrieb Bharath R:

> Hi All ,
>
> Currentl when I parse my String , I am getting some errors printed  
> in the console.
>
> Like below : -
>
> line 1:6 no viable alternative at character '?'
> line 1:6 no viable alternative at character ' '
>
> and for the other characters also ( '@' ,',' )
>
> Instead of having the System.err , I need the parser to through the  
> exception.
>
> How Should I achieve this ??
>
>
>
> HUAWEI TECHNOLOGIES CO.,LTD. 
>
>
> Address: Huawei Industrial Base
> Bantian Longgang
> Shenzhen 518129, P.R.China
> www.huawei.com
> -
> This e-mail and its attachments contain confidential information  
> from HUAWEI, which
> is intended only for the person or entity whose address is listed  
> above. Any use of the
> information contained herein in any way (including, but not limited  
> to, total or partial
> disclosure, reproduction, or dissemination) by persons other than  
> the intended
> recipient(s) is prohibited. If you receive this e-mail in error,  
> please notify the sender by
> phone or email immediately and delete it!
>
>
> 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-interest@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


[il-antlr-interest: 23723] Re: [antlr-interest] Modifying tree based on semantic content

2009-05-15 Thread David Jameson
Tilman, thanks for the suggestion. Sadly, that approach will only work  
if a and b are literals. It will not work if the non-terminals a and/ 
or b represent identifiers whose type can only be determined by  
checking the symbol table.



Cheers,
D

On May 15, 2009, at 4:43 AM, Tilman Bender wrote:

> Hi David,
>
> I think this is possible with rewrite rules, but it depends on how  
> you structure you grammar:
>
> e.g. Have lexer rules for STRING, INT, FLOAT so you could do things  
> like
>
> expr:
>   a=STRING '+' b=STRING -> ^(CONCATENATE a b)
> | a=number '+' b=number -> ^(PLUS a b)
> ;
>
> number:
>   INT
> | FLOAT
> ;
>
> This is just a quick brain-dump but might give you hints in the  
> right direction.
>
> Tilman Bender
> Student des Software Engineering
> Hochschule Heilbronn
> tben...@stud.hs-heilbronn.de
>
>
>
> Am 15.05.2009 um 05:38 schrieb David Jameson:
>
>> Is there any way to control the built-in tree generation (from an
>> initial parse phase) based on semantics of what is being parsed?
>>
>> As a simple example,if   I see the expression
>>a + b
>>
>> then I want to produce
>> (PLUS a b)
>> or
>>(CONCATENATE a b)
>>
>> depending on whether a and b are numeric or string.
>>
>>
>> How can I do this with rewrite rules (for example)?   Or do I have to
>> construct my own trees?
>>
>>
>> Thanks,
>> D
>>
>> 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-interest@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


[il-antlr-interest: 23724] Re: [antlr-interest] Modifying tree based on semantic content

2009-05-15 Thread Steve Ebersole

someRule
: a PLUS b
-> { areStrings($a.tree,$b.tree) } ^(CONCATENATE a b)
-> ^(PLUS a b)

On Thu, 2009-05-14 at 23:38 -0400, David Jameson wrote:
> Is there any way to control the built-in tree generation (from an  
> initial parse phase) based on semantics of what is being parsed?
> 
> As a simple example,if   I see the expression
> a + b
> 
> then I want to produce
>  (PLUS a b)
> or
> (CONCATENATE a b)
> 
> depending on whether a and b are numeric or string.
> 
> 
> How can I do this with rewrite rules (for example)?   Or do I have to  
> construct my own trees?
> 
> 
> Thanks,
> D
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: 
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
-- 
Steve Ebersole 
Hibernate.org


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-interest@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: 23725] Re: [antlr-interest] Modifying tree based on semantic content

2009-05-15 Thread David Jameson

I was not aware of this kind of construction. Thank you for bringing  
it to my attention.  Where is there an article that specifically  
discusses this mechanism? I couldn't find it in my ANTLR book nor  
through (a few) google searches?

In other words, what exactly is "areStrings(...)" --- is it just a  
function that returns boolean? I'm assuming that the syntax here  
implies that you can have a sequence of these
 -> {  }   TREE
lines and that ANTRL looks for the first expression in braces that is  
"true"

Is that correct?

D


On May 15, 2009, at 7:26 AM, Steve Ebersole wrote:

> someRule
>: a PLUS b
>-> { areStrings($a.tree,$b.tree) } ^(CONCATENATE a b)
>-> ^(PLUS a b)
>
> On Thu, 2009-05-14 at 23:38 -0400, David Jameson wrote:
>> Is there any way to control the built-in tree generation (from an
>> initial parse phase) based on semantics of what is being parsed?
>>
>> As a simple example,if   I see the expression
>>a + b
>>
>> then I want to produce
>> (PLUS a b)
>> or
>>(CONCATENATE a b)
>>
>> depending on whether a and b are numeric or string.
>>
>>
>> How can I do this with rewrite rules (for example)?   Or do I have to
>> construct my own trees?
>>
>>
>> Thanks,
>> D
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe: 
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> -- 
> Steve Ebersole 
> Hibernate.org
>


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-interest@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: 23726] Re: [antlr-interest] Modifying tree based on semantic content

2009-05-15 Thread Steve Ebersole

On Fri, 2009-05-15 at 07:34 -0400, David Jameson wrote:
> I was not aware of this kind of construction. Thank you for bringing  
> it to my attention.  Where is there an article that specifically  
> discusses this mechanism? I couldn't find it in my ANTLR book nor  
> through (a few) google searches?
> 
> In other words, what exactly is "areStrings(...)" --- is it just a  
> function that returns boolean? I'm assuming that the syntax here  
> implies that you can have a sequence of these
>  -> {  }   TREE
> lines and that ANTRL looks for the first expression in braces that is  
> "true"
Here specifically I would assume that areStrings(...) would be a grammar
member function so that the types of the 'a' and 'b' expressions could
be determined.  But in general yes, the fragment inside {} just needs to
evaluate to a boolean value.  I believe these are called rewrite
predicates(?).  And yes, just like regular predicates you can list
multiples and the first match will "win".

> Is that correct?
> 
> D
> 
> 
> On May 15, 2009, at 7:26 AM, Steve Ebersole wrote:
> 
> > someRule
> >: a PLUS b
> >-> { areStrings($a.tree,$b.tree) } ^(CONCATENATE a b)
> >-> ^(PLUS a b)
> >
> > On Thu, 2009-05-14 at 23:38 -0400, David Jameson wrote:
> >> Is there any way to control the built-in tree generation (from an
> >> initial parse phase) based on semantics of what is being parsed?
> >>
> >> As a simple example,if   I see the expression
> >>a + b
> >>
> >> then I want to produce
> >> (PLUS a b)
> >> or
> >>(CONCATENATE a b)
> >>
> >> depending on whether a and b are numeric or string.
> >>
> >>
> >> How can I do this with rewrite rules (for example)?   Or do I have to
> >> construct my own trees?
> >>
> >>
> >> Thanks,
> >> D
> >>
> >> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> >> Unsubscribe: 
> >> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> > -- 
> > Steve Ebersole 
> > Hibernate.org
> >
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: 
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
-- 
Steve Ebersole 
Hibernate.org


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-interest@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: 23727] [antlr-interest] Lexer matching non-matching rule

2009-05-15 Thread Jesper Larsson

Sorry if this is a stupid question, but if it is I hope it has a quick
stupid answer.

My ANTLR-generated lexer protests about unexpected characters in a
situation where it could have matched the input with other rules. My
understanding of ANTLR and other tools that generate lexers is that it
should use the rule that matches the most from the input, but here it
seems to pick a rule that does NOT match the input. Why does it do that?

Here is a pretty much minimal example that produces the problem:

===
grammar Y;
options { output=AST; }

file
: IDENT DOT EOF
;

IDENT:  ('a'..'z' | 'A'..'Z')+;
DOT:'.';
WHITESPACE: ('\f' | '\n' | '\r' | '\t' | ' ')+
{ $channel = HIDDEN; };

URL:('a'..'z') ('a'..'z' | '0'..'9' | '+' | '-' | '.')* ':'
~('\f' | '\n' | '\r' | '\t' | ' ')*;
===

Here is a sample input:

===
foo.
===

I get the following complaint when using the lexer + parser:

line 1:4 mismatched character '\n' expecting ':'

But if I remove the URL lexer rule (which is not used by the parser),
the sample goes through just fine.

Can somebody explain this? Should not the lexer just bail out of the
URL rule when the input does not match it?

J'




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-interest@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: 23728] Re: [antlr-interest] Lexer matching non-matching rule

2009-05-15 Thread Michael

Am Friday 15 May 2009 14:03:16 schrieb Jesper Larsson:

>
> URL:('a'..'z') ('a'..'z' | '0'..'9' | '+' | '-' | '.')* ':'
> ~('\f' | '\n' | '\r' | '\t' | ' ')*;

if you leave out the dot in the URL rule it works as it should. 
If the dot is there the IDENT rule is not called but the URL rule is called 
which raises an exception since the colon is missing.
No idea why .

cheers
 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-interest@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: 23729] [antlr-interest] ANTLR 3 grammar for C++

2009-05-15 Thread Mark Volkmann

I'm looking for an ANTLR 3 grammar for C++. Does one exist?

-- 
R. Mark Volkmann
Object Computing, Inc.

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-interest@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: 23730] Re: [antlr-interest] Modifying tree based on semantic content

2009-05-15 Thread David Jameson

I hate to bother you with more on this but I ran into difficulty when  
I tried to translate the simple question/response into my real grammar.


My actual rule in my grammar is below --- I added two rewrite  
predicates, the idea being that if the type of LHS is a string, then  
my tree will have an extra token in it, making the tree parser grammar  
trivial.

However, when I try to generate the grammar from this, I get the error
 expecting RPAREN, found  '->'
and the row/col value indicates the beginning of the second predicate

I'm probably missing something stupid here but I can't see it.

D

--




expression returns [TAttributeType type]
 :
 optionalSign
 lhs = simpleExpression
{
   $type = $lhs.type;
}
(
 (comparisonOperator^ rhs = simpleExpression)   
 {
$type =  
TErrorHandling.Compatible($comparisonOperator.tree.token,  
$comparisonOperator.token, $lhs.type, $rhs.type);
 } -> { isString($lhs.tree) } ^(comparisonOperator  
STRINGCOMPARE lhs rhs)
   -> ^(comparisonOperator lhs rhs)
)*  
;


comparisonOperator returns [int token]
   : EQ { $token = EQ; }
   | NE { $token = NE; }
   | LT { $token = LT; }
   | LE { $token = LE; }
   | GT { $token = GT; }
   | GE { $token = GE; }





On May 15, 2009, at 7:57 AM, Steve Ebersole wrote:

> On Fri, 2009-05-15 at 07:34 -0400, David Jameson wrote:
>> I was not aware of this kind of construction. Thank you for bringing
>> it to my attention.  Where is there an article that specifically
>> discusses this mechanism? I couldn't find it in my ANTLR book nor
>> through (a few) google searches?
>>
>> In other words, what exactly is "areStrings(...)" --- is it just a
>> function that returns boolean? I'm assuming that the syntax here
>> implies that you can have a sequence of these
>> -> {  }   TREE
>> lines and that ANTRL looks for the first expression in braces that is
>> "true"
> Here specifically I would assume that areStrings(...) would be a  
> grammar
> member function so that the types of the 'a' and 'b' expressions could
> be determined.  But in general yes, the fragment inside {} just  
> needs to
> evaluate to a boolean value.  I believe these are called rewrite
> predicates(?).  And yes, just like regular predicates you can list
> multiples and the first match will "win".
>
>> Is that correct?
>>
>> D
>>
>>
>> On May 15, 2009, at 7:26 AM, Steve Ebersole wrote:
>>
>>> someRule
>>>   : a PLUS b
>>>   -> { areStrings($a.tree,$b.tree) } ^(CONCATENATE a b)
>>>   -> ^(PLUS a b)
>>>
>>> On Thu, 2009-05-14 at 23:38 -0400, David Jameson wrote:
 Is there any way to control the built-in tree generation (from an
 initial parse phase) based on semantics of what is being parsed?

 As a simple example,if   I see the expression
   a + b

 then I want to produce
(PLUS a b)
 or
   (CONCATENATE a b)

 depending on whether a and b are numeric or string.


 How can I do this with rewrite rules (for example)?   Or do I  
 have to
 construct my own trees?


 Thanks,
 D

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


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-interest@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: 23731] Re: [antlr-interest] Modifying tree based on semantic content

2009-05-15 Thread David Jameson

Hmmm,  answering my own question, it looks like you have to put a ?  
after the predicate

D

On May 15, 2009, at 7:57 AM, Steve Ebersole wrote:

> On Fri, 2009-05-15 at 07:34 -0400, David Jameson wrote:
>> I was not aware of this kind of construction. Thank you for bringing
>> it to my attention.  Where is there an article that specifically
>> discusses this mechanism? I couldn't find it in my ANTLR book nor
>> through (a few) google searches?
>>
>> In other words, what exactly is "areStrings(...)" --- is it just a
>> function that returns boolean? I'm assuming that the syntax here
>> implies that you can have a sequence of these
>> -> {  }   TREE
>> lines and that ANTRL looks for the first expression in braces that is
>> "true"
> Here specifically I would assume that areStrings(...) would be a  
> grammar
> member function so that the types of the 'a' and 'b' expressions could
> be determined.  But in general yes, the fragment inside {} just  
> needs to
> evaluate to a boolean value.  I believe these are called rewrite
> predicates(?).  And yes, just like regular predicates you can list
> multiples and the first match will "win".
>
>> Is that correct?
>>
>> D
>>
>>
>> On May 15, 2009, at 7:26 AM, Steve Ebersole wrote:
>>
>>> someRule
>>>   : a PLUS b
>>>   -> { areStrings($a.tree,$b.tree) } ^(CONCATENATE a b)
>>>   -> ^(PLUS a b)
>>>
>>> On Thu, 2009-05-14 at 23:38 -0400, David Jameson wrote:
 Is there any way to control the built-in tree generation (from an
 initial parse phase) based on semantics of what is being parsed?

 As a simple example,if   I see the expression
   a + b

 then I want to produce
(PLUS a b)
 or
   (CONCATENATE a b)

 depending on whether a and b are numeric or string.


 How can I do this with rewrite rules (for example)?   Or do I  
 have to
 construct my own trees?


 Thanks,
 D

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


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-interest@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: 23732] Re: [antlr-interest] How do I throw exception on ERROR "no viable alternative at character "

2009-05-15 Thread Bharath R
Thanx a lot.  Its working fine ! 
 
I have overridden the below method in the parser and lexer code generated. 
 
public void displayRecognitionError
 (String[]
tokenNames,RecognitionException
  e)

The exception can be handled , but i am facing 2 below issues 
 
1. getting the passed input from the Lexer code. 
Let say I have passed the string input , but from the lexer code I cant
able to get the "input" string passed. 
I am expecting the same behaviour as the paser . ( where the input
variable is accessible ). 
 
2. Embedding the code to lexer , when i override the method in the grammar
file. Its inserted only in the parser code not 
in the lexer code. 
 
HUAWEI TECHNOLOGIES CO.,LTD. huawei_logo 


Address: Huawei Industrial Base
Bantian Longgang
Shenzhen 518129, P.R.China
www.huawei.com

-
This e-mail and its attachments contain confidential information from
HUAWEI, which 
is intended only for the person or entity whose address is listed above. Any
use of the 
information contained herein in any way (including, but not limited to,
total or partial 
disclosure, reproduction, or dissemination) by persons other than the
intended 
recipient(s) is prohibited. If you receive this e-mail in error, please
notify the sender by 
phone or email immediately and delete it!

 

  _  

From: antlr-interest-boun...@antlr.org
[mailto:antlr-interest-boun...@antlr.org] On Behalf Of Tilman Bender
Sent: Friday, May 15, 2009 2:21 PM
To: antlr-inter...@antlr.org
Subject: Re: [antlr-interest] How do I throw exception on ERROR "no viable
alternative at character "


Hi, 

Please have a look at the error reporting and recovery page on the wiki:

http://www.antlr.org/wiki/display/ANTLR3/Error+reporting+and+recovery

Maybe you could also override this:
http://www.antlr.org/api/Java/classorg_1_1antlr_1_1runtime_1_1_base_recogniz
er.html#6c32f5b03a9049357f3ddfbccee9a5e0

Allthough I am not sure this is a good idea.

HTH

Tilman Bender
Student des Software Engineering
Hochschule Heilbronn
tben...@stud.hs-heilbronn.de



Am 15.05.2009 um 06:51 schrieb Bharath R:


Hi All ,
 
Currentl when I parse my String , I am getting some errors printed in the
console. 
 
Like below : - 
 
line 1:6 no viable alternative at character '?'

line 1:6 no viable alternative at character ' '
 
and for the other characters also ( '@' ,',' ) 
 
Instead of having the System.err , I need the parser to through the
exception. 
 
How Should I achieve this ?? 
 


HUAWEI TECHNOLOGIES CO.,LTD.  


Address: Huawei Industrial Base
Bantian Longgang
Shenzhen 518129, P.R.China
www.huawei.com

-
This e-mail and its attachments contain confidential information from
HUAWEI, which 
is intended only for the person or entity whose address is listed above. Any
use of the 
information contained herein in any way (including, but not limited to,
total or partial 
disclosure, reproduction, or dissemination) by persons other than the
intended 
recipient(s) is prohibited. If you receive this e-mail in error, please
notify the sender by 
phone or email immediately and delete it!

 

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-interest@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


[il-antlr-interest: 23733] Re: [antlr-interest] How do I throw exception on ERROR "no viable alternative at character "

2009-05-15 Thread Tilman Bender
Hi,

Good to hear it works for you. But you probably shouldn't do that in  
the generated code or it will be gone
once you need to regenerate the Praser/Lexer in case you change  
something. Instead you should do
the overriding in a @members{} block like it is described on the wiki- 
page.

hth

Tilman Bender
Student des Software Engineering
Hochschule Heilbronn
tben...@stud.hs-heilbronn.de



Am 15.05.2009 um 16:07 schrieb Bharath R:

> I have overridden the below method in the parser and lexer code  
> generated.


--~--~-~--~~~---~--~~
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-interest@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


[il-antlr-interest: 23734] [antlr-interest] How to free ANTLR3_STRING (c runtime)?

2009-05-15 Thread Chetty, Jay

What's the right way to free the ANTLR3_STRING returned from
pANTLR3TOKEN_STREAM's toStringSS()


I used destroy method of the string factory and it seems that's not the right 
way
As I get these lines when my executable exists.

*** glibc detected *** double free or corruption (fasttop): 0x081514b8 ***
*** glibc detected *** double free or corruption (!prev): 0x081641a8 ***

Thanks
+Jay

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-interest@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: 23735] Re: [antlr-interest] How to free ANTLR3_STRING (c runtime)?

2009-05-15 Thread Jim Idle

Chetty, Jay wrote:
> What's the right way to free the ANTLR3_STRING returned from
> pANTLR3TOKEN_STREAM's toStringSS()
>
>
> I used destroy method of the string factory and it seems that's not the right 
> way
> As I get these lines when my executable exists.
>
> *** glibc detected *** double free or corruption (fasttop): 0x081514b8 ***
> *** glibc detected *** double free or corruption (!prev): 0x081641a8 ***
>   
The correct way is to do nothing at all:-). The string factory tracks 
the memory and releases it once you close the factory. The factory will 
be created by the token or node stream and will be closed when you free 
the token or node stream.

Note that the string factory stuff is basically convenience methods for 
things like toStringTree(). If you need pure performance, then you 
should access the token structures yourself.

You can use valgrind to check that all your memory is being freed correctly.

Also note that while making a string from the AST is a quick way of 
looking at your tree, you might find the dot generator and the dot 
program much more useful (install graphviz from your distro or 
www.graphviz.org).

To use it from C, you just do this:

pANTLR3_STRINGdotSpec;
dotSpec = nodes->adaptor->makeDot(nodes->adaptor, psrReturn.tree);

Where nodes is the pANTLR3_COMMON_TREE_NODE_STREAM and psrReturn is the 
return type of the rule you invoke on your parser.

You can then fwrite the spec to a text file:

dotSpec = dotSpec->toUTF8(dotSpec);   // Only need this if your input 
was not 8 bit characters
fwrite((const void *) dotSpec->chars, 1, (size_t) dotSpec->len, dotFILE);

Then turn this in to a neat png graphic like this:

sprintf(command, "dot -Tpng -o%spng %sdot", dotFname, dotFname);
system(command)

Jim

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-interest@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: 23736] Re: [antlr-interest] How to free ANTLR3_STRING (c runtime)?

2009-05-15 Thread Chetty, Jay

Jim thanks for the reply.

My understanding was also that string factory will manage the life time of the 
strings it created.
But ran into out of memory issue on a 32 bit machine, so thought of freeing up 
some strings that 
Were created while forward looking some tokens during error reporting.

As you suggested I will access the token structure directly.

And thanks for info on dot generator , I will give it a try.

Note:
By the way the toStringSS() function doesn't check for the pointer returned by 
the string factory 
(so and seg faults when out of memory).


static pANTLR3_STRING   
toStringSS   (pANTLR3_TOKEN_STREAM ts, ANTLR3_UINT32 start, ANTLR3_UINT32 stop)
{
...

string  = tsource->strFactory->newRaw(tsource->strFactory);

for (i = start; i <= stop; i++)
{
tok = ts->get(ts, i);

if  (tok != NULL)
{
string->appendS(string, tok->getText(tok));
}
}

...
}

Thanks
+Jay
 
-Original Message-
From: antlr-interest-boun...@antlr.org 
[mailto:antlr-interest-boun...@antlr.org] On Behalf Of Jim Idle
Sent: Friday, May 15, 2009 10:54 AM
Cc: antlr-inter...@antlr.org
Subject: Re: [antlr-interest] How to free ANTLR3_STRING (c runtime)?

Chetty, Jay wrote:
> What's the right way to free the ANTLR3_STRING returned from
> pANTLR3TOKEN_STREAM's toStringSS()
>
>
> I used destroy method of the string factory and it seems that's not the right 
> way
> As I get these lines when my executable exists.
>
> *** glibc detected *** double free or corruption (fasttop): 0x081514b8 ***
> *** glibc detected *** double free or corruption (!prev): 0x081641a8 ***
>   
The correct way is to do nothing at all:-). The string factory tracks 
the memory and releases it once you close the factory. The factory will 
be created by the token or node stream and will be closed when you free 
the token or node stream.

Note that the string factory stuff is basically convenience methods for 
things like toStringTree(). If you need pure performance, then you 
should access the token structures yourself.

You can use valgrind to check that all your memory is being freed correctly.

Also note that while making a string from the AST is a quick way of 
looking at your tree, you might find the dot generator and the dot 
program much more useful (install graphviz from your distro or 
www.graphviz.org).

To use it from C, you just do this:

pANTLR3_STRINGdotSpec;
dotSpec = nodes->adaptor->makeDot(nodes->adaptor, psrReturn.tree);

Where nodes is the pANTLR3_COMMON_TREE_NODE_STREAM and psrReturn is the 
return type of the rule you invoke on your parser.

You can then fwrite the spec to a text file:

dotSpec = dotSpec->toUTF8(dotSpec);   // Only need this if your input 
was not 8 bit characters
fwrite((const void *) dotSpec->chars, 1, (size_t) dotSpec->len, dotFILE);

Then turn this in to a neat png graphic like this:

sprintf(command, "dot -Tpng -o%spng %sdot", dotFname, dotFname);
system(command)

Jim

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-interest@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: 23737] [antlr-interest] Hopefully just a little more help with syntax for semantic predicates?

2009-05-15 Thread dhjdhj

I have been trying all day to get the rule below accepted (oh yeah,  
that doesn't count about 2 hours wasted before I figured out that you  
can't have a space after the right curly brace and the question mark  
in a semantic predicate  (grin))

I get a "cannot generate the grammar because" error  which is

 rule expression alt 1 uses rewrite syntax and also an AST operator

Now, I'm pretty certain this is happening because of the "^" that  
follows lhs = simpleExpression^ in the first section of the rule.

However, removing that operator causes no tree node to be generated in  
the case where there is just a simple expression.  However, I tried  
removing that operator and adding a rewrite rule after the FIRST  
closing right brace, e.g.

lhs = simpleExpression
   {
  $type = $lhs.type;
   } -> ^($lhs)

and many variants but this just caused ANTLR to complain that  
comparisonOperator was an unexpected token.  I also tried inserting a  
third predicate in the bottom group that would test whether $rhs was  
null and just put out the $lhs in that case but that didn't work either.

Can somebody please put me out of my misery (in a kind manner (grin))  
and show me what I'm doing wrong? I'd love to have a quiet weekend  
with no problems to worry about!!!

Thanks,
D

--







expression returns [TAttributeType type]
:
optionalSign
lhs = simpleExpression^
   {
  $type = $lhs.type;
   }
   (
(comparisonOperator rhs = simpleExpression) 
{
   $type =  
TErrorHandling.Compatible($comparisonOperator.tree.token,  
$comparisonOperator.token, $lhs.type, $rhs.type);
}

  -> { isString($lhs.type) }? ^(comparisonOperator  
STRINGOP $lhs $rhs)
  ->  ^(comparisonOperator $lhs $rhs)
   )*   
;


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-interest@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: 23738] Re: [antlr-interest] How to free ANTLR3_STRING (c runtime)?

2009-05-15 Thread Jim Idle

Chetty, Jay wrote:
> Jim thanks for the reply.
>
> My understanding was also that string factory will manage the life time of 
> the strings it created.
> But ran into out of memory issue on a 32 bit machine, so thought of freeing 
> up some strings that 
> Were created while forward looking some tokens during error reporting.
>   
> As you suggested I will access the token structure directly.
>   
It is better if you are building big outputs, but string factory is fine 
for smaller outputs where you just want something that looks after 
memory for you and so on.
> And thanks for info on dot generator , I will give it a try.
>
> Note:
> By the way the toStringSS() function doesn't check for the pointer returned 
> by the string factory 
> (so and seg faults when out of memory).
>   
It probably should, but you must be creating some huge structure for it 
to run out of memory. What are you parsing?

Or do you have your ulimits very low or something? Make sure you are are 
running 3.1.3 runtime as this has a fair bit of memory optimization on 
tree building.


Jim

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-interest@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: 23741] Re: [antlr-interest] Lexer matching non-matching rule

2009-05-15 Thread Indhu Bharathi




This is because on seeing 'f' of foo lexer has two options - 1. IDENT
2. URL. And it takes the second options since that seems to be longer
that the first alternative. Note that the lexer always tries to match
the longest token possible. 

After having decided to go for URL, it matches the input with URL and
it fails. Lexer doesn't backtrack and hence throws an exception. 

In your case you can use semantic predicates to validate whether 'URL'
exists before matching the input with URL. You can refactor the code
similar to the one shown below:

grammar Test;

options { output=AST; }

file
    : IDENT DOT EOF
    ;


DOT:    '.';

WHITESPACE: ('\f' | '\n' | '\r' | '\t' | ' ')+
    { $channel = HIDDEN; };


URL_OR_IDENT    :    (FRAG_URL) =>FRAG_URL
            { $type = URL; }
        |    (FRAG_IDENT) => FRAG_IDENT
            { $type = IDENT; }
        ;

fragment IDENT
    :    ;

fragment URL
    :    ;

fragment
FRAG_IDENT:  ('a'..'z' | 'A'..'Z')+;

fragment
FRAG_URL:    ('a'..'z') ('a'..'z' | '0'..'9' | '+' | '-' |
'.')* ':'
    ~('\f' | '\n' | '\r' | '\t' | ' ')*;
    
    
Hope that helps.

Cheers, Indhu

Michael wrote:

  Am Friday 15 May 2009 14:03:16 schrieb Jesper Larsson:

  
  
URL:('a'..'z') ('a'..'z' | '0'..'9' | '+' | '-' | '.')* ':'
~('\f' | '\n' | '\r' | '\t' | ' ')*;

  
  
if you leave out the dot in the URL rule it works as it should. 
If the dot is there the IDENT rule is not called but the URL rule is called 
which raises an exception since the colon is missing.
No idea why .

cheers
 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-interest@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


[il-antlr-interest: 23740] Online Dating and friend finder

2009-05-15 Thread manju

Online Dating and friend finder

http://friendfinder.com/go/g1100916

http://friendfinder.com/go/g1100916
--~--~-~--~~~---~--~~
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-interest@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
-~--~~~~--~~--~--~---