In an attempt to write a MiniJava compiler in Spoofax I ran into what is probably a bug when parsing this code:

`class Main {

public static void main(String[] args) {
	System.out.println(new Fac().fac(10)) ;


class Fac {

public int fac(int num) {
	a = b;
	return c;


The editor reports a warning on line //bla1 altough “transform->show abstract syntax” reports no ambiguities:
Fragment is ambiguous: amb([MethodDecl(Int,"fac",FormalList([TypeId(Int,"num")]),[],[Assign ("a",Id("b"))],Id("c")),MethodDecl(Int,"fac",FormalList([TypeId(Int,"num")]),[],[Assign("a",Id ("b"))],Id("c"))])

I’ll try to also post my syntax definition.

Submitted on 21 September 2010 at 12:39

On 21 September 2010 at 15:13 Lennart Kats closed this issue.

On 21 September 2010 at 15:13 Lennart Kats commented:

I had a closer look at the grammar and the example and it turns out it is missing the following restriction:

context-free restrcitions
LAYOUT? -/- [/].[/]

This restriction ensures that comments can only be parsed on one level of the tree.

On 22 September 2010 at 16:13 Niels Egberts commented:

I can confirm that it was indeed the problem.

Log in to post comments