SableCC and GWT

17 views
Skip to first unread message

Alexander Ryzhov

unread,
Jan 28, 2013, 2:15:00 PM1/28/13
to sab...@googlegroups.com
Hi,

I'd like to share my experience of using a SableCC-generated parser with Google Web Toolkit. For those who don't know, GWT is a Java-to-Javascript compiler that allows developing client-side web applications using Java. I faced some issues when attempting to compile the parser with GWT.

1. SableCC-generated parser uses some classes from java.io that are absent in GWT JRE Emulation Library:
    PushbackReader
    DataInputStream
    BufferedInputStream
2. It also uses getClass().getResourceAsStream() which is absent as well.
3. Class Node implements Cloneable interface which is not supported as well.
4. It uses class Hashtable which is absent as well (although HashMap is supported).

Here is how I defeated them:

1. Rewrote Lexer and Parser to get their data tables from memory instead of .dat files. Basically, wrote a DataInputStream that accepts a byte array as a constructor parameter and has methods readInt(), readChar(), and close(). Wrote a generator program that surgically changes the generated Parser and Lexer classes to use the new class every time sablecc is run.
2. Added classes called PushbackReader, Hashtable (extends HashMap), and interface Cloneable and added them to the packages from which they are referenced. This tricked the compiler into loading those classes instead of the JRE classes.

I admit that this is a big hack but the good news is that it's possible to change SableCC to generate GWT-compliant parser. I am not sure if anyone else is interested in this feature though.

Alexander

Paweł Cesar Sanjuan Szklarz

unread,
Jan 28, 2013, 5:03:54 PM1/28/13
to sab...@googlegroups.com
Hi.

I am really interested!!!. I use GWT on commercial products, and the capability to have a formal grammar to support the server-client communication may be really useful.

I volunteer to help on such change to sablecc and to create sample project on GWT to show how to use the final product.

As I think about it now, I don't know why I did not try before.

Regards.
Pawel Cesar Sanjuan Szklarz




Alexander

--
-- You received this message because you are subscribed to the SableCC group. To post to this group, send email to sab...@googlegroups.com. To unsubscribe from this group, send email to sablecc+u...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/sablecc?hl=en
---
You received this message because you are subscribed to the Google Groups "SableCC" group.
To unsubscribe from this group, send email to sablecc+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Gonzalo Ortiz Jaureguizar

unread,
Jan 29, 2013, 3:37:05 AM1/29/13
to sab...@googlegroups.com
It is a very interesting topic. I can only help by saying that in the last version of SableCC, PushbackReader is suplied by IPushbackReader, a very simple interface with only a couple of methods.
Reply all
Reply to author
Forward
0 new messages