[il-antlr-interest: 28602] Re: [antlr-interest] Newbie question, 3.2 Using Syntax to Drive Action Execution

2010-04-26 Thread Gordon Tyler
Your first System.out.println is followed by a curly brace, not a left 
parenthesis.

-Original Message-
From: antlr-interest-boun...@antlr.org 
[mailto:antlr-interest-boun...@antlr.org] On Behalf Of Mark Atherton
Sent: April 26, 2010 3:53 AM
To: antlr-interest@antlr.org
Subject: [antlr-interest] Newbie question, 3.2 Using Syntax to Drive Action 
Execution

Hi All,

I am making my way through The definitive ANTLR reference and have 
managed to get stuck on page 55. I have got through Testing the 
Recognizer without any problems, but adding the changes through page 
55 results in System.out.println not being recognized. Code is at 
http://www.idesignz.org/Antlr/expr.g I have been around the houses 
several times now and need a second pair of eyes to take a look. What 
am I doing that's daft ?

Thanks, Mark


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: 28603] [antlr-interest] Not processing a newline always

2010-04-26 Thread Francesc d'Assis Massanés
Hello,

I am trying to program a complex math program and to process the user
input I have been working in a grammar in antlr.

At this point it works almost as I want it to work but I am missing
something: I do not want to process newlines always.

Let me explain it better: when an expression is finished ( 4+5 ) you can
find a semi-colon or a newline, in any case you just finished this
expression.
But what happens if the expression is incomplete: ( 4+5+ ) then if you find
a semi-colon you have an error (you should not be able to parse this input)
but if you find a newline you should look the next line to follow
processing.

What I want is a rule like: Newline is HIDDEN if some other token is need to
finish the actual rule.

I do not know if it is even possible to do this with antlr or I shall go to
modify the output code.

Thanks,
Francesc Massanés

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: 28604] [antlr-interest] Generate an AST with virtual nodes and conditions

2010-04-26 Thread Loïc Habermacher
Hello everybody,

I am new to ANTLR but as I have to do a quite big project with it, I have
already read a lot of docs (includig the definitive guide) and played with
my first grammars.

I need
- to parse an input like this one : table_name(elem1 blue opt, elem2 blue ,
elem3 red, elem4 red opt);

- to produce an AST like this one : (table_name (WITH_OPT (elem1 blue)
(elem4 red)) (WITHOUT_OPT (elem2 blue) (elem3 red)))
// I want to regroup under the same branch all the elements with opt at the
end and on another branch the elements without opt at the end

- to process the AST

I am stucked with the rewrite rule
table_def
 :
 table_name LEFT_PAREN elem_list RIGHT_PAREN SEMICOLON
 - ^(table_name ^(WITH_OPT elem_list) ^(WITHOUT_OPT elem_list));

How can I communicate with the other rules to have the right content in each
list ?


Thanks
Loïc

*Code*
*
*
*FirstGram.g (to parse and generate the AST)*
grammar FirstGram;

options {
  language = Java;
  output   = AST;
  ASTLabelType = CommonTree;
}
tokens{
WITH_OPT;
WITHOUT_OPT;
}
@header {
  package toy.draft;
}
@lexer::header {
  package toy.draft;
}

table_def
 :
 table_name LEFT_PAREN elem_list RIGHT_PAREN SEMICOLON
 - ^(table_name ^(WITH_OPT elem_list) ^(WITHOUT_OPT elem_list));

elem_list:
elem (COMMA elem)* - elem+;

elem :
elem_name elem_color option?
- ^(elem_name elem_color);

table_name :ID ;
elem_name : ID ;
elem_color : ('blue'|'red');
option : 'opt'  ;

/*--
 * LEXER RULES
 *--*/

LEFT_PAREN : '(';
RIGHT_PAREN : ')';
COMMA : ',';
SEMICOLON : ';';
DOT :  '.';
NUMBER  : (DIGIT)+;
ID  : (('a'..'z'|'A'..'Z' | '_') ((DIGIT)*))+ ;
NEWLINE:'\r'? '\n' { $channel = HIDDEN; };
WS : ( '\t' | ' ' | '\r' | '\n' | '\u000C' )+   { $channel = HIDDEN; } ;
fragment DIGIT :   '0'..'9' ;

*Walker.g (to process the AST)*
tree grammar Walker;

options {
  language = Java;
  tokenVocab = FirstGram;
  ASTLabelType = CommonTree;
  output = template;
  rewrite = true;
}
@header {
  package toy.draft;
}

table_def
  :^(table_name list_with_opt list_without_opt)
  ;

list_with_opt
  : ^(WITH_OPT elem_list)
  ;

 list_without_opt
  : ^(WITHOUT_OPT elem_list)
  ;

table_name :ID ;
elem_list: elem+ ;
elem : elem_name;
elem_name : ID ;

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: 28605] [antlr-interest] VHDL Target

2010-04-26 Thread David Blubaugh
To All,
 
Has anyone developed a VHDL target within ANTLR??  Has any developed a 
translation entity with ANTLR by converting MATLAB or OCTAVE script to VHDL 
supporting coarse-grain parallelism and floating-point support ??  
 
Thanks,
 
David Blubaugh
 
 
 


  

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: 28607] Re: [antlr-interest] ANTLR - Detecting if parsing was successful

2010-04-26 Thread Kunal Sawlani
Hi Ron,
Thanks for the reply. It helped me get few of my doubts cleared as to what I
have to do. It turns out, that the errors that I am trying to catch are the
lexer errors, and not the parser errors. I will look into that, and once I
have the solution I would post back here. If anyone has already dealt with
this issue, any help would be greatly appreciated.
Thanks


On Fri, Apr 23, 2010 at 4:20 PM, Ron Hunter-Duvar 
ron.hunter-du...@oracle.com wrote:

 Hi Kunal,

 There's a getNumberOfSyntaxErrors() method available on the parser object.
 If there were any errors this will return a number greater than zero (though
 I don't believe it includes lexer errors, you have to check separately for
 them). You can test this when the parsing finishes.

 To detect at the end of individual rules, you can test the state.failed
 field. But just looking at the generated code, I don't think testing it in
 the @after will work, because a match failure will result in an early
 return, so the @after won't get executed. I don't know if there's a way to
 tell Antlr to put your code in the finally block to guarantee it always gets
 executed (and if so, you'd probably want to check state.backtracking to see
 if this is a real failure or a failure during backtracking). Otherwise, I
 think you'd need to check in an action in the calling rule (but then that
 action won't be executed until the calling rule succeeds). I'm not sure if
 there's a way to make this work.

 Turning off recovery is a separate issue. I don't know if there's any other
 way than overriding the recover method and possibly some related methods in
 BaseRecognizer.

 Ron



 Kunal Sawlani wrote:

 Hi,
 I am a new to ANTLR and have been trying to detect if the parsing was
 successful or not. As of now, I was using the @after block, which gets
 executed
 only if the parsing was successful. But this block gets executed, even for
 incorrect inputs in the language. I think I am missing something, which I
 must do
 to deactivate the error recovery mechanism, to avoid the after block from
 being executed. Can anyone please guide me to some material on this issue.

 Any help would be greatly appreciated.
 Thanks



 --
 Ron Hunter-Duvar | Software Developer V | 403-272-6580
 Oracle Service Engineering
 Gulf Canada Square 401 - 9th Avenue S.W., Calgary, AB, Canada T2P 3C5

 All opinions expressed here are mine, and do not necessarily represent
 those of my employer.




-- 
Kunal Sawlani

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: 28608] [antlr-interest] Matching Substring In Lexer

2010-04-26 Thread Kunal Sawlani
Hi All,
I have been trying to solve a problem which I have been having in the lexer,
but with no luck. My example goes as follows.
I have a simple grammar with two tokens.
I want to treat the the string $ text as a token TEXTINPUT and everything
else as a token ANYTHING, which matches anything.
The scanning process works fine when you supply it the string $ TEXT, the
correct token is returned. And if any other character is supplied, the token
ANYTHING is returned.
However, for the string $1, the scanner complaints that it was looking for
' ', and no viable alternative for 1. What I want it to return is two tokens
ANYTHING for the $, and another token ANYTHING for 1. I was reading into
the concept of syntactic
predicates to solve this issue, but I am not quiet getting it right. If
anyone could point me in the right direction, it would be great. Also, I
wanted to know if there are any other approaches to solve this issue. I got
the syntactic predicates concept after reading the following article
http://www.jguru.com/faq/view.jsp?EID=459059

http://www.jguru.com/faq/view.jsp?EID=459059Any help would be greatly
appreciated!
Thanks

-- 
Kunal Sawlani

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: 28609] Re: [antlr-interest] Matching Substring In Lexer

2010-04-26 Thread Jim Idle
TEXTINPUT : '$'
  (   ('a'..'z'| 'A'..'Z')+
| { $type = ANYTHING; }
  )
  ;
ANYTHING  : . ;

Jim

 -Original Message-
 From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-
 boun...@antlr.org] On Behalf Of Kunal Sawlani
 Sent: Monday, April 26, 2010 1:41 PM
 To: antlr-interest@antlr.org
 Subject: [antlr-interest] Matching Substring In Lexer
 
 Hi All,
 I have been trying to solve a problem which I have been having in the
 lexer,
 but with no luck. My example goes as follows.
 I have a simple grammar with two tokens.
 I want to treat the the string $ text as a token TEXTINPUT and
 everything
 else as a token ANYTHING, which matches anything.
 The scanning process works fine when you supply it the string $ TEXT,
 the
 correct token is returned. And if any other character is supplied, the
 token
 ANYTHING is returned.
 However, for the string $1, the scanner complaints that it was
 looking for
 ' ', and no viable alternative for 1. What I want it to return is two
 tokens
 ANYTHING for the $, and another token ANYTHING for 1. I was reading
 into
 the concept of syntactic
 predicates to solve this issue, but I am not quiet getting it right. If
 anyone could point me in the right direction, it would be great. Also,
 I
 wanted to know if there are any other approaches to solve this issue. I
 got
 the syntactic predicates concept after reading the following article
 http://www.jguru.com/faq/view.jsp?EID=459059
 
 http://www.jguru.com/faq/view.jsp?EID=459059Any help would be greatly
 appreciated!
 Thanks
 
 --
 Kunal Sawlani
 
 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: 28611] Re: [antlr-interest] Matching Substring In Lexer

2010-04-26 Thread Kunal Sawlani
Hi,
Thanks to both of you, I have something which works now. However, I am
running into a slight issue, where the parser complaints that ANYTHING is
not defined, in case of the grammar Jim suggested, and for John's grammar,
it complaints that TEXTNODE is not defined. I tried defining these using
Fragment, but to no avail. Also, I am using a combined grammar, and will
splitting it into a lexer and parser be necessary?

Thanks for the help. Really appreciate it.

On Mon, Apr 26, 2010 at 5:02 PM, John B. Brodie j...@acm.org wrote:

 Greetings!

 On Mon, 2010-04-26 at 16:40 -0400, Kunal Sawlani wrote:
  Hi All,
  I have been trying to solve a problem which I have been having in the
 lexer,
  but with no luck. My example goes as follows.
  I have a simple grammar with two tokens.
  I want to treat the the string $ text as a token TEXTINPUT and
 everything
  else as a token ANYTHING, which matches anything.
  The scanning process works fine when you supply it the string $ TEXT,
 the
  correct token is returned. And if any other character is supplied, the
 token
  ANYTHING is returned.
  However, for the string $1, the scanner complaints that it was looking
 for
  ' ', and no viable alternative for 1. What I want it to return is two
 tokens
  ANYTHING for the $, and another token ANYTHING for 1. I was reading
 into
  the concept of syntactic
  predicates to solve this issue, but I am not quiet getting it right. If
  anyone could point me in the right direction, it would be great. Also, I
  wanted to know if there are any other approaches to solve this issue. I
 got
  the syntactic predicates concept after reading the following article
  http://www.jguru.com/faq/view.jsp?EID=459059
 
  http://www.jguru.com/faq/view.jsp?EID=459059Any help would be greatly
  appreciated!
  Thanks
 

 see attached






-- 
Kunal Sawlani

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: 28612] Re: [antlr-interest] Matching Substring In Lexer

2010-04-26 Thread John B. Brodie
Greetings!

On Mon, 2010-04-26 at 19:02 -0400, Kunal Sawlani wrote:
 Hi, 
 Thanks to both of you, I have something which works now. However, I am
 running into a slight issue, where the parser complaints that ANYTHING
 is not defined, in case of the grammar Jim suggested, and for John's
 grammar, it complaints that TEXTNODE is not defined. I tried defining
 these using Fragment, but to no avail. Also, I am using a combined
 grammar, and will splitting it into a lexer and parser be necessary?


In the complete and tested example that I posted there are 2 tokens:
ANYTHING and TEXTINPUT. TEXTINPUT is defined in a tokens {} option block
near the top of the file.

As an aside, why did you expect a TEXTNODE token?

In any case, you should be able to run my example through the
org.antlr.Tool, compile the resultant .java files, execute the parser,
and then observe the results.





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: 28613] Re: [antlr-interest] Matching Substring In Lexer

2010-04-26 Thread Kunal Sawlani
Hi John,
I tried out your example and it worked just as expected.
The problem I was having was with the JavaScript target. For some reason,
the statement $type = TEXTNODE, kept reporting the error, TEXTNODE is not
defined. I changed this to use the actual type value(2 in this case) and it
worked!.
I am now confused as to why this is. I know the JavaScript target is new to
ANTLR, but this is something which I guess should be standard across all
platforms. I am not sure if there is any other way to set the type of the
token in the lexer.
Thanks

On Mon, Apr 26, 2010 at 7:20 PM, John B. Brodie j...@acm.org wrote:

 Greetings!

 On Mon, 2010-04-26 at 19:02 -0400, Kunal Sawlani wrote:
  Hi,
  Thanks to both of you, I have something which works now. However, I am
  running into a slight issue, where the parser complaints that ANYTHING
  is not defined, in case of the grammar Jim suggested, and for John's
  grammar, it complaints that TEXTNODE is not defined. I tried defining
  these using Fragment, but to no avail. Also, I am using a combined
  grammar, and will splitting it into a lexer and parser be necessary?


 In the complete and tested example that I posted there are 2 tokens:
 ANYTHING and TEXTINPUT. TEXTINPUT is defined in a tokens {} option block
 near the top of the file.

 As an aside, why did you expect a TEXTNODE token?

 In any case, you should be able to run my example through the
 org.antlr.Tool, compile the resultant .java files, execute the parser,
 and then observe the results.







-- 
Kunal Sawlani

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: 28614] Re: [antlr-interest] VHDL Target

2010-04-26 Thread Bart Kiers



  On Mon, Apr 26, 2010 at 10:02 PM, David Blubaugh 
 davidblubaugh2...@yahoo.comhttp://us.mc1133.mail.yahoo.com/mc/compose?to=davidblubaugh2...@yahoo.com
  wrote:

 To All,

 Has anyone developed a VHDL target within ANTLR??


 Hi, do you really mean a VHDL-target (being able to generate VHDL
 sourcefiles from a given grammar?), or did you mean a VHDL-grammar?

 Regards,

 Bart.


 
 Both

 Thank You

 David


The examples section has a couple of VHDL grammars:
http://www.antlr.org/grammar/list

I'm not familiar with the language itself, but I doubt there is a VHDL
target around (if even possible since it is some sort of of
hardware-modeling language). Why do you need a VHDL-target? What problem are
you trying to solve? Some more info cuold clarify things.

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.