[antlr-interest] Token.filename being ignored - solutions

antlrlist antlrlist at yahoo.com
Fri Jun 6 11:55:19 PDT 2003



Terrence,

I've had this problem for a little while: filenames are usually 
ignored by default in antlr. CommonToken does not take it in account, 
and what's worse antlr.CharScanner.makeToken() does not fill it.

Could you please explain this? Is it a matter of efficiency?

According to this link:

http://java.sun.com/docs/books/tutorial/java/data/stringsAndJavac.html

storing a String in CommonToken would add the overhead of managing 1 
pointer - String objects are not created unless you modify them.

This is shown specially in this piece of code :

  String s1 = "hello";
  String s2 = s1;
  System.out.println("s1 = " + s1
                   + "; s2 = " + s2);
  System.out.println("System.identityHashCode(s1) = "
                   + System.identityHashCode(s1));
  System.out.println("System.identityHashCode(s2) = "
                   + System.identityHashCode(s2));

  s1 += " world";
  System.out.println("\ns1 = " + s1
                   + "; s2 = " + s2);
  System.out.println("System.identityHashCode(s1) = "
                   + System.identityHashCode(s1));
  System.out.println("System.identityHashCode(s2) = "
                   + System.identityHashCode(s2));

Here's the output: 

  s1 = hello; s2 = hello
  System.identityHashCode(s1) = 2452092
  System.identityHashCode(s2) = 2452092

  s1 = hello world; s2 = hello
  System.identityHashCode(s1) = 7474923
  System.identityHashCode(s2) = 2452092

s1 points to a new address after " world" is appended. 

Cheers,

Enrique



 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list