Hi,

I’ve started using Spoofax to implement an island grammar in order to analyze program code (in COBOL). The plugin works fine (great work!), but I want to export the parser because I want to incorporate it into a Java program which analyzes the resulting AST.

However, I get a NullPointerException when I try to parse a file. As I didn’t find any documentation besides http://strategoxt.org/Stratego/JSGLR, I’ve been playing around with the parameters but didn’t get it to work.

    import org.spoofax.jsglr.io.SGLR;  
    import org.spoofax.jsglr.client.imploder.TreeBuilder;  
    import org.spoofax.jsglr.io.ParseTableManager;  
    ...
    String parseTable = "MyParseTable.tbl";  
    String inputFile = "cobol/example.cbl";  
    String inputString = "IDENTIFICATION DIVISION. ....";  
    ParseTableManager ptm = new ParseTableManager();  
    SGLR sglr = new SGLR(new TreeBuilder(),ptm.loadFromFile(parseTable));  
    ATerm t = (ATerm)sglr.parse(new FileReader(inputFile));  
    System.out.println(t);

The exception:
Exception in thread “main” java.lang.NullPointerException
at org.spoofax.jsglr.client.SGLR.checkRecoverCountGlobal(SGLR.java:690)
at org.spoofax.jsglr.client.SGLR.checkMaxRecoverCount(SGLR.java:680)
at org.spoofax.jsglr.client.SGLR.reduceAllPaths(SGLR.java:664)
at org.spoofax.jsglr.client.SGLR.doReductions(SGLR.java:621)
at org.spoofax.jsglr.client.SGLR.actor(SGLR.java:532)
at org.spoofax.jsglr.client.SGLR.parseCharacter(SGLR.java:478)
at org.spoofax.jsglr.client.SGLR.doParseStep(SGLR.java:364)
at org.spoofax.jsglr.client.SGLR.sglrParse(SGLR.java:308)
at org.spoofax.jsglr.client.SGLR.parse(SGLR.java:297)
at org.spoofax.jsglr.io.SGLR.parse(SGLR.java:124)
at org.spoofax.jsglr.io.SGLR.parse(SGLR.java:111)
at my.project.Analyzer.main(Analyzer.java:64)

Do you see what’s wrong with that approach?
I tried parsing the file via the command-line utility and everything worked fine.
Command: java -ss8m -mx512m -client -cp lib\strategoxt.jar org.spoofax.jsglr.Main –implode -p MyParseTable.tbl -i cobol\example.cbl

It would be great to have some kind of documentation (JavaDoc would be helpful) on how to use the parsing functions manually!

Submitted on 20 March 2012 at 17:21

On 20 March 2012 at 18:09 Maartje commented:

The NullPointerException is probably caused by a bug that is supposed to be fixed in the latest version of the JSGLR parser.
However, a fix is to call the setUseStructureRecovery(boolean b) which enables/disables error recovery.

SGLR sglr = new SGLR(new TreeBuilder(),ptm.loadFromFile(parseTable));
sglr.setUseStructureRecovery(false) //or true if error recovery is supposed to be used


On 20 March 2012 at 18:59 Johannes commented:

That fixed it. Thanks a lot for your quick answer, I appreciate the support!


On 25 March 2012 at 18:00 Lennart Kats closed this issue.

On 25 March 2012 at 18:00 Lennart Kats commented:

Good to hear it works now; closing this issue :)


On 25 March 2012 at 18:00 Lennart Kats tagged 1.1

Log in to post comments