javacc testing Simple1.jj - javacc

If you see my other question, you will now better my goals. Take a look at: https://stackoverflow.com/questions/19510039/from-regex-to-parser-generators .
As I'm trying to be a good boy, I'm reading the README (see https://java.net/projects/javacc/sources/svn/show/tags/release_60/examples/SimpleExamples?rev=555 ).
Run javacc on the grammar input file to generate a bunch of Java files that implement the parser and lexical analyzer (or token
manager):
javacc Simple1.jj
Now compile the resulting Java programs:
javac *.java
The parser is now ready to use. To run the parser, type:
java Simple1
My try:
D:\tests\javacc\simple1>javacc ..\Simple1.jj
Java Compiler Compiler Version 6.0_beta (Parser Generator)
(type "javacc" with no arguments for help)
Reading from file ..\Simple1.jj . . .
File "TokenMgrError.java" does not exist. Will create one.
File "ParseException.java" does not exist. Will create one.
File "Token.java" does not exist. Will create one.
File "SimpleCharStream.java" does not exist. Will create one.
Parser generated successfully.
D:\tests\javacc\simple1>javac *.java
SimpleCharStream.java:474: error: non-static variable this cannot be referenced from a static context
static void setTrackLineColumn(boolean trackLineColumn) { this.trackLineColumn = trackLineColumn; }
^
1 error
My java version:
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) Client VM (build 24.45-b08, mixed mode, sharing)
I'm sure that "these" guys known what they are doing, I'm sure I did something wrong, but what? Getting a simple error like that in the first test with javacc?
How can I fix that and continue my lecture?

I suggest using version 5.0 for now. There are a lot of changes in version 6 and these came along with some bugs. There should be an update to version 6 soon. https://java.net/projects/javacc/downloads

Will you put the code to look it or your complete call. I think, that it´s a code error or that you call a bad .java archive. For example:
I have: Mytokens.jj and javaCode.java ok? Good, you need said:
javacc Mytokens.jj
javac javaCode.java
java javaCode <test1.txt>
I give you my *.bat for the test. You create a new txt and write it:
CALL javacc nameJJ.jj
#pause
CALL javac NameJava.java
#pause
java NameJava <prueba1> salida.txt
type salida.txt
#pause
This do the test for you when you do a double-click on it if you have a copy in your javacc/bin and your practice directories.

Related

Replicating a java -jar execution through rJava

I have a java file that I would normally execute by doing
java -jar jarname.jar arguments
I want to be able to run this file from R in the most system agnostic way possible. My current pipeline partially relies on rJava do identify JAVA_HOME and run the jar by doing
# path for the example file below
pathToJar = 'pdftk-java.jar'
# start up java session
rJava::.jinit()
# find JAVA_HOME
javaPath = rJava::.jcall( 'java/lang/System', 'S', 'getProperty', 'java.home' )
# get all java files
javaFiles = list.files(javaPath,recursive = TRUE,full.names = TRUE)
# find java command
java = javaFiles[grepl('/java($|\\.exe)',javaFiles)]
# run the jar using system
system(glue::glue('{shQuote(java)} -jar {shQuote(pathToJar)} arguments'))
This does work fine but I was wondering if there was a reliable way to replicate execution of a jar through rJava itself. I want to do this because
I want to avoid any possible system dependent issues when finding the java command from JAVA_HOME
I already started an rJava session just to get the JAVA_HOME. I might as well use it since .jinit isn't undoable
I not that familiar with what calling a jar through -jar does and I am curious. Can it be done in a jar independent way? If not what should I look for in the code to know how to do this.
This is the file in I am working with. Taken from https://gitlab.com/pdftk-java/pdftk/tree/master
Executing JAR file is (essentially) running class file that is embedded inside JAR.
Instead of calling system and executing it as external application, you can do following:
make sure to add your JAR file to CLASSPATH
rJava::.jaddClassPath(pathToJar)
check inside JAR file what is the main class. Look into META-INF/MANIFEST.MF file to identify the main class. (In this case com.gitlab.pdftk_java.pdftk)
instantiate class inside R.
newObj = rJava::.jnew('com/gitlab/pdftk_java/pdftk')
run the class following way: http://www.owsiak.org/running-java-code-in-r/
Update
Running JAR file (calling main method of Main-class) is the same things as calling any other method inside Java based class. Please note that main method takes array of Strings as argument. Take a look here for sample: http://www.owsiak.org/running-jar-file-from-r-using-rjava-without-spawning-new-process/
newObj$main(rJava::.jarray('--version'))
For this specific case if you look at the source code for this class, you'll see that it terminates the session
public static void main(String[] args) {
System.exit(main_noexit(args));
}
This will also terminate your R session. Since all main function does it to call main_noexit then exit, you can replace main with main_noexit in the code above.
newObj$main_noexit(rJava::.jarray('--version'))

command line compiling generates bigger file than the online version

I am testing google closure compiler on command line.
I took the latest version :
java -jar closure-compiler.jar --version
Closure Compiler (http://github.com/google/closure-compiler)
Version: v20190618
Built on: 2019-06-21 17:24
I am generating a compressed version of my javascript like this :
java -jar closure-compiler.jar my_script.js > out.js
The problem is that the generated code is bigger than the one I get when I use the online service at https://closure-compiler.appspot.com/home
I noticed that the command line version added, at the beginning, the following code :
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.findInternal=function(a,c,b){a instanceof String&&(a=String(a));for(var d=a.length,e=0;e<d;e++){var f=a[e];if(c.call(b,f,e,a))return{i:e,v:f}}return{i:-1,v:void 0}};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1;
$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,c,b){a!=Array.prototype&&a!=Object.prototype&&(a[c]=b.value)};$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this);
$jscomp.polyfill=function(a,c,b,d){if(c){b=$jscomp.global;a=a.split(".");for(d=0;d<a.length-1;d++){var e=a[d];e in b||(b[e]={});b=b[e]}a=a[a.length-1];d=b[a];c=c(d);c!=d&&null!=c&&$jscomp.defineProperty(b,a,{configurable:!0,writable:!0,value:c})}};$jscomp.polyfill("Array.prototype.find",function(a){return a?a:function(a,b){return $jscomp.findInternal(this,a,b).v}},"es6","es3");
I do not have such a code in my script: Where does it come from ?
how can I produce the same output as the online version ?
To get the compiler command line work as the web service, I just added an option :
--language_out=ECMASCRIPT_2015
This is likely a discrepancy between the settings on the web service and the ones you're using locally.
Have a look at a Closure Compiler: Flags and Options to see what settings you might prefer.
If you'd share your source, it'd be possible to try and help you narrow down the options.
As for the extra code, I believe it is at least partially a polyfill for Array.prototype.find (aka [].find), which I assume is in your code?
If so, that's Closure injecting code to improve your cross browser compatibility.

Fail to link to standard library of Ocaml-java (or Cafesterol)

I am a new user of Ocaml-java (or Cafesterol) which compiles primtive Ocaml program to executable jar that is allowed run on JVM. However when I try to compile a test program into executable jar I got error info as follow:
>java -jar ~/ocaml-project/ocamljava-bin-1.4/bin/ocamljava.jar -standalone regexdna.ml -o regexdna.jar
File "regexdna.ml", line 1, characters 0-1:
Error: No implementations provided for the following modules:
Str referenced from regexdna.cmj
Unix referenced from regexdna.cmj
It seems module Str and Unix is missing from Ocaml-java. However, str.jar and unix.jar do exist under ~/ocaml-project/ocamljava-bin-1.4/lib/others/ when I install Ocaml-java, and within these jars we do have Str.class and Unix.class. (I suppose this directory is on the path of the standard library of Ocaml-java, so it should be included in default search path)
Can any Ocaml-java user tell me how Ocaml-java search for dependency libraries?
Quoting Xavier Clerc on this :
Well it should work, but you have to pass explicitly the referenced
library (just as in vanilla OCaml). Leading in your case to:
$ /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java -jar ~/opt/ocamljava-2.0-early-access9/lib/ocamljava.jar str.cmja regexdna.ml
Note that I am using the latest ocamljava preview.

Closure Templates through IKVM?

Google Closure works GREAT without the Java Runtime Environment by using IKVM
In case that ever goes away, the simplified steps to convert it to an exe are:
Download and extract (but nothing to install) Closure Compiler and IKVM
Move compiler.jar to the IKVM bin folder
ikvmc -target:exe -fileversion:2012.09.17 .\compiler.jar (with the jar's release date). Note: I get a few warnings about ANT libraries.
Copy these dependencies from the ikvm bin directory to the closure directory:
IKVM.OpenJDK.Core.dll
IKVM.OpenJDK.Jdbc.dll
IKVM.OpenJDK.Misc.dll
IKVM.OpenJDK.SwingAWT.dll
IKVM.OpenJDK.Text.dll
IKVM.OpenJDK.Util.dll
XML.API.dll
IKVM.Runtime.dll
Then you can move the compiler.jar and new compiler.exe back to your closure directory. Fredrik recommends this powershell version of execution because of the ability to specify ascii encoding overriding unicode (half the bytes):
.\compiler.exe --js .\jquery-1.4.2.js --warning_level QUIET | out-file -encoding ascii .\jquery.min.js
==============================
However, I do not have the same luck with the Closure Templates's SoyToJsSrcCompiler.jar. I get warnings from ikvmc -target:exe -fileversion:2011.12.22 .\SoyToJsSrcCompiler.jar as with compiler.jar.
warning IKVMC0105: Unable to compile class "com.google.template.soy.jssrc.internal.GenerateSoyUtilsEscapingDirectiveCode"
(missing class "org.apache.tools.ant.Task")
warning IKVMC0100: Class "com.google.inject.internal.asm.util.$TraceClassVisitor" not found
warning IKVMC0111: Emitted java.lang.NoClassDefFoundError in "com.google.inject.internal.cglib.core.$DebuggingClassWriter$1.run()Ljava.lang.Object;"
("com.google.inject.internal.asm.util.$TraceClassVisitor")
warning IKVMC0100: Class "com.google.template.soy.jssrc.internal.GenerateSoyUtilsEscapingDirectiveCode" not found
The resulting SoyToJsSrcCompiler.exe with no command-line arguments works to show the help page, but supplying a .soy file gives:
Exception in thread "main" cli.System.MethodAccessException:
com.google.inject.assistedinject.FactoryProvider2.getBindingFromNewInjector(java.lang.reflect.Method, System.Object[], AssistData) at
com.google.inject.assistedinject.FactoryProvider2$$FastClassByGuice$$9dcdf6d7.invoke() at
com.google.inject.internal.cglib.reflect.$FastMethod.invoke(FastMethod.java:53) at
com.google.inject.internal.SingleMethodInjector$1.invoke(SingleMethodInjector.java:56) at
com.google.inject.internal.SingleMethodInjector.inject(SingleMethodInjector.java:90) at
com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:107) at
com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:76) at
com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:73) at
com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1031) at
com.google.inject.internal.MembersInjectorImpl.injectAndNotify(MembersInjectorImpl.java:88) at
com.google.inject.internal.Initializer$InjectableReference.get(Initializer.java:150) at
com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:40) at
com.google.inject.internal.SingleFieldInjector.inject(SingleFieldInjector.java:53) at
com.google.inject.internal.InjectionRequestProcessor$StaticInjection$1.call(InjectionRequestProcessor.java:11 6) at
com.google.inject.internal.InjectionRequestProcessor$StaticInjection$1.call(InjectionRequestProcessor.java:11 0) at
com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1024) at
com.google.inject.internal.InjectionRequestProcessor$StaticInjection.injectMembers(InjectionRequestProcessor. java:110) at
com.google.inject.internal.InjectionRequestProcessor.injectMembers(InjectionRequestProcessor.java:78) at
com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:171) at
com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:111) at
com.google.inject.Guice.createInjector(Guice.java:95) at
com.google.inject.Guice.createInjector(Guice.java:72) at
com.google.template.soy.MainClassUtils.createInjector(MainClassUtils.java:212) at
com.google.template.soy.SoyToJsSrcCompiler.execMain(SoyToJsSrcCompiler.java:223) at
com.google.template.soy.SoyToJsSrcCompiler.main(SoyToJsSrcCompiler.java:205)
Anyone know how to get this to work?
The exception can be an bug in IKVM. Which version do you use? Test the latest version.
warning IKVMC0100: Class "com.google.template.soy.jssrc.internal.GenerateSoyUtilsEscapingDirectiveCode" not found
Another problem can be that you have not compile all needed jar files for SoyToJsSrcCompiler.jar. In which jar file is this missing class file? Take a look in the wiki to see how you compile multiple jar files.
The next problem can be that there is the same package in different jar files. It there are only package visible for some mthods this will not work for .NET. You can test a sharedclassloader. See the wiki for details.

How to use QCA library in Qt

I have used QCA (qca-2.0.1-mingw) library for encryption.
I have searched some code and write into the application. But it does not support the AES encryption standard.
e.g
QCA::supportedFeatures();
QCA::isSupported("aes128-cbc-pkcs7");
shows the o/p
("random", "md5", "sha1", "keystorelist")
false
Why AES is not supported ?
Thanx.. Frank and elmigranto
now, i have download qca-ossl-2.0.0-beta3 form link and also install the OpenSSl(Win32OpenSSL-1_0_0j.exe).then i build it by follows this link
configwin rd
Configuring for release and debug, dynamic
Wrote conf_win.pri
qmake
C:\qca-ossl-2.0.0-beta3>qmake
'qmake' is not recognized as an internal or external command,
operable program or batch file.
Also when i build the qca-ossl.pro file it shows o/p as:
c:\qca-ossl-2.0.0-beta3\qca-ossl.pro:17: warning: Unable to find file for inclusion winlocal.prf
what to do next? pls help me guys..

Resources