From yang.jiang.z at gmail.com Fri Dec 5 03:06:47 2008 From: yang.jiang.z at gmail.com (Yang Jiang) Date: Fri, 05 Dec 2008 03:06:47 -0800 Subject: Visual tool using the Java grammar Message-ID: <49390B47.9020806@gmail.com> Hi list, Try this out, a simple use case for the Java.g grammar: a visual tool showing how your java file is parsed. http://www.antlr.org/wiki/display/ANTLR3/Tool+showing+grammatical+structure+of+Java+code Thanks, Yang -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.openjdk.java.net/pipermail/compiler-grammar-dev/attachments/20081205/18994ebf/attachment.html -------------- next part -------------- A non-text attachment was scrubbed... Name: screenshot.png Type: image/png Size: 195855 bytes Desc: not available Url : http://mail.openjdk.java.net/pipermail/compiler-grammar-dev/attachments/20081205/18994ebf/attachment.png From forax at univ-mlv.fr Sun Dec 7 08:34:13 2008 From: forax at univ-mlv.fr (=?ISO-8859-1?Q?R=E9mi_Forax?=) Date: Sun, 07 Dec 2008 17:34:13 +0100 Subject: use Tatoo's compiler as front end of javac Message-ID: <493BFB05.7080808@univ-mlv.fr> Hi all, I've written a blog entry that show how to use Tatoo to generate a parser usable as front end of javac. http://weblogs.java.net/blog/forax/archive/2008/12/using_tatoo_as.html cheers, R?mi From Jonathan.Gibbons at Sun.COM Mon Dec 8 14:31:53 2008 From: Jonathan.Gibbons at Sun.COM (Jonathan Gibbons) Date: Mon, 08 Dec 2008 14:31:53 -0800 Subject: use Tatoo's compiler as front end of javac In-Reply-To: <493BFB05.7080808@univ-mlv.fr> References: <493BFB05.7080808@univ-mlv.fr> Message-ID: <493DA059.4060200@sun.com> R?mi Forax wrote: > Hi all, > I've written a blog entry that show how to use Tatoo > to generate a parser usable as front end of javac. > http://weblogs.java.net/blog/forax/archive/2008/12/using_tatoo_as.html > > cheers, > R?mi > I've patched the compiler grammar's javac (which is already a patch of > javac) a litte bit to be able to specify a parser factory on the > command line. How big is the patch to compiler grammar's javac? Would it be worth contributing the patch to the main OpenJDK javac -- i.e. the work to specify a parser factory on the command line. -- Jon From forax at univ-mlv.fr Mon Dec 8 15:22:27 2008 From: forax at univ-mlv.fr (=?windows-1252?Q?R=E9mi_Forax?=) Date: Tue, 09 Dec 2008 00:22:27 +0100 Subject: use Tatoo's compiler as front end of javac In-Reply-To: <493DA059.4060200@sun.com> References: <493BFB05.7080808@univ-mlv.fr> <493DA059.4060200@sun.com> Message-ID: <493DAC33.30408@univ-mlv.fr> Jonathan Gibbons a ?crit : > R?mi Forax wrote: >> Hi all, >> I've written a blog entry that show how to use Tatoo >> to generate a parser usable as front end of javac. >> http://weblogs.java.net/blog/forax/archive/2008/12/using_tatoo_as.html >> >> cheers, >> R?mi >> I've patched the compiler grammar's javac (which is already a patch >> of javac) a litte bit to be able to specify a parser factory on the >> command line. > > How big is the patch to compiler grammar's javac? Not that big. It removes dependency to ANTLR and use reflection to get the ParserFactory. I have reuse the same name for the option but perhaps "parserFactory" is a better name than "parser". > Would it be worth contributing the patch to the main OpenJDK javac -- > i.e. the work to specify a parser factory on the command line. see the patch below :) By the way, ParserFactory should be abstract and should have an implementation containing Javac specifics. Currently, the factory instantiates a Keyword and a Scanner.Factory that are specific to the current hand written scanner. > > -- Jon > R?mi diff --git a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java @@ -26,6 +26,7 @@ package com.sun.tools.javac.main; package com.sun.tools.javac.main; import java.io.*; +import java.lang.reflect.InvocationTargetException; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.LinkedHashMap; @@ -45,7 +46,6 @@ import com.sun.source.util.TaskEvent; import com.sun.source.util.TaskEvent; import com.sun.source.util.TaskListener; -import com.sun.tools.javac.antlr.AntlrParserFactory; import com.sun.tools.javac.util.*; import com.sun.tools.javac.code.*; import com.sun.tools.javac.tree.*; @@ -387,11 +387,28 @@ public class JavaCompiler implements Cla : null; String parser = options.get("parser"); - //useAntlrParser = (parser != null && parser.equalsIgnoreCase("antlr")); - useAntlrParser = (parser == null || parser.equalsIgnoreCase("antlr")); - - if (useAntlrParser) - AntlrParserFactory.preRegister(context); + if (parser != null) { + try { + Class parserClass = Class.forName(parser); + parserClass.getMethod("preRegister", Context.class). + invoke(null, context); + } catch(ClassNotFoundException e) { + throw new AssertionError(e); + } catch(IllegalAccessException e) { + throw new AssertionError(e); + } catch(NoSuchMethodException e) { + throw new AssertionError(e); + } catch(InvocationTargetException e) { + Throwable cause=e.getCause(); + if (cause instanceof RuntimeException) { + throw (RuntimeException)cause; + } + if (cause instanceof Error) { + throw (Error)cause; + } + throw new AssertionError(cause); + } + } parserFactory = ParserFactory.instance(context); } From Jonathan.Gibbons at Sun.COM Tue Dec 16 15:45:49 2008 From: Jonathan.Gibbons at Sun.COM (Jonathan Gibbons) Date: Tue, 16 Dec 2008 15:45:49 -0800 Subject: use Tatoo's compiler as front end of javac In-Reply-To: <493DAC33.30408@univ-mlv.fr> References: <493BFB05.7080808@univ-mlv.fr> <493DA059.4060200@sun.com> <493DAC33.30408@univ-mlv.fr> Message-ID: <49483DAD.7070301@sun.com> R?mi, Thanks for the suggested patch. I'm thinking it might be worth investigating this one step further, and see if we can leverage the JDK ServiceLoader mechanism to come up with a more general mechanism that would apply to any object that might be found via the javac Context. I can see 3 possibilities: Early: as soon as the context is created, populate it with any objects found via the service loader. Later: after the command line options have been read, populate the context with any objects found via the service loader. This will allow the ability to select objects via hidden command line options. Latest: on an instance by instance basis, check the service loader before creating each default object for the context. This is the most expensive option, since it requires checking the service loader on an object by object basis; the previous two options would just require one access to the service loader, for any/all objects to put in the context. We could also go for a radically different dependency injection framework, but I'd prefer to go for a small/lightweight change, and not any major refactoring at this time. -- Jon R?mi Forax wrote: > Jonathan Gibbons a ?crit : >> R?mi Forax wrote: >>> Hi all, >>> I've written a blog entry that show how to use Tatoo >>> to generate a parser usable as front end of javac. >>> http://weblogs.java.net/blog/forax/archive/2008/12/using_tatoo_as.html >>> >>> cheers, >>> R?mi >>> I've patched the compiler grammar's javac (which is already a patch >>> of javac) a litte bit to be able to specify a parser factory on the >>> command line. >> >> How big is the patch to compiler grammar's javac? > Not that big. It removes dependency to ANTLR and use reflection > to get the ParserFactory. > I have reuse the same name for the option but perhaps "parserFactory" > is a better > name than "parser". >> Would it be worth contributing the patch to the main OpenJDK javac -- >> i.e. the work to specify a parser factory on the command line. > see the patch below :) > > By the way, ParserFactory should be abstract and should have an > implementation > containing Javac specifics. > Currently, the factory instantiates a Keyword and a Scanner.Factory > that are specific to > the current hand written scanner. >> >> -- Jon >> > R?mi > > diff --git > a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java > b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java > --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java > +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java > @@ -26,6 +26,7 @@ package com.sun.tools.javac.main; > package com.sun.tools.javac.main; > > import java.io.*; > +import java.lang.reflect.InvocationTargetException; > import java.util.HashSet; > import java.util.LinkedHashSet; > import java.util.LinkedHashMap; > @@ -45,7 +46,6 @@ import com.sun.source.util.TaskEvent; > import com.sun.source.util.TaskEvent; > import com.sun.source.util.TaskListener; > > -import com.sun.tools.javac.antlr.AntlrParserFactory; > import com.sun.tools.javac.util.*; > import com.sun.tools.javac.code.*; > import com.sun.tools.javac.tree.*; > @@ -387,11 +387,28 @@ public class JavaCompiler implements Cla > : null; > > String parser = options.get("parser"); > - //useAntlrParser = (parser != null && > parser.equalsIgnoreCase("antlr")); > - useAntlrParser = (parser == null || > parser.equalsIgnoreCase("antlr")); > - > - if (useAntlrParser) > - AntlrParserFactory.preRegister(context); > + if (parser != null) { > + try { > + Class parserClass = Class.forName(parser); > + parserClass.getMethod("preRegister", Context.class). > + invoke(null, context); > + } catch(ClassNotFoundException e) { > + throw new AssertionError(e); > + } catch(IllegalAccessException e) { > + throw new AssertionError(e); > + } catch(NoSuchMethodException e) { > + throw new AssertionError(e); > + } catch(InvocationTargetException e) { > + Throwable cause=e.getCause(); > + if (cause instanceof RuntimeException) { > + throw (RuntimeException)cause; > + } > + if (cause instanceof Error) { > + throw (Error)cause; > + } > + throw new AssertionError(cause); > + } > + } > > parserFactory = ParserFactory.instance(context); > } > From forax at univ-mlv.fr Thu Dec 18 02:22:13 2008 From: forax at univ-mlv.fr (=?windows-1252?Q?R=E9mi_Forax?=) Date: Thu, 18 Dec 2008 11:22:13 +0100 Subject: use Tatoo's compiler as front end of javac In-Reply-To: <49483DAD.7070301@sun.com> References: <493BFB05.7080808@univ-mlv.fr> <493DA059.4060200@sun.com> <493DAC33.30408@univ-mlv.fr> <49483DAD.7070301@sun.com> Message-ID: <494A2455.60204@univ-mlv.fr> Jonathan Gibbons a ?crit : > R?mi, > > Thanks for the suggested patch. I'm thinking it might be worth > investigating this one step further, and see if we can leverage the > JDK ServiceLoader mechanism to come up with a more general > mechanism that would apply to any object that might be found via > the javac Context. ServiceLoader requires an empty constructor and objects store in a Content are constructed with that context. I don't see how to use it without modifications of java.util.ServiceLoader. > > I can see 3 possibilities: > > Early: as soon as the context is created, populate it with any > objects found via the service loader. > > Later: after the command line options have been read, populate > the context with any objects found via the service loader. This > will allow the ability to select objects via hidden command line > options. > > Latest: on an instance by instance basis, check the service loader > before creating each default object for the context. This is the > most expensive option, since it requires checking the service > loader on an object by object basis; the previous two options > would just require one access to the service loader, for any/all > objects to put in the context. In my opinion, this should be done in instance(), (your latest solution), Context is already a cache but again there is no way to get the service class from a ServiceLoader. > > We could also go for a radically different dependency injection > framework, but I'd prefer to go for a small/lightweight change, > and not any major refactoring at this time. yes, we could :) > > -- Jon R?mi