JFlex - how to test the scanner - jflex

I've just started to learn JFlex. I am studying one of the official Jflex examples, which is a scanner for the Java language. In the Readme file it says:
The scanner (without parser attached) can be test with:
java TestLexer <inputfiles>
But when I tried this in cmd, I got an error message instead, saying 'Could not find or load main class TestLexer'.Does anyone know why? Thank you in advance.

To test the lexer for Java, JFlex has a depency to the CUP parser generator, did you installed it?
Then there is several commands to make before being able to run the lexer:
jflex unicode.flex
jflex java.flex
java java_cup.Main -interface < java12.cup
javac JavaParser.java TestLexer.java
For the third command, you need to have the java-cup-11a.jar somewhere in your classpath.
Only then you would be able to test the parser:
java JavaParser <inputfiles>
or the scanner:
java TestLexer <inputfiles>

Related

Intellij IDEA Error: Could not find or load main class org.jetbrains.jps.cmdline.Launcher in Scala Project

I am facing the following error when I click Run from simple Hello World program of Scala. I am unable to find any solution as I am beginner in the Java field.
I am currently using IntelliJ IDEA 2021.2.3 which I am trying to integrate with Scala but to no avail.I am following this tutorial to run the Scala Program and Install all the required softwares and libraries as mentioned in this link.
https://www.guru99.com/scala-tutorial.html
Screenshot - Intellij IDEA Error for Scala Program
"C:\Program Files\Java\jdk1.8.0_144\bin\java.exe" -Xmx700m -Djava.awt.headless=true -Djava.endorsed.dirs=\"\" -Dpreload.project.path=D:/Scala-Projects -Dpreload.config.path=C:/Users/Khalid/AppData/Roaming/JetBrains/IdeaIC2021.2/options -Dcompile.parallel=false -Drebuild.on.dependency.change=true -Djdt.compiler.useSingleThread=true -Daether.connector.resumeDownloads=false -Dio.netty.initialSeedUniquifier=-2427656205608767245 -Dfile.encoding=windows-1252 -Duser.language=en -Duser.country=US -Didea.paths.selector=IdeaIC2021.2 -Didea.home.path=D:/Softwares/ideaIC-2021.2.3.win -Didea.config.path=C:/Users/Khalid/AppData/Roaming/JetBrains/IdeaIC2021.2 -Didea.plugins.path=C:/Users/Khalid/AppData/Roaming/JetBrains/IdeaIC2021.2/plugins -Djps.log.dir=C:/Users/Khalid/AppData/Local/JetBrains/IdeaIC2021.2/log/build-log -Djps.fallback.jdk.home=D:/Softwares/ideaIC-2021.2.3.win/jbr -Djps.fallback.jdk.version=11.0.12 -Dio.netty.noUnsafe=true -Djava.io.tmpdir=C:/Users/Khalid/AppData/Local/JetBrains/IdeaIC2021.2/compile-server/helloworld_14920d90/_temp_ -Djps.backward.ref.index.builder=true -Dkotlin.incremental.compilation=true -Dkotlin.incremental.compilation.js=true -Dkotlin.daemon.enabled -Dkotlin.daemon.client.alive.path=\"C:\Users\Khalid\AppData\Local\Temp\kotlin-idea-3911355212386532999-is-running\" -Dtmh.instrument.annotations=true -Dtmh.generate.line.numbers=true -Dcompile.parallel.max.threads=4 -Dcompile.parallel=true -Dscala.compile.server.socket.connect.timeout.milliseconds=10000 -Dscala.compiler.indices.rebuild=true -classpath "D:/Softwares/ideaIC-2021.2.3.win/plugins/java/lib/jps-launcher.jar;C:/Program Files/Java/jdk1.8.0_144/lib/tools.jar" org.jetbrains.jps.cmdline.Launcher D:/Softwares/ideaIC-2021.2.3.win/lib/annotations.jar;D:/Softwares/ideaIC-2021.2.3.win/lib/slf4j.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/java/lib/jps-builders.jar;D:/Softwares/ideaIC-2021.2.3.win/lib/kotlin-stdlib-jdk8.jar;D:/Softwares/ideaIC-2021.2.3.win/lib/jps-model.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/java/lib/javac2.jar;D:/Softwares/ideaIC-2021.2.3.win/lib/forms_rt.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/java/lib/maven-resolver-transport-file-1.3.3.jar;D:/Softwares/ideaIC-2021.2.3.win/lib/util.jar;D:/Softwares/ideaIC-2021.2.3.win/lib/protobuf-java-3.15.8.jar;D:/Softwares/ideaIC-2021.2.3.win/lib/platform-api.jar;D:/Softwares/ideaIC-2021.2.3.win/lib/jna-platform.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/java/lib/aether-dependency-resolver.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/java/lib/jps-javac-extension-1.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/java/lib/jps-builders-6.jar;D:/Softwares/ideaIC-2021.2.3.win/lib/jna.jar;D:/Softwares/ideaIC-2021.2.3.win/lib/idea_rt.jar;D:/Softwares/ideaIC-2021.2.3.win/lib/3rd-party.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/java/lib/maven-resolver-connector-basic-1.3.3.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/java/lib/maven-resolver-transport-http-1.3.3.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/Kotlin/lib/kotlin-reflect.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/Kotlin/lib/kotlin-plugin.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/IntelliLang/lib/java-langInjection-jps.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/eclipse/lib/eclipse-jps.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/eclipse/lib/eclipse-common.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/javaFX/lib/javaFX-jps.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/javaFX/lib/javaFX-common.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/ant/lib/ant-jps.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/Groovy/lib/groovy-jps.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/Groovy/lib/groovy-constants-rt.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/uiDesigner/lib/jps/java-guiForms-jps.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/maven/lib/maven-jps.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/gradle-java/lib/gradle-jps.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/Kotlin/lib/jps/kotlin-jps-plugin.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/Kotlin/lib/kotlin-jps-common.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/Kotlin/lib/kotlin-common.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/space/lib/space-java-jps.jar;D:/Softwares/ideaIC-2021.2.3.win/plugins/devkit/lib/devkit-jps.jar;C:/Users/Khalid/AppData/Roaming/JetBrains/IdeaIC2021.2/plugins/Scala/lib/scala-library.jar;C:/Users/Khalid/AppData/Roaming/JetBrains/IdeaIC2021.2/plugins/Scala/lib/compiler-shared.jar;C:/Users/Khalid/AppData/Roaming/JetBrains/IdeaIC2021.2/plugins/Scala/lib/jps/nailgun.jar;C:/Users/Khalid/AppData/Roaming/JetBrains/IdeaIC2021.2/plugins/Scala/lib/jps/compiler-jps.jar;C:/Users/Khalid/AppData/Roaming/JetBrains/IdeaIC2021.2/plugins/Scala/lib/jps/sbt-interface.jar;C:/Users/Khalid/AppData/Roaming/JetBrains/IdeaIC2021.2/plugins/Scala/lib/jps/incremental-compiler.jar;C:/Users/Khalid/AppData/Roaming/JetBrains/IdeaIC2021.2/plugins/Scala/lib/jps/scala-parallel-collections.jar;C:/Users/Khalid/AppData/Roaming/JetBrains/IdeaIC2021.2/plugins/Scala/lib/spray-json_2.13-1.3.5.jar;C:/Users/Khalid/AppData/Roaming/JetBrains/IdeaIC2021.2/plugins/Scala/lib/scala-compiler-indices-protocol_2.12-0.1.1.jar org.jetbrains.jps.cmdline.BuildMain 127.0.0.1 57901 33b87547-d627-4a07-bd5f-0b53060f32c9 C:/Users/Khalid/AppData/Local/JetBrains/IdeaIC2021.2/compile-server
Error: Could not find or load main class org.jetbrains.jps.cmdline.Launcher
Make sure you are correctly specified the main class in Run configuration dialog:
You can open it from the main toolbar:

Error when calling Native Code using JNI from a Jython module

I am calling a simple HelloWorld program written in C from a Jython module (inside a PyDev project). There is an intermediate Java Class (in a separate Java project) which calls the native code using JNI (Java Native Interface). The native call is successful if I run the Java class directly. But when I call the Java class from my Jython module, I get the following error:
java.lang.UnsatisfiedLinkError: no ctest in java.library.path
I have successfully run several C programs from my Jython module using JNA (Java Native Access). But JNA hits performance (speed) really hard and I want to revisit JNI and fix this problem (also I simply want to know what is going on). The IDE I am using is Eclipse.
Here is the code for the Java class:
package JNIPackage;
public class HelloWorld {
native void helloFromC(); /* (1) */
static {
// Added the line below but still no luck. Was sure this would fix it.
System.setProperty("java.library.path", "/Users/haiderriaz/Desktop/JNI-C");
System.loadLibrary("ctest"); /* (2) */
}
static public void main(String argv[]) {
HelloWorld helloWorld = new HelloWorld();
helloWorld.helloFromC(); /* (3) */
}
}
Running this Java class directly, there is no error and "Hello World" gets printed out. But when I import JNIPackage to my Jython module and then call JNIPackage.HelloWorld, then all of a sudden java can not find ctest. I think this is strange and the problem only exists when calling C code using JNI as opposed to JNA.
Try System.load([full path and filename of ctest]), which works independently from values of LD_LIBRARY_PATH or java.library.path.
To ease user configuration I usually implement my own library-search-mechanism, i.e. make it look for libraries in the working directory and on the classpath too. I know ideologically this is somewhat wrong, but works much smoother for your users. Use java.io.File.exists to confirm the actual location of ctest-file and then use java.io.File.getAbsolutePath() to get the appropriate input for System.load.
System.mapLibraryName(...) can also be useful for this.

Java - running cmd

I'm trying to run a simple java test code. I'm getting a "can not find or load main class file "(something like that)
The tutorial I'm following uses this command
-> javac name.java (javac doesn't work, using ->java ..)
-> dir (shows the classname as a file)
> java classname
> outputs "hello world"
I can't seem to get past the ->java running.java
class apples //everything begins with a class - need this to do anything
{
public static void main(String args[])//method
{
System.out.println("Hello World");
}
}
There could be a few problems here. Check the following:
Are you saving the file as the name of the class plus .java, e.g. apples.java
When you execute it, are you typing the name of the class or the name of the class file? you should be typing java apples, not java apples.class or java apples.java.
EDIT:
I Noticed you haven't compiled the program using javac, which makes the progrm unrunnable by java [program_name]. You need to run javac [java_sourcde_file_name] to generate a .class file. If javac doesn't work, maybe:
You don't have the JDK (Java Development Kit) installed and should download it from Oracle
javac is not in your PATH - unlikely but possible - see http://www.apl.jhu.edu/~hall/java/beginner/settingup.html.
javac runs properly but your program doesn't compile properly. this seems unlikely given the program you posted looks fine.
class Apples //- need this to do anything
{
public static void main(String args[])//everything begins with a method
{
System.out.println("Hello World");
}
}
Make sure you are in current directory of java file
compile as
javac Apples.java
Run as
java Apples
Before working in it , should need to know the coding convention it would be better to work java
Well. All you have to do in Jaca is navigate you where your class files are stored and then use java "class name". You DO NOT need to put .java or .class. Just the name.
change your class name from apples to Apples (naming convention for java class names):
http://en.wikipedia.org/wiki/Naming_convention_%28programming%29#Java
also recommend you to change the file name accordingly...
then recompile and run it
javac Apples.java
java Apples
cheers

Step by step guide to get Scala to run on .net?

I have never used .Net framework and need to demonstrate to someone that Scala indeed works on .Net. I need to get a "quick and dirty" .Net setup with Scala working on some existing JVM Scala code. I could not find a step-by-step guide for this. I would appreciate some resources on this:
How to install minimal .Net and which version to get Scala to work.
How to install the .Net variant of Scala and which version to use (preferred 2.9).
How to get hello world to run.
Thanks in advance.
Platform in question: Windows 7 professional 32 bit.
Self-explaining file
helloworld.scala
/*
see https://github.com/magarciaEPFL/scaladotnet#readme
quick test
==========
1. Name this file helloworld.scala and put it in c:\scala-dotnettest
2. Download binaries from https://github.com/magarciaEPFL/scaladotnet/downloads and unpack the zipped files to the directory c:\scala-dotnet
3. Compile with: c:\scala-dotnet\scalacompiler -d c:\scala-dotnettest -target:exe -Xassem-extdirs c:\scala-dotnet -Xassem-name helloworld.exe -Xshow-class HelloWorld helloworld.scala
4. Copy runtime dependencies scalalib.dll, IKVM.OpenJDK.Core.dll, IKVM.OpenJDK.Util.dll and IKVM.Runtime.dll (or all IKVM*.dll) from c:\scala-dotnet to c:\scala-dotnettest
5. run helloworld
C:\scala-dotnettest>helloworld
Hello World!
*/
object HelloWorld extends App {
println("Hello World!")
}
There are some instructions here:
http://lampwww.epfl.ch/~magarcia/ScalaNET/2011Q2/PreviewScalaNET.pdf
Along with a interview with Miguel Garcia who was (is?) working on it here
http://www.scala-lang.org/node/10299/

GWT Junit - error='no compilation unit for that type was seen'

I'm trying to run a GWT unit test in a sample app. I ran
cmd /c /java/gwt-windows-1.6.4/webAppCreator.cmd -out gwttasks com.gwttasks.GwtTasks
Copied in junit-4.5.jar into a lib directory, and added that to the classpath.
Ran:
cmd /c /java/gwt-windows-1.6.4/junitCreator.cmd -junit lib/junit-4.5.jar -module com.gwttasks.GwtTasks -eclipse GwtTasks com.gwt
tasks.unit.GwtJunit
When I try to run any of the generated cmd file (such as GwtJunit-hosted.cmd) or any of the launch files, I get the following error. All the web pages I've seen say to add the test source to the classpath, but it's already there, so that's not the problem. Anyone else seen this?
com.google.gwt.junit.JUnitFatalLaunchException: The test class 'com.gwttasks.unit.GwtJunit' was not found in module 'com.gwttasks.GwtTasks'; no compilation unit for that type was seen
at com.google.gwt.junit.JUnitShell.checkTestClassInCurrentModule(JUnitShell.java:390)
at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:626)
...
The answer could be found here :
http://raibledesigns.com/rd/entry/testing_gwt_applications
In netbeans I added the src/java and test to the class path and debugging worked!!!!!
THANKS
I just want to add that I had the same problem, because I did the (very silly) mistake to not put the GWTTestCase class into the "client" directory, but into another one. No wonder it wasn't found ;)