Error running ParseTree - rascal

In the Rascal shell, doing this:
import lang::c90::\syntax::C;
import ParseTree;
parse(#TranslationUnit, |file:///teste.c|);
I get in the stable standalone jar:
|prompt:///|(24,93,<1,24>,<1,117>): ParseError(|file:///home/rafael2k/files/UnB/static_analysis/eclipse-workspace/rascal-C/c-source/teste.c|(47,0,<4,0>,<4,0>))
at parse(|prompt:///|(24,93,<1,24>,<1,117>))
at *** somewhere ***(|prompt:///|(24,93,<1,24>,<1,117>))
at parse(|prompt:///|(24,93,<1,24>,<1,117>))
And in Eclipse I get a giant message error:
(...)
public AbstractStackNode<IConstructor>[] FloatingPointConstant() {
return FloatingPointConstant.EXPECTS;
}
public AbstractStackNode<IConstructor>[] StructDeclarator() {
return StructDeclarator.EXPECTS;
}
}
Advice: |http://tutor.rascal-mpl.org/Errors/Static/JavaCompilation/JavaCompilation.html|null
Any tip?
Btw, running Debian Jessie, Oracle Java 1.8.0_112,x86_64.

I think it can be fixed with this:
parse(#start[TranslationUnit], |file:///teste.c|);
By using a start non-terminal you can parse files which begin and/or end with whitespace or source code comments. See also the answer to this question: Layout in Rascal
By the way, this grammar will parse c programs after the processor has been applied.
The Eclipse error is a seemingly unrelated issue for which we would love to receive a stack trace on the github issue tracker.

Related

Using java in rascal

I have made a java function genImage(List<String lines) which is located in class vis. I am trying to import it into my rascal code, but it won't work. This is the last of my efforts to import it:
#javaClass{visualization.vis}
java void genImage(list[str] lines);
The error I get:
Cannot link method visualization.vis because: visualization.vis.(io.usethesource.vallang.IValueFactory)
Advice: |http://tutor.rascal-mpl.org/Errors/Static/JavaMethodLink/JavaMethodLink.html%7C
The #javaClass tag must point to a fully qualified classname, including the package and the class. It seems it's the class you are missing, right?

Basic and enhanced dependencies give different results in Stanford coreNLP

I am using dependency parsing of coreNLP for a project of mine. The basic and enhanced dependencies are different result for a particular dependency.
I used the following code to get enhanced dependencies.
val lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz")
lp.setOptionFlags("-maxLength", "80")
val rawWords = edu.stanford.nlp.ling.Sentence.toCoreLabelList(tokens_arr:_*)
val parse = lp.apply(rawWords)
val tlp = new PennTreebankLanguagePack()
val gsf:GrammaticalStructureFactory = tlp.grammaticalStructureFactory()
val gs:GrammaticalStructure = gsf.newGrammaticalStructure(parse)
val tdl = gs.typedDependenciesCCprocessed()
For the following example,
Account name of ramkumar.
I use simple API to get basic dependencies. The dependency i get between
(account,name) is (compound). But when i use the above code to get enhanced dependency i get the relation between (account,name) as (dobj).
What is the fix to this? Is this a bug or am i doing something wrong?
When I run this command:
java -Xmx8g edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,ner,parse -file example.txt -outputFormat json
With your example text in the file example.txt, I see compound as the relationship between both of those words for both types of dependencies.
I also tried this with the simple API and got the same results.
You can see what simple produces with this code:
package edu.stanford.nlp.examples;
import edu.stanford.nlp.semgraph.SemanticGraphFactory;
import edu.stanford.nlp.simple.*;
import java.util.*;
public class SimpleDepParserExample {
public static void main(String[] args) {
Sentence sent = new Sentence("...example text...");
Properties props = new Properties();
// use sent.dependencyGraph() or sent.dependencyGraph(props, SemanticGraphFactory.Mode.ENHANCED) to see enhanced dependencies
System.out.println(sent.dependencyGraph(props, SemanticGraphFactory.Mode.BASIC));
}
}
I don't know anything about any Scala interfaces for Stanford CoreNLP. I should also note my results are using the latest code from GitHub, though I presume Stanford CoreNLP 3.8.0 would also produce similar results. If you are using an older version of Stanford CoreNLP that could be a potential cause of the error.
But running this example in various ways using Java I don't see the issue you are encountering.

HHVM non-deterministic behaviour of the typechecker

I've noticed that calling hh_client is not always returning correct result. For example: I have following pieces of code:
backend\ConvertMessage.hh:
<?hh // strict
namespace ApiBackend\ConvertMessage {
enum Status: int {
success = 0;
// ... error codes
};
// ... some other classes
};
other place in project:
throw new \SoapFault(
'Server',
\ApiBackend\ConvertMessage\Status::getNames()[$result->status]
);
Sometimes, after doing some changes in project I get following error message: Could not find static method getNames in type ApiBackend\ConvertMessage\Status (Typing[4090])
When I remove a semicolon after one of closing curly brackets, hh_client stops displaying error. But when I insert semicolon back on its place, typechecker still gives me No errors! message.
This is not the only file that causes this problem - it happens to all enums.
It seems to me that it is problem with some cache of either hh_client or hh_server.
Thanks in advance for helping me with solving this problem (and sorry if my english is not too good).
You are probably using an outdated version of HHVM. This problem sounds an awful lot like this race condition, which was fixed in HHVM 3.5.0 and newer (and was backported into the 3.3.3 LTS release). Notably, 3.4.x still had the bug.
What version of HHVM are you using?

Get warnings when programmatically parsing Dart file with analyzer_experimental

I am using analyzer_experimental to parse a Dart file into a CompilationUnit:
import 'package:analyzer_experimental/analyzer.dart';
var unit;
try {
unit = parseDartFile(path);
} on AnalyzerErrorGroup catch(e){
print(e);
}
The above code will catch any parsing errors encountered.
I am also interested in seeing any warnings associated with the file (e.g. 'Undefined name "foo"'). I know that the experimental_analyzer library has the capability to generate these warnings when running from the command line but it does not seem to be possible to get the warnings programmatically, without directly referencing classes in the src folder (which seems like a bad idea).
Is there any way to achieve this?
It's likely this package was very incomplete at the time.
There's now an analyzer package on pub and also a (work-in-progress) STDIN/STDOUT Analyzer Service aimed to help making tooling support easier for IDE extension authors.

javac will not compile enum, ( Windows Sun 1.6 --> OpenJDK 1.6)

package com.scheduler.process;
public class Process {
public enum state {
NOT_SUBMITTED, SUBMITTED, BLOCKED, READY, RUNNING, COMPLETED
}
private state currentState;
public state getCurrentState() {
return currentState;
}
public void setCurrentState(state currentState) {
this.currentState = currentState;
}
}
package com.scheduler.machine;
import com.scheduler.process.Process;
import com.scheduler.process.Process.state;
public class Machine {
com.scheduler.process.Process p = new com.scheduler.process.Process();
state s = state.READY; //fails if I don't also explicitly import Process.state
p.setCurrentState(s); //says I need a declarator id after 's'... this is wrong.
p.setCurrentState(state.READY);
}
Modified the example to try and direct to the issue. I cannot change the state on this code. Eclipse suggests importing Process.state like I had on my previous example, but this doesn't work either. This allows state s = state.READY but the call to p.setCurrentState(s); fails as does p.setCurrentState(state.READY);
Problem continued.... Following Oleg's suggestions I tried more permutations:
package com.scheduler.machine;
import com.scheduler.process.Process;
import com.scheduler.process.Process.*;
public class Machine {
com.scheduler.process.Process p = new com.scheduler.process.Process();
public state s = Process.state.READY;
p.setCurrentState(s);
p.setCurrentState(state.READY);
}
Okay. It's clear now that I'm a candidate for lobotomy.
package com.scheduler.machine;
import com.scheduler.process.Process;
import com.scheduler.process.Process.state;
public class Machine {
public void doStuff(){
com.scheduler.process.Process p = new com.scheduler.process.Process();
state s = state.READY; //fails if I don't also explicitly import Process.state
p.setCurrentState(s); //says I need a declarator id after 's'... this is wrong.
p.setCurrentState(state.READY);
}
}
I needed to have a method in the class--but we're still missing something (probably obvious) here. When I go via the command line and run javac on the Machine class AFTER compiling Process, I still get the following error:
mseil#context:/media/MULTIMEDIA/Scratch/Scratch/src/com/scheduler/machine$ javac Machine.java
Machine.java:3: package com.scheduler.process does not exist
import com.scheduler.process.Process;
^
So I guess the question now becomes, what idiot thing am I missing that is preventing me from compiling this by hand that eclipse is doing for me behind the scene?
======
Problem solved here:
Java generics code compiles in eclipse but not in command line
This has just worked for me:
Download latest Eclipse
Create new project
Create two packages com.scheduler.process and com.scheduler.machine
Create class Process in package com.scheduler.process and class Machine in com.scheduler.machine and copy their contents from your post modifying them to conform to Java language syntax, like this:
Everything compiles right away.
------ to answer the previous version of the question ------
To answer the question as it is right now: you need to either
import com.scheduler.process.Process.status or import com.scheduler.process.Process.* and refer to status as just status
or
import com.scheduler.process.* or import com.scheduler.process.Process and refer to status as Process.status
------ to answer the original version of the question ------
You can't import classes that are not inside some package. You just can't. It is a compile time error to import a type from the unnamed package.
You don't need to import anything if your classes are in the same package, or if all of your classes are packageless.
If Process class was inside some package it would be possible to import just its status inner class: import a.b.c.Process.status would work just fine.
All your Windows/Linux migration issues don't have anything to do with Java and exceptions that you see. import Process.state; will produce exception on any OS because you can't import classes that don't belong to any package.
Eclipse doesn't use the Sun JDK by default. I would assume that you are using Eclipse's built in compiler as Sun's JDK and the OpenJDK are almost identical.
Java code compiles and runs exact the same on Windows and Linux most of the time (unless you use a few of the platform specific operations)
I suspect you are not building the code the same way and when you compile Machine, the Process class has not been compiled.
I suggest you use a standard build system like maven or ant and it will build the same everywhere. Failing that run Eclipse on Linux or just the same .class you use on windows as they don't need to be re-compiled in any case.
BTW: You don't need to import Process.state as it not used and its in the same package (so you wouldn't need to if you did)

Resources