[il-antlr-interest: 27677] [antlr-interest] Disabling rules in the lexer

2010-01-26 Thread Jeff Wilcox
Hi,

I have a special area in this language that has symbols within a table 
structure that are normally used in other tokens in other areas of the language 
(like a couple digits, a couple letters and a couple symbols).  So I am trying 
to setup the lexer to accept these table tokens only when in a table.  Based on 
what I have been able to dig up, I believe gated semantic predicates are a 
valid way to disable rules in the lexer.  However, I am seeing issues with this 
with ANTLR 3.2 and the java language target.  

So I expected a lexer rules like this to do the trick:  

Level0   : {inTable}?= '0';

But that actually creates a very strange loop when inTable is false.  I 
basically throws a FailedPredicateException (which I would not have expected 
for a gated predicate) and then retries the same token with the same rule, 
obviously resulting in an infinite loop.

Can someone clarify whether this is allowed and if so whether there is some 
trick to using it?  I am stumped.  

Thanks
Jeff






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: 27678] [antlr-interest] Test class for tree grammars

2010-01-26 Thread Konstantinos Kakousis
Hello,

I have my grammar and tree grammars working exactly as expected at the 
AntlrWorks.
Now I was trying to run from console or Eclipse the same grammar using 
the following Test.java
class:

import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.tree.CommonTreeNodeStream;
import org.antlr.runtime.tree.Tree;

public class Test{

public static void main (String[] args){
   
   try{
 String in = 5+6*7;
ANTLRStringStream input = new ANTLRStringStream(in);
UtilityLexer lexer = new UtilityLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
UtilityParser parser = new UtilityParser(tokens);
UtilityParser.prog_return r = null;
r = parser.prog();
   CommonTree t = (CommonTree)r.getTree(); // get tree from parser
 System.out.println(Parse Tree:+t.toStringTree());

CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
 System.out.println (Here1);
  
nodes.setTokenStream(tokens);
 System.out.println (Here2);

UtilTree walker = new UtilTree(nodes);
 System.out.println (Here3);
walker.prog();
 System.out.println (Here4);
   
} catch (RecognitionException e) {
e.printStackTrace();
}

  
}
}

 From the output:
Parse Tree:(+ 5 (* 6 7))
Here1
Here2

It seems that the programs hangs on the following command:
   UtilTree walker = new UtilTree(nodes);
Is there somewhere a standard Test.java class for running the generated 
grammars?
Is there something wrong with the above class?

BR,

-- 
Konstantinos Kakousis
Research Associate

Department of Computer Science
University of Cyprus

Address: P.O. Box 20537, CY-1678, Nicosia, Cyprus
Tel: +357 22892684
Fax: +357 22892701
Webpage: http://www.cs.ucy.ac.cy/~csp7kk3
Email:   mailto://kakou...@cs.ucy.ac.cy
Skype:   callto://costas.kakousis


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: 27680] Re: [antlr-interest] Running ANTLRWorks 1.3.1 -- javac error

2010-01-26 Thread Bart Kiers
Karljürgen,

In order to run ANTLRWorks, you do not need 'javac', but 'java'.

'javac' is the compiler that will compile java source files into byte codes
that the JRE (Java Runtime Environment) interprets/executes.

'java' is the application that executes the byte codes produced by 'javac'.
Since ANTLRWorks is already compiled, you only need 'java'.

So, on the command line, give the following command:

java -jar antlrworks-1.3.1.jar

If the above does not work, please post the exact error message(s) on the
list.

Thanks.

Bart.


On Tue, Jan 26, 2010 at 6:51 PM, Karljurgen Feuerherm kfeuerh...@wlu.cawrote:

 Hello,

 I'm new to this product (and to modern products of this type
 generally... was a B programmer in the early 80s and trying to get
 updated!)

 I'm on Windows XP, and have run the JAR file to invoke ANTLRWorks.

 I'm trying out the Expression Evaluator Tutorial. Interpreter works
 fine, but invoking the debugger gets me

 java.IO.IOException: Cannot run program javac: CreateProcess
 error=2, the system cannot find the file specified

 (Oddly, after a while, trying it again got me a different error about
 timeout, even though I'd changed nothing [Sure. Famous Last Words,
 eh?].)

 Not sure where to go from here... By all means be pedantic in a
 response :)

 Thanks!

 K

 Karljürgen G. Feuerherm, PhD
 Department of Archaeology and Classical Studies
 Wilfrid Laurier University
 75 University Avenue West
 Waterloo, Ontario N2L 3C5
 Tel. (519) 884-1970 x3193
 Fax (519) 883-0991 (ATTN Arch.  Classics)

 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: 27681] Re: [antlr-interest] Running ANTLRWorks 1.3.1 -- javac error

2010-01-26 Thread Bart Kiers
On Tue, Jan 26, 2010 at 7:37 PM, Andreas Stefik stef...@gmail.com wrote:

 I think he's asking why the debugger throws errors with javac, not how to
 start antlrworks.

 The error you are seeing is because the antlrworks debugger, far as I
 understand it, needs a java compiler to actually debug a grammar. As such,
 you need to put the path to your javac compiler in the path field in
 antlrworks. This is straightforward to do:

 1. Open up the options window. I'm on mac at the moment, which is in
 preferences, but on windows it is similar.
 2. Go to the tab labeled compiler and look for where it says javac.
 3. Check path under javac, then click browse and a window should appear.
 4. Browse to where javac is located.

 As I'm on mac, the paths are different, but if I recall correctly, on
 windows javac is in program files, so it would be something like

 c:\program files\Java\bin\javac.exe

 That path might not be correct, but I don't have a windows box on me to
 give it to you exactly. Should be close though and if you browse around you
 should find it.

 The last detail is that, if you can't find javac, you may not have the JDK
 installed (java.sun.com), so you'll need to do that. It's just a little
 installer, so there's nothing fancy to do. You can know for sure whether you
 have it by going to the command line and typing:

 javac

 if it throws an error, you need the JDK. If it's there, you will see a
 bunch of information put out to the terminal.

 Hope that helps,

 Andreas Stefik, Ph.D.
 Assistant Professor
 Department of Computer Science
 Southern Illinois University Edwardsville



 On Tue, Jan 26, 2010 at 12:19 PM, Bart Kiers bki...@gmail.com wrote:

 Karljürgen,

 In order to run ANTLRWorks, you do not need 'javac', but 'java'.

 'javac' is the compiler that will compile java source files into byte
 codes
 that the JRE (Java Runtime Environment) interprets/executes.

 'java' is the application that executes the byte codes produced by
 'javac'.
 Since ANTLRWorks is already compiled, you only need 'java'.

 So, on the command line, give the following command:

 java -jar antlrworks-1.3.1.jar

 If the above does not work, please post the exact error message(s) on the
 list.

 Thanks.

 Bart.


 On Tue, Jan 26, 2010 at 6:51 PM, Karljurgen Feuerherm kfeuerh...@wlu.ca
 wrote:

  Hello,
 
  I'm new to this product (and to modern products of this type
  generally... was a B programmer in the early 80s and trying to get
  updated!)
 
  I'm on Windows XP, and have run the JAR file to invoke ANTLRWorks.
 
  I'm trying out the Expression Evaluator Tutorial. Interpreter works
  fine, but invoking the debugger gets me
 
  java.IO.IOException: Cannot run program javac: CreateProcess
  error=2, the system cannot find the file specified
 
  (Oddly, after a while, trying it again got me a different error about
  timeout, even though I'd changed nothing [Sure. Famous Last Words,
  eh?].)
 
  Not sure where to go from here... By all means be pedantic in a
  response :)
 
  Thanks!
 
  K
 
  Karljürgen G. Feuerherm, PhD
  Department of Archaeology and Classical Studies
  Wilfrid Laurier University
  75 University Avenue West
  Waterloo, Ontario N2L 3C5
  Tel. (519) 884-1970 x3193
  Fax (519) 883-0991 (ATTN Arch.  Classics)
 
  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




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: 27682] Re: [antlr-interest] Running ANTLRWorks 1.3.1 -- javac error

2010-01-26 Thread Andreas Stefik
JDK means the same thing as SDK does for Java (Java Development Kit). JDK 6
U18 is the correct thing to have downloaded, so you are on the right track.

After installing it, you definitely should have javac and it should be in
your environment variables. Might be obvious, but have you tried restarting?

Andreas Stefik, Ph.D.
Assistant Professor
Department of Computer Science
Southern Illinois University Edwardsville


On Tue, Jan 26, 2010 at 3:41 PM, Karljurgen Feuerherm kfeuerh...@wlu.cawrote:

  Hi

 Thanks, that makes a lot more sense.

 Now, oddly, I found and downloaded JDK 6 U18, and installed it... and javac
 is still not found. I'm hunting around for documentation on the site, but
 there are so many different options...

 Maybe I need an SDK?

 K

 Karljürgen G. Feuerherm, PhD
 Department of Archaeology and Classical Studies
 Wilfrid Laurier University
 75 University Avenue West
 Waterloo, Ontario N2L 3C5
 Tel. (519) 884-1970 x3193
 Fax (519) 883-0991 (ATTN Arch.  Classics)

  Bart Kiers bki...@gmail.com 26/01/2010 1:40 pm 

 On Tue, Jan 26, 2010 at 7:37 PM, Andreas Stefik * stef...@gmail.com* 
 wrote:

  I think he's asking why the debugger throws errors with javac, not how to
  start antlrworks.
 
  The error you are seeing is because the antlrworks debugger, far as I
  understand it, needs a java compiler to actually debug a grammar. As
 such,
  you need to put the path to your javac compiler in the path field in
  antlrworks. This is straightforward to do:
 
  1. Open up the options window. I'm on mac at the moment, which is in
  preferences, but on windows it is similar.
  2. Go to the tab labeled compiler and look for where it says javac.
  3. Check path under javac, then click browse and a window should appear.
  4. Browse to where javac is located.
 
  As I'm on mac, the paths are different, but if I recall correctly, on
  windows javac is in program files, so it would be something like
 
  c:\program files\Java\bin\javac.exe
 
  That path might not be correct, but I don't have a windows box on me to
  give it to you exactly. Should be close though and if you browse around
 you
  should find it.
 
  The last detail is that, if you can't find javac, you may not have the
 JDK
  installed (java.sun.com), so you'll need to do that. It's just a little
  installer, so there's nothing fancy to do. You can know for sure whether
 you
  have it by going to the command line and typing:
 
  javac
 
  if it throws an error, you need the JDK. If it's there, you will see a
  bunch of information put out to the terminal.
 
  Hope that helps,
 
  Andreas Stefik, Ph.D.
  Assistant Professor
  Department of Computer Science
  Southern Illinois University Edwardsville
 
 
 
  On Tue, Jan 26, 2010 at 12:19 PM, Bart Kiers * bki...@gmail.com* 
 wrote:
 
  Karljürgen,
 
  In order to run ANTLRWorks, you do not need 'javac', but 'java'.
 
  'javac' is the compiler that will compile java source files into byte
  codes
  that the JRE (Java Runtime Environment) interprets/executes.
 
  'java' is the application that executes the byte codes produced by
  'javac'.
  Since ANTLRWorks is already compiled, you only need 'java'.
 
  So, on the command line, give the following command:
 
  java -jar antlrworks-1.3.1.jar
 
  If the above does not work, please post the exact error message(s) on
 the
  list.
 
  Thanks.
 
  Bart.
 
 
  On Tue, Jan 26, 2010 at 6:51 PM, Karljurgen Feuerherm *
 kfeuerh...@wlu.ca*
  wrote:
 
   Hello,
  
   I'm new to this product (and to modern products of this type
   generally... was a B programmer in the early 80s and trying to get
   updated!)
  
   I'm on Windows XP, and have run the JAR file to invoke ANTLRWorks.
  
   I'm trying out the Expression Evaluator Tutorial. Interpreter works
   fine, but invoking the debugger gets me
  
   java.IO.IOException: Cannot run program javac: CreateProcess
   error=2, the system cannot find the file specified
  
   (Oddly, after a while, trying it again got me a different error about
   timeout, even though I'd changed nothing [Sure. Famous Last Words,
   eh?].)
  
   Not sure where to go from here... By all means be pedantic in a
   response :)
  
   Thanks!
  
   K
  
   Karljürgen G. Feuerherm, PhD
   Department of Archaeology and Classical Studies
   Wilfrid Laurier University
   75 University Avenue West
   Waterloo, Ontario N2L 3C5
   Tel. (519) 884-1970 x3193
   Fax (519) 883-0991 (ATTN Arch.  Classics)
  
   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
 *
 
 
 

 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: 

[il-antlr-interest: 27684] [antlr-interest] better error messages in tree parsers

2010-01-26 Thread Terence Parr
Hi, a reminder that debugging tree grammars can be a bitch.  I like to override 
standard messaging to spew lots of stuff.  E.g., i like this kind of thing:

ASTVerifier.g: node from after line 150:17 [grammarSpec, rules, rule, 
altListAsBlock, altList, alternative, elements, element, ebnf, block, altList, 
alternative]  no viable alt; toke...@-1,0:0='ALT',84,0:-1] (decision=24 state 
3) decision=
context=...DOWN BLOCK DOWN ALT DOWN DOC_COMMENT...

Here's my code:

public String getErrorMessage(RecognitionException e,
  String[] tokenNames)
{
List stack = getRuleInvocationStack(e, this.getClass().getName());
String msg = null;
String inputContext =
((Tree)input.LT(-3)).getText()+ +
((Tree)input.LT(-2)).getText()+ +
((Tree)input.LT(-1)).getText()+ +
((Tree)input.LT(1)).getText()+ +
((Tree)input.LT(2)).getText()+ +
((Tree)input.LT(3)).getText();
if ( e instanceof NoViableAltException ) {
   NoViableAltException nvae = (NoViableAltException)e;
   msg =  no viable alt; token=+e.token+
   (decision=+nvae.decisionNumber+
   state +nvae.stateNumber+)+
   decision=+nvae.grammarDecisionDescription+;
}
else {
   msg = super.getErrorMessage(e, tokenNames);
}
return stack+ +msg+ context=...+inputContext+...;
}
public String getTokenErrorDisplay(Token t) {
return t.toString();
}

Ter

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: 27686] Re: [antlr-interest] Disabling rules in the lexer

2010-01-26 Thread William B. Clodius
Generally don't try to be too restrictive with your lexer and parser. This sort 
of context dependence is more naturally handled in the semantic analysis. In 
particular error reporting is much better if you accept things that are 
ultimately illegal in the lexer and parser and determine whether they are they 
are illegal in the semantic analysis. Instead of a minimal message such as 
Illegal token you can report Illegal token for the table structure see 
constraint # in the language definition, or Token is not one of the set of 
...

On Jan 26, 2010, at 7:52 AM, Jeff Wilcox wrote:

 Hi,
 
 I have a special area in this language that has symbols within a table 
 structure that are normally used in other tokens in other areas of the 
 language (like a couple digits, a couple letters and a couple symbols).  So I 
 am trying to setup the lexer to accept these table tokens only when in a 
 table.  Based on what I have been able to dig up, I believe gated semantic 
 predicates are a valid way to disable rules in the lexer.  However, I am 
 seeing issues with this with ANTLR 3.2 and the java language target.  
 
 So I expected a lexer rules like this to do the trick:  
 
 Level0   : {inTable}?= '0';
 
 But that actually creates a very strange loop when inTable is false.  I 
 basically throws a FailedPredicateException (which I would not have expected 
 for a gated predicate) and then retries the same token with the same rule, 
 obviously resulting in an infinite loop.
 
 Can someone clarify whether this is allowed and if so whether there is some 
 trick to using it?  I am stumped.  
 
 Thanks
 Jeff
snip

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.