|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
syntax extensionHi!
Is it possible to add my own syntax extensions to Janino compiler? Is there any interface to implement? :-) i.e. I have line like this: $orderID := order; which is ekvivalent to java code: setOrderID(order); and I would like to compile it as java code by Janino. thanks for reply Martin Varecha --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: syntax extensionHi Martin,
what you need to do is derive from class "Parser" and then override "parseAssignmentExpression()" something like this: if (!this.scanner.peek().toString().startsWith("$")) { return super.parseAssignmentExpression(); } String attributeName = this.readIdentifier(); this.readOperator(":"); this.readOperator("="); Java.Rvalue rhs = this.parseAssignmentExpression().toRvalueOrPE(); return new MethodInvocation( this.location(), (Atom) null, "set" + Character.toUpperCase(attributeName.charAt(0)) + attributeName.substring(1), new Rvalue[] { rhs } ); Notice that Java identifiers can legally start with a dollar sign. Then, depending on whether you use ExpressionEvaluator, ScriptEvaluator, SimpleCompiler or Compiler, you need to derive from that class, override the method that calls "new Parser()" and change it to call "new MyParser()". (E.g. for ExpressionEvaluator and ScriptEvaluator it is "makeBlock()".) Haven't tested that; please let me know if it works out for you. CU Arno martin.varecha@... schrieb: > Hi! > > Is it possible to add my own syntax extensions to Janino compiler? > Is there any interface to implement? :-) > > i.e. I have line like this: > $orderID := order; > which is ekvivalent to java code: > setOrderID(order); > and I would like to compile it as java code by Janino. > > thanks for reply > Martin Varecha > > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: syntax extensionWow!
Thanks for suggestions. I didn't expect you will write code for me :-) It was just theoretical question, becouse we are considering use of Janino for something more then common java. Now I see that it's generally possible. best regards Martin Varecha Cituji Arno Unkrig <arno@...>: > Hi Martin, > > what you need to do is derive from class "Parser" and then override > "parseAssignmentExpression()" something like this: > > if (!this.scanner.peek().toString().startsWith("$")) { > return super.parseAssignmentExpression(); > } > String attributeName = this.readIdentifier(); > this.readOperator(":"); > this.readOperator("="); > Java.Rvalue rhs = this.parseAssignmentExpression().toRvalueOrPE(); > return new MethodInvocation( > this.location(), > (Atom) null, > "set" + Character.toUpperCase(attributeName.charAt(0)) + > attributeName.substring(1), > new Rvalue[] { rhs } > ); > > Notice that Java identifiers can legally start with a dollar sign. > > Then, depending on whether you use ExpressionEvaluator, > ScriptEvaluator, SimpleCompiler or Compiler, you need to derive from > that class, override the method that calls "new Parser()" and change it > to call "new MyParser()". (E.g. for ExpressionEvaluator and > ScriptEvaluator it is "makeBlock()".) > > Haven't tested that; please let me know if it works out for you. > > > CU > > Arno > > martin.varecha@... schrieb: >> Hi! >> >> Is it possible to add my own syntax extensions to Janino compiler? >> Is there any interface to implement? :-) >> >> i.e. I have line like this: >> $orderID := order; >> which is ekvivalent to java code: >> setOrderID(order); >> and I would like to compile it as java code by Janino. >> >> thanks for reply >> Martin Varecha >> >> >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> >> >> > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
overloaded method & ternary operatorHi!
I have problem with compilation of this code: public class Main { public void method(Object s) {} public void method(Long l) {} public static void main(String[] args) { Main m = new Main(); m.method(1==1 ? "a" : new Long(1)); } }// Main class I get following error with Janino, but it works with JDK compiler. Why is it so? I tried to find something about this in specification, but I haven't found any unambiguous explanation. Should I report it as a bug? org.codehaus.janino.CompileException: Line 6, Column 16: Reference types "java.lang.String" and "java.lang.Long" don't match at org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.getType2(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.access$100(UnitCompiler.java) at org.codehaus.janino.UnitCompiler$15.visitConditionalExpression(UnitCompiler.java) at org.codehaus.janino.Java$ConditionalExpression.accept(Java.java) at org.codehaus.janino.UnitCompiler.getType(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.findMostSpecificIInvocable(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.access$51(UnitCompiler.java) at org.codehaus.janino.UnitCompiler$9.visitMethodInvocation(UnitCompiler.java) at org.codehaus.janino.Java$MethodInvocation.accept(Java.java) at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.access$25(UnitCompiler.java) at org.codehaus.janino.UnitCompiler$6.visitMethodInvocation(UnitCompiler.java) at org.codehaus.janino.Java$MethodInvocation.accept(Java.java) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.access$8(UnitCompiler.java) at org.codehaus.janino.UnitCompiler$4.visitExpressionStatement(UnitCompiler.java) at org.codehaus.janino.Java$ExpressionStatement.accept(Java.java) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.access$7(UnitCompiler.java) at org.codehaus.janino.UnitCompiler$4.visitBlock(UnitCompiler.java) at org.codehaus.janino.Java$Block.accept(Java.java) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java) at org.codehaus.janino.UnitCompiler$3.visitPackageMemberClassDeclaration(UnitCompiler.java) at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java) at org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java) at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java) at org.codehaus.janino.Cookable.cook(Cookable.java) at org.codehaus.janino.Cookable.cook(Cookable.java) at org.codehaus.janino.Cookable.cook(Cookable.java) Thanks Martin Varecha --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: overloaded method & ternary operatorHi Martin,
all JDK compilers that I have at hand report an error (as I expected), see below. What JDK compiler are you using exactly (java -version)? CU Arno -------------------------- $ JAVA_HOME=/cygdrive/c/jdk-1.2.2; rm -f Main.class; $JAVA_HOME/bin/java -version && $JAVA_HOME/bin/javac Main.java && $JAVA_HOME/bin/java Main java version "1.2.2" Classic VM (build JDK-1.2.2_017, native threads, symcjit) Main.java:7: Incompatible type for ?:. Can't convert java.lang.String to java.lang.Long. m.method(1==1 ? "a" : new Long(1)); ^ 1 error Arno@sharon /cygdrive/c/tmp $ JAVA_HOME=/cygdrive/c/j2sdk1.4.1_02/; rm -f Main.class; $JAVA_HOME/bin/java -version && $JAVA_HOME/bin/javac Main.java && $JAVA_HOME/bin/java Main java version "1.4.1_02" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06) Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode) Main.java:7: incompatible types found : java.lang.Long required: java.lang.String m.method(1==1 ? "a" : new Long(1)); ^ 1 error Arno@sharon /cygdrive/c/tmp $ JAVA_HOME=/cygdrive/c/j2sdk-1.5.0-beta; rm -f Main.class; $JAVA_HOME/bin/java -version && $JAVA_HOME/bin/javac Main.java && $JAVA_HOME/bin/java Main java version "1.5.0-beta" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c) Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode) Main.java:7: incompatible types for ?: neither is a subtype of the other second operand: java.lang.String third operand : java.lang.Long m.method(1==1 ? "a" : new Long(1)); ^ 1 error Arno@sharon /cygdrive/c/tmp $ martin.varecha@... schrieb: > Hi! > I have problem with compilation of this code: > > public class Main { > public void method(Object s) {} > public void method(Long l) {} > public static void main(String[] args) { > Main m = new Main(); > m.method(1==1 ? "a" : new Long(1)); > } > }// Main class > > I get following error with Janino, but it works with JDK compiler. > Why is it so? > I tried to find something about this in specification, but I haven't > found any unambiguous explanation. > Should I report it as a bug? > > org.codehaus.janino.CompileException: Line 6, Column 16: Reference types > "java.lang.String" and "java.lang.Long" don't match > at org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java) > at org.codehaus.janino.UnitCompiler.getType2(UnitCompiler.java) > at org.codehaus.janino.UnitCompiler.access$100(UnitCompiler.java) > at > org.codehaus.janino.UnitCompiler$15.visitConditionalExpression(UnitCompiler.java) > > at org.codehaus.janino.Java$ConditionalExpression.accept(Java.java) > at org.codehaus.janino.UnitCompiler.getType(UnitCompiler.java) > at > org.codehaus.janino.UnitCompiler.findMostSpecificIInvocable(UnitCompiler.java) > > at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java) > at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java) > at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java) > at org.codehaus.janino.UnitCompiler.access$51(UnitCompiler.java) > at > org.codehaus.janino.UnitCompiler$9.visitMethodInvocation(UnitCompiler.java) > at org.codehaus.janino.Java$MethodInvocation.accept(Java.java) > at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java) > at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java) > at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java) > at org.codehaus.janino.UnitCompiler.access$25(UnitCompiler.java) > at > org.codehaus.janino.UnitCompiler$6.visitMethodInvocation(UnitCompiler.java) > at org.codehaus.janino.Java$MethodInvocation.accept(Java.java) > at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java) > at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java) > at org.codehaus.janino.UnitCompiler.access$8(UnitCompiler.java) > at > org.codehaus.janino.UnitCompiler$4.visitExpressionStatement(UnitCompiler.java) > > at org.codehaus.janino.Java$ExpressionStatement.accept(Java.java) > at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java) > at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java) > at org.codehaus.janino.UnitCompiler.access$7(UnitCompiler.java) > at org.codehaus.janino.UnitCompiler$4.visitBlock(UnitCompiler.java) > at org.codehaus.janino.Java$Block.accept(Java.java) > at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java) > at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java) > at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java) > at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java) > at > org.codehaus.janino.UnitCompiler$3.visitPackageMemberClassDeclaration(UnitCompiler.java) > > at > org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java) > at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java) > at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java) > at > org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java) > > at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java) > at org.codehaus.janino.Cookable.cook(Cookable.java) > at org.codehaus.janino.Cookable.cook(Cookable.java) > at org.codehaus.janino.Cookable.cook(Cookable.java) > > Thanks > Martin Varecha > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: overloaded method & ternary operatorHi Arno,
I've done some tests and here are my results. Problem is obviously with some changes in 1.5 compiler. Probably because of generics. * 1.4 compiler - reports an error * 1.5 compiler - reports an error only if 1.4 compatibility is set * 1.6 compiler - reports an error only if 1.4 compatibility is set * 1.5 compiler - compiles without errors * 1.6 compiler - compiles without errors see below for details I'm still confused about error reported by your j2sdk-1.5.0-beta compiler. I believe, that it's because it's just beta release. I understand, that I can't expect from Janino compatibility with 1.5 compiler. Thanks for your help! You are doing great job. regards Martin Varecha mvarecha@mava:~/java> /usr/java/j2sdk1.4.2_16/bin/javac Main.java Main.java:6: incompatible types for ?: neither is a subtype of the other second operand: java.lang.String third operand : java.lang.Long m.method(1==1 ? "a" : new Long(1)); ^ 1 error mvarecha@mava:~/java> /usr/java/jdk1.5.0_14/bin/javac -source 1.4 -target 1.4 -version Main.java javac 1.5.0_14 Main.java:6: incompatible types for ?: neither is a subtype of the other second operand: java.lang.String third operand : java.lang.Long m.method(1==1 ? "a" : new Long(1)); ^ 1 error mvarecha@mava:~/java> /usr/java/jdk1.6.0_03/bin/javac -source 1.4 -target 1.4 -version Main.java javac 1.6.0_03 Main.java:6: incompatible types for ?: neither is a subtype of the other second operand: java.lang.String third operand : java.lang.Long m.method(1==1 ? "a" : new Long(1)); ^ 1 error mvarecha@mava:~/java> /usr/java/jdk1.5.0_14/bin/javac -version Main.java javac 1.5.0_14 mvarecha@mava:~/java> /usr/java/jdk1.6.0_03/bin/javac -version Main.java javac 1.6.0_03 Cituji Arno Unkrig <arno@...>: > Hi Martin, > > all JDK compilers that I have at hand report an error (as I expected), > see below. > > What JDK compiler are you using exactly (java -version)? > > > CU > > Arno > > -------------------------- > > $ JAVA_HOME=/cygdrive/c/jdk-1.2.2; rm -f Main.class; > $JAVA_HOME/bin/java -version && $JAVA_HOME/bin/javac Main.java && > $JAVA_HOME/bin/java Main > java version "1.2.2" > Classic VM (build JDK-1.2.2_017, native threads, symcjit) > Main.java:7: Incompatible type for ?:. Can't convert java.lang.String > to java.lang.Long. > m.method(1==1 ? "a" : new Long(1)); > ^ > 1 error > > Arno@sharon /cygdrive/c/tmp > $ JAVA_HOME=/cygdrive/c/j2sdk1.4.1_02/; rm -f Main.class; > $JAVA_HOME/bin/java -version && $JAVA_HOME/bin/javac Main.java && > $JAVA_HOME/bin/java Main > java version "1.4.1_02" > Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06) > Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode) > Main.java:7: incompatible types > found : java.lang.Long > required: java.lang.String > m.method(1==1 ? "a" : new Long(1)); > ^ > 1 error > > Arno@sharon /cygdrive/c/tmp > $ JAVA_HOME=/cygdrive/c/j2sdk-1.5.0-beta; rm -f Main.class; > $JAVA_HOME/bin/java -version && $JAVA_HOME/bin/javac Main.java && > $JAVA_HOME/bin/java Main > java version "1.5.0-beta" > Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c) > Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode) > Main.java:7: incompatible types for ?: neither is a subtype of the other > second operand: java.lang.String > third operand : java.lang.Long > m.method(1==1 ? "a" : new Long(1)); > ^ > 1 error > > Arno@sharon /cygdrive/c/tmp > $ > > > martin.varecha@... schrieb: >> Hi! >> I have problem with compilation of this code: >> >> public class Main { >> public void method(Object s) {} >> public void method(Long l) {} >> public static void main(String[] args) { >> Main m = new Main(); >> m.method(1==1 ? "a" : new Long(1)); >> } >> }// Main class >> >> I get following error with Janino, but it works with JDK compiler. >> Why is it so? >> I tried to find something about this in specification, but I >> haven't found any unambiguous explanation. >> Should I report it as a bug? >> >> org.codehaus.janino.CompileException: Line 6, Column 16: Reference >> types "java.lang.String" and "java.lang.Long" don't match >> at org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java) >> at org.codehaus.janino.UnitCompiler.getType2(UnitCompiler.java) >> at org.codehaus.janino.UnitCompiler.access$100(UnitCompiler.java) >> at >> org.codehaus.janino.UnitCompiler$15.visitConditionalExpression(UnitCompiler.java) at >> org.codehaus.janino.Java$ConditionalExpression.accept(Java.java) >> at org.codehaus.janino.UnitCompiler.getType(UnitCompiler.java) >> at >> org.codehaus.janino.UnitCompiler.findMostSpecificIInvocable(UnitCompiler.java) at >> org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java) >> at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java) >> at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java) >> at org.codehaus.janino.UnitCompiler.access$51(UnitCompiler.java) >> at >> org.codehaus.janino.UnitCompiler$9.visitMethodInvocation(UnitCompiler.java) >> at org.codehaus.janino.Java$MethodInvocation.accept(Java.java) >> at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java) >> at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java) >> at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java) >> at org.codehaus.janino.UnitCompiler.access$25(UnitCompiler.java) >> at >> org.codehaus.janino.UnitCompiler$6.visitMethodInvocation(UnitCompiler.java) >> at org.codehaus.janino.Java$MethodInvocation.accept(Java.java) >> at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java) >> at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java) >> at org.codehaus.janino.UnitCompiler.access$8(UnitCompiler.java) >> at >> org.codehaus.janino.UnitCompiler$4.visitExpressionStatement(UnitCompiler.java) at >> org.codehaus.janino.Java$ExpressionStatement.accept(Java.java) >> at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java) >> at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java) >> at org.codehaus.janino.UnitCompiler.access$7(UnitCompiler.java) >> at org.codehaus.janino.UnitCompiler$4.visitBlock(UnitCompiler.java) >> at org.codehaus.janino.Java$Block.accept(Java.java) >> at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java) >> at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java) >> at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java) >> at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java) >> at >> org.codehaus.janino.UnitCompiler$3.visitPackageMemberClassDeclaration(UnitCompiler.java) at >> org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java) >> at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java) >> at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java) >> at >> org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java) at >> org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java) >> at org.codehaus.janino.Cookable.cook(Cookable.java) >> at org.codehaus.janino.Cookable.cook(Cookable.java) >> at org.codehaus.janino.Cookable.cook(Cookable.java) >> >> Thanks >> Martin Varecha >> >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> >> >> > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Free embeddable forum powered by Nabble | Forum Help |