Re: CUP/LEX has limitations

Joel Jones <>
26 Jun 2005 11:18:56 -0400

          From comp.compilers

Related articles
CUP/LEX has limitations (Sharma, Girish \(Girish\)) (2005-06-23)
Re: CUP/LEX has limitations (Scott Nicol) (2005-06-24)
Re: CUP/LEX has limitations (Joel Jones) (2005-06-26)
Re: CUP/LEX has limitations (Scott Nicol) (2005-06-26)
Re: CUP/LEX has limitations (2005-06-30)
Re: CUP/LEX has limitations (glen herrmannsfeldt) (2005-06-30)
Re: CUP/LEX has limitations (Scott Nicol) (2005-07-02)
Re: CUP/LEX has limitations (Martin Ward) (2005-07-03)
Re: CUP/LEX has limitations (A Pietu Pohjalainen) (2005-07-22)
| List of all articles for this month |

From: Joel Jones <>
Newsgroups: comp.compilers
Date: 26 Jun 2005 11:18:56 -0400
Organization: Compilers Central
References: 05-06-115 05-06-118
Keywords: Java
Posted-Date: 26 Jun 2005 11:18:56 EDT

At 9:55 AM -0400 6/24/05, Scott Nicol wrote:
>I haven't used CUP/LEX, but I'm quite familiar with the "code too
>large" error in Java. Java has a limit of 64k code per method (you,
>like I, might be wondering what was being smoked when that decision
>was made).
>This snags lots of generated code. Tables are no help, because they
>are simply shorthand for an array creation plus one assignment for
>each table index. And all class-level variables are lumped together
>in one method!

It is actually more correct to say that tables help, you just have to
initialize them the right way. You are correct in saying that using
Java's array initialization is no help. The solution is to write
strings in the source and then unpack the strings at run time. This
is the solution that Java Cup uses. The parser's tables are written
out as very long strings, along with a routine which unpacks them into
an array. This code is executed in the class initializer once when
the class is loaded. Here is an example:

      protected static final short _production_table[][] =
          unpackFromStrings(new String[] {
          "\000\140\000\002\003\003\000\002\002\004\000\002\004" +
          "\004\000\002\004\002\000\002\005\007\000\002\005\011" +

      I have often wished that the .class file had a means of doing array
initialization. However, given endianess and implementation choices
for arrays, I can see that many VMs would end up not being able to use
the initalized array "in-place" anyway.
Joel Jones
Department of Computer Science
University of Alabama (205) 348-1618

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.