2

I am looking to use Rascal's existing Java AST provided in the m3 library but I would like to extend this to add some features. We are working with a Java-like language (about 95% Java and 5% our specific features). Ideally, I'd like to be able to take the Java syntax and AST code (src/org/rascalmpl/library/lang/java/syntax/Java15.rsc and src/org/rascalmpl/library/lang/java/m3/AST.rsc, respectively) modify the syntax a bit and add some new AST nodes. Going through and exploring how this all works has shown this all doesn't work the same as the other language examples I've found.

For example, the constructors in Java15.rsc don't match the constructors in AST.rsc which is how all the other language examples appear to work. My current understanding of how this all works is when a user makes a call to createAstFromFile() what actually happens is Rascal calls into some Java code which produces the AST.

I've tried a number of things, the most successful being started to rename the constructors in Java15.rsc to match those in AST.rsc but didn't make it too far before I realised this was going to be a daunting task and perhaps not the best way to approach this problem.

Is there anyway I can "easily" extract the syntax and AST portions here and modify them on my own?

Thanks.

josh
  • 1,544
  • 2
  • 16
  • 27
  • Do you insist on a Rascal answer, or are you interested in alternative ways that might let you express your exact grammar? – Ira Baxter Aug 11 '15 at 16:09
  • Yes, Rascal is the tool we are currently using. I have a bunch of code written, in Rascal, already which does some processing. I'd rather not change it. Do you have a suggestion though? – josh Aug 11 '15 at 21:42
  • Have you considered DMS? You can provide it with a base grammar, and with a dialect variant. http://www.semdesigns.com/Products/DMS/DMSParsers.html – Ira Baxter Aug 11 '15 at 22:27

1 Answers1

2

M3 (and it's AST) is disconnected from the Java15 grammar. It used eclipse JDT for parsing and name binding. It you want to extend the AST, you can add new constructors to the ADT.

data Expression = delayedCall(Expression receiver, str name, list[Expression] arguments);

Adds a new alternative to the Expression ADT.

However, we do not have a java printer for the AST, so depending on what you want to do, you might actually want a grammar for your language and work with parse trees. You can extend grammars in a similar way as ADTs.

Davy Landman
  • 15,109
  • 6
  • 49
  • 73
  • Thanks, Davy. What exactly is `delayedCall()` here? And if I were modifying the AST in this way I wouldn't be able to modify the concrete syntax? – josh Aug 11 '15 at 21:43
  • 1
    Hi Josh. Because for the m3 front-end for java we have used the Eclipse java compiler, you'd have to extend said compiler to achieve extending the syntax. Another option would be to use the Rascal grammar for java and simply extend it, write a desugaring to plain java which can then be compiled again using the Eclipse compiler. Or finally, the last option is to bite the bullet and write a full front-end for java which maps the concrete trees generated from the java grammar to m3 trees and relations. would amount to a full extensible java front-end comparable to the jastadd java compiler suite. – Jurgen Vinju Aug 12 '15 at 11:08
  • Great, thanks! This definitely gives us something to work with / think about. – josh Aug 12 '15 at 18:32