Jflex and CUP not working on vscode and mac - jflex

I downloaded jflex by doing brew install jflex everything worked the way it should.
But now when I'm trying to make it work with java_cup.runtime.*. And I keep getting the errors below
Lexer.java:681: error: cannot find symbol
{ return new java_cup.runtime.Symbol(sym.EOF); }
^
symbol: variable sym
location: class Lexer
My proffesor said,
"The Symbol class is
part of the parser (JavaCUP)’s runtime jar file. You may use it in the lexer simply by
setting the classpath to include the jar file from JavaCUP and importing it"
So I made bash file below and did what he said and it is not working.
#!/bin/bash
jflex MiniJava.jflex
javac -cp "/Users/carlosfield/Desktop/School/csc453/java-cup-bin-11b-20160615/java-cup-11b.jar" Lexer.java
java -cp "/Users/carlosfield/Desktop/School/csc453/java-cup-bin-11b-20160615/java-cup-11b-runtime.jar" Lexer Factorial.java
rm Lexer*
This is my jflex file
import java.util.*;
import java_cup.runtime.*;
%%
%class Lexer
%cup
%line
%column
%{
private Symbol symbol(int type) {
return new Symbol(type, yyline, yycolumn);
}
private Symbol symbol(int type, Object value) {
return new Symbol(type, yyline, yycolumn, value);
}
%}
WhiteSpace = [ \t\r\n]
Identifier = [a-zA-Z_][a-zA-Z0-9_]*
Integer = 0 | [1-9][0-9]*
%%
“+” { }

The fix for this issue is that if you use %cup in your jflex file you must then make your own sym class which contains public static final int EOF=0.

Related

AOSP build: Api check failed when replacing public java files under frameworks/base/core with prebuilt .jar

I am compiling Android 8.1 AOSP, I want to remove any specified java files under frameworks/base/services and frameworks/base/core, and build the removed java files into .jar libraries, then add the library to framework to make it compile successfully. I succeeded in frameworks/base/services, but failed with API check when do it in frameworks/base/core.
What I did:
Disable JACK compile tool, modify file build/make/core/combo/javac.mk
ANDROID_COMPILE_WITH_JACK := false
Copy frameworks/base/core/java/android/app/ActivityManager.java to frameworks/base/core/mytest/core/java/ActivityManager.java
Create frameworks/base/core/mytest/Android.mk:
include $(CLEAR_VARS)
LOCAL_MODULE := frameworks.base.core.mytest
LOCAL_SRC_FILES += \
$(call all-java-files-under,core/java)
# depends on it to make compilition success
LOCAL_JAVA_LIBRARIES := services
include $(BUILD_STATIC_JAVA_LIBRARY)
Run command: mmm frameworks/base/core/mytest
Then it will generat a .jar file: out/target/product/mydevice/obj/JAVA_LIBRARIES/frameworks.base.core.mytest_intermediates/javalib.jar, copy it into prebuilt/mylibs/
Create prebuilt/mylibs/Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
# my lib is named as 'myam'
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += myam:javalib.jar
include $(BUILD_MULTI_PREBUILT)
Modify frameworks/base/Android.mk, in framework module, add line:
LOCAL_MODULE := framework
# add my lib to framework.jar
LOCAL_STATIC_JAVA_LIBRARIES += myam
REMOVE the original file: rm frameworks/base/core/java/android/app/ActivityManager.java
Run make command to build the AOSP project, I got the error log:
javadoc: error - In doclet class com.google.doclava.Doclava, method start has thrown an exception java.lang.reflect.InvocationTargetException
java.lang.IllegalArgumentException: Unable to find ActivityManager.java. This is usually because doclava has been asked to generate stubs for a file that isn't present in the list of input source files but exists in the input classpath.
at com.google.doclava.Stubs.parseLicenseHeader(Stubs.java:656)
at com.google.doclava.Stubs.writeClassFile(Stubs.java:635)
Where throws the exception is in external/doclava/src/com/google/doclava/Stubs.java:
private static String parseLicenseHeader(/* #Nonnull */ SourcePositionInfo positionInfo) {
//...
File sourceFile = new File(positionInfo.file);
if (!sourceFile.exists()) {
throw new IllegalArgumentException("Unable to find " + sourceFile +
". This is usually because doclava has been asked to generate stubs for a file " +
"that isn't present in the list of input source files but exists in the input " +
"classpath.");
}
Since the source file has been removed, so I specified the source file path to a Stub file that generated by a previous successful built:
out/target/common/obj/JAVA_LIBRARIES/android_system_stubs_current_intermediates/src/android/app/ActivityManager.java, copy it to /data1/myAOSProot/generated/stubs/ActivityManager.java,
private static String parseLicenseHeader(/* #Nonnull */ SourcePositionInfo positionInfo) {
//...
File sourceFile = new File(positionInfo.file);
if (!sourceFile.exists()) {
// As it can't find the source file, I specified it as below:
if (positionInfo.file.equals("ActivityManager.java") || positionInfo.file.endsWith("/ActivityManager.java")) {
sourceFile = new File("/data1/myAOSProot/generated/stubs/ActivityManager.java");
} else {
throw new IllegalArgumentException("Unable to find " + sourceFile +
". This is usually because doclava has been asked to generate stubs for a file " +
"that isn't present in the list of input source files but exists in the input " +
"classpath.");
}
}
But I got a new error:
ActivityManager.java:0: warning: Method android.app.ActivityManager.TaskSnapshot.getSnapshot returns unavailable type GraphicBuffer m.position? ActivityManager.java [110]
ActivityManager.java:0: warning: Method android.app.ActivityManager.getGrantedUriPermissions returns unavailable type ParceledListSlice m.position? ActivityManager.java [110]
ActivityManager.java:0: warning: Method android.app.ActivityManager.getService returns unavailable type IActivityManager m.position? ActivityManager.java [110]
ActivityManager.java:0: warning: Parameter of unavailable type android.content.pm.IPackageDataObserver in android.app.ActivityManager.clearApplicationUserData() [110]
out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/core/java/android/app/IActivityManager.java:10691: warning: Parameter of hidden type android.app.ContentProviderHolder in android.app.IActivityManager.publishContentProviders() [110]
out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/core/java/android/app/IApplicationThread.java:2321: warning: Parameter of hidden type android.app.ResultInfo in android.app.IApplicationThread.scheduleSendResult() [110]
out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/core/java/android/app/IApplicationThread.java:2322: warning: Parameter of hidden type android.app.ResultInfo in android.app.IApplicationThread.scheduleLaunchActivity() [110]
out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/core/java/android/app/IApplicationThread.java:2341: warning: Parameter of hidden type android.app.ResultInfo in android.app.IApplicationThread.scheduleRelaunchActivity() [110]
This is because of the #hide or #removed comments in GraphicBuffer.java etc., I try ignoring the errors by comment the codes reporting error in external/doclava/src/com/google/doclava/Errors.java:
public static void error(Error error, SourcePositionInfo where, String text) {
// all commented
}
But still, another error:
out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/android/content/pm/ParceledListSlice.java:19: error: cannot find symbol
extends android.content.pm.BaseParceledListSlice<T>
^
symbol: class BaseParceledListSlice
location: package android.content.pm
out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/android/app/IApplicationThread.java:13: error: cannot find symbol
public abstract void scheduleSendResult(android.os.IBinder token, java.util.List<android.app.ResultInfo> results) throws android.os.RemoteException;
^
symbol: class ResultInfo
location: package android.app
out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/android/app/IApplicationThread.java:14: error: cannot find symbol
public abstract void scheduleLaunchActivity(android.content.Intent intent, android.os.IBinder token, int ident, android.content.pm.ActivityInfo info, android.content.res.Configuration curConfig, android.content.res.Configuration overrideConfig, android.content.res.CompatibilityInfo compatInfo, java.lang.String referrer, com.android.internal.app.IVoiceInteractor voiceInteractor, int procState, android.os.Bundle state, android.os.PersistableBundle persistentState, java.util.List<android.app.ResultInfo> pendingResults, java.util.List<com.android.internal.content.ReferrerIntent> pendingNewIntents, boolean notResumed, boolean isForward, android.app.ProfilerInfo profilerInfo) throws android.os.RemoteException;
^
symbol: class ResultInfo
location: package android.app
out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/android/app/IApplicationThread.java:33: error: cannot find symbol
public abstract void scheduleRelaunchActivity(android.os.IBinder token, java.util.List<android.app.ResultInfo> pendingResults, java.util.List<com.android.internal.content.ReferrerIntent> pendingNewIntents, int configChanges, boolean notResumed, android.content.res.Configuration config, android.content.res.Configuration overrideConfig, boolean preserveWindow) throws android.os.RemoteException;
^
symbol: class ResultInfo
location: package android.app
The files reporting error like out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/android/content/pm/ParceledListSlice.java actually is NOT existed in a NORMAL AOSP compiling, and the file it refers like BaseParceledListSlice.java is just under the same directory as ParceledListSlice.java, I am confused why would this error happen.
Did I miss anything or is there a different way to achieve my goal? I just want to replace java files to .jar libraries.
Anyone could help me out? Thanks a lot!

How do I get args passed to this scala object?

I'm trying to figure out how to pass args to this scala object:
I have this class written in this sbt project path: allaboutscala/src/main/scala/gzip_practice/gzipwriter
package gzip_practice
import java.io._
import java.util.zip._
/** Gzcat
*/
object gzcat extends App {
private val buf = new Array[Byte](1024)
try {
for (path <- args) {
try {
var in = new GZIPInputStream(new FileInputStream(path))
var n = in.read(buf)
while (n >= 0) {
System.out.write(buf, 0, n)
n = in.read(buf)
}
}
catch {
case _:FileNotFoundException =>
System.err.printf("File Not Found: %s", path)
case _:SecurityException =>
System.err.printf("Permission Denied: %s", path)
}
}
}
finally {
System.out.flush
}
}
This is an sbt project called allaboutscala. I am trying to run it with:
scala src/main/scala/gzip_practice/gzipwriter.scala "hi" but the command just hangs and I don't know why.
How am I supposed to run this object constructor with args?
You can use the scala command as a script runner.
Normally, it will wrap your "script" code in a main method.
But if you have an object with a main method, like your App, it will use that for the entry point.
However, it doesn't like package statements in the script.
If you comment out your package statement, you can compile and run with:
scala -nc somefile.scala myarg.gz
-nc means "no compile daemon"; otherwise, it will start a second process to compile scripts, so that subsequent compiles go faster; but it is a brittle workflow and I don't recommend it.
I confirmed that your code works.
Usually, folks use sbt or an IDE to compile and package in a jar to run with scala myapp.jar.
An object is a static instance of a class. You could construct it using:
object gzcat(args: String*) extends App {
...
}
args is bound as a val within the object gzcat.
Are you trying to run it with repl? I would suggest running it with sbt, then you can run sbt projects from project root directory with command line parameter as follows:
sbt "run file1.txt file2.txt"
The quotes are required. If you leave sbt shell open, then it running it will be much faster. Open shell in project root with
sbt
In the sbt shell:
run file1.txt file2.txt
Within the sbt shell, no quotes.

Getting error in eclipse for spock's #Shared annotation

As a try, I created a simple groovy class in eclipse and wrote a simple spock test method.
I created one object with #Shared annotation and eclipse is complaining like:
Multiple markers at this line
- Groovy:unable to resolve class Shared , unable to find class
for annotation
- Groovy:class Shared is not an annotation in #Shared
I googled a little but did not find the solution. Does anyone know why this error is occurring? Below is the sample code:
class SimpleSpockTestExampleSpec extends Specification {
#Shared
MyObject obj;
def "length of Spock's and his friends' names"()
{
expect:"Replaces when-then block"
name.size() == length
where:
name << ["zzzzz","xxx","yyy"]
length << [5,6,7]
}
}
Pease ignore the line numbers in the image.
It seems that you haven't imported appropriate package. Do you have the following statement in the code:
import spock.lang.Shared
?

Inline::java STUDY configuration

The Inline docs aren't too helpful in learning how to use the STUDY config,
can anyone clarify the syntax involved in calling a simple void method that prints a method, say, Hello() ?
Also, in terms of the external java file, is there a specific directory i need to put it in, or does it go in the same directory of the perl script?
Let's start with the file /home/foo/java_src/Hello.java, which contains:
public class Hello {
public Hello() {}
public void instance_hello() { System.out.println("hello world"); }
public static void static_hello() { System.out.println("HELLO WORLD"); }
}
Tackling your second question first, the first argument after use Inline Java ... can be a filename, and so you can put your source file anywhere and refer to it by its file name in your perl code:
use Inline Java => '/home/foo/java_src/Hello.java';
$obj = Hello->new();
$obj->instance_hello(); # "hello world"
Hello->static_hello(); # "HELLO WORLD"
Note that you don't need STUDY so far. The Hello class is defined in source code that is read directly by the Inline::Java module, so the module automatically creates and populates the Hello namespace in Perl.
STUDY is for classes that aren't parsed directly by Inline::Java. So let's say instead that our Hello class has been compiled into a jar file called /home/foo/jars/hello.jar. Now to use the Hello class you would need to (1) include hello.jar in your CLASSPATH and (2) use STUDY to tell Inline::Java to create the Hello namespace:
use Inline Java => 'STUDY',
CLASSPATH => '/home/foo/jars/hello.jar',
STUDY => ['Hello'];
$obj = Hello->new;
Hello->static_hello; # "HELLO WORLD"
$obj->instance_hello; # "hello world"
We include the first argument STUDY to signal to the Inline::Java that we're not passing any source code directly to the module. We could have also passed valid source code or a valid source code filename.
use Inline Java => 'public class Nothing() { }',
CLASSPATH => '/home/foo/jars/hello.jar',
STUDY => ['Hello'];

How can I import other files in Vala?

The question pretty much says it all- how could I import file2.vala to file1.vala?
You don't do it directly. If you run valac file1.vala file2.vala, it is as if you compiled them in one big file.
If you want to make them reusable, then you probably want a shared library. In which case, you compile one to produce a C header file and a VAPI definition:
valac --vapi file1.vapi -H file1.h --library libfile1.so file1.vala
The second one can then consume this:
valac --pkg file1 file2.vala
This assume that the VAPI file has been installed. If this is not the case, you'll need to pass --vapidir and the location where file1.vapi exists, probably .. Similarly, you'll need to inform the C compiler about where file1.h lives with -X -I/directory/containing, again, probably -X -I.. Finally, you'll need to tell the C linker where libfile1.so is via -X -L/directory/containing -X -lfile1. This is a little platform specific, and you can smooth the difference out using AutoMake, though this is a bit more involved. Ragel is the usual go-to project for how to use AutoMake with Vala.
just to supply apmasell:
you can use multiple files by using classes and public variables:
main.vala:
extern void cfunction(string text);
void main ()
{
first f = new first ();
f.say_something(f.mytext);
cfunction("c text\n");
}
class.vala:
public class first {
public string mytext = "yolo\n";
public first ()
{
stdout.printf("text from constructer in first\n");
}
public void say_something(string text)
{
stdout.printf("%s\n", text);
}
}
text.c:
#include <stdio.h>
void cfunction(const char *s)
{
puts("This is C code");
printf("%s\n", s);
}
compiles with: valac class.vala main.vala text.c
as you can see, you can even use C code