problem antlrworks code too large - parsing

In Antlrworks I get this error:
[18:21:03] Checking Grammar Grammar.g...
[18:21:26] Grammar.java:12: code too large
[18:21:26] public static final String[] tokenNames = new String[] {
[18:21:26] ^
[18:21:26] 1 error
Using instead the generated code in a Java project works normally. What can be had this problem?
Thanks.

For larger grammars, it's easier to split your grammar into bite-sized chunks (at least a separate lexer and parser). If you do so, ANTLRWorks will probably stop complaining as well.
Checkout the Wiki entry about "Composite grammars".

Related

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.

Error using rascal Java15 grammar

I tried to parse some Java Code using the Java15 grammar of Rascal. However, it does not accept the declaration of local variable of parameterized types. In more details:
it does not recognize List<String> files = ...
it recognizes final List<String> files = ...
it recognizes List<String, String> files = ...
It seems to me that the problem is related to some ambiguity involving LocalVarDecStatements and expressions involving "<" and ">". However, I could not figure out how to fix the problem.
I'm not one to say "works for me", but it does :-) See:
rascal>import lang::java::\syntax::Java15;
ok
rascal>import ParseTree;
ok
rascal>parse(#LocalVarDec, "List\<String\> files = null")
LocalVarDec: (LocalVarDec) `List<String> files = null`
Could you provide the example or a simplified example which has the error in it?

How parse Perl 6 code using STD.pm6 grammar?

I would like minimal working example of parsing Perl 6 code from Perl 6 using STD.pm6
Running something like this
use v6;
use STD.pm6;
my $j = slurp 'e:\src\perl6\valid-p6-script.p6';
my $o = STD::Grammar.parse($j);
say $o.perl;
under debugger give me absolutely weird output:
e:\src\prg\perl6>c:\rakudo\bin\perl6-debug-m.bat -I. p6.p6
>>> LOADING p6.p6
>>> LOADING E:\src\prg\perl6\STD.pm6
Unhandled exception: ctxlexpad needs an MVMContext
at gen/moar/m-CORE.setting:15136 (C:\rakudo/share/perl6/runtime/CORE.setting.moarvm::24)
from gen/moar/m-CORE.setting:15250 (C:\rakudo/share/perl6/runtime/CORE.setting.moarvm:AT-KEY:95)
from gen/moar/m-CORE.setting:4291 (C:\rakudo/share/perl6/runtime/CORE.setting.moarvm:postcircumfix:<{ }>:4294967295)
from C:\rakudo/share/perl6/lib/Debugger/UI/CommandLine.pm:736 (C:\rakudo\share\perl6\lib\Debugger\UI\CommandLine.pm.mo
arvm::82)
from gen/moar/m-CORE.setting:2826 (C:\rakudo/share/perl6/runtime/CORE.setting.moarvm:sink-all:168)
from gen/moar/m-CORE.setting:10187 (C:\rakudo/share/perl6/runtime/CORE.setting.moarvm:sink:36)
from C:\rakudo/share/perl6/lib/Debugger/UI/CommandLine.pm:730 (C:\rakudo\share\perl6\lib\Debugger\UI\CommandLine.pm.mo
arvm:unhandled:114)
from C:\rakudo/share/perl6/lib/Debugger/UI/CommandLine.pm:721 (C:\rakudo\share\perl6\lib\Debugger\UI\CommandLine.pm.mo
arvm::25)
from gen/moar/m-Metamodel.nqp:3586 (C:\rakudo\share\nqp\lib/Perl6/Metamodel.moarvm:enter:28)
from gen/moar/m-CORE.setting:5190 (C:\rakudo/share/perl6/runtime/CORE.setting.moarvm:CALL-ME:57)
from gen/moar/m-BOOTSTRAP.nqp:2749 (C:\rakudo/share/nqp/lib/Perl6/BOOTSTRAP.moarvm::93)
from gen\moar\stage2\NQPHLL.nqp:1425 (C:\rakudo\share\nqp\lib/NQPHLL.moarvm:command_eval:380)
from src/Perl6/Compiler.nqp:59 (C:\rakudo\share\nqp\lib/Perl6/Compiler.moarvm:command_eval:93)
from gen\moar\stage2\NQPHLL.nqp:1365 (C:\rakudo\share\nqp\lib/NQPHLL.moarvm:command_line:114)
from gen/moar/m-perl6-debug.nqp:497 (C:\rakudo\share\perl6\runtime\perl6-debug.moarvm:MAIN:190)
from gen/moar/m-perl6-debug.nqp:440 (C:\rakudo\share\perl6\runtime\perl6-debug.moarvm:<mainline>:68)
from <unknown>:1 (C:\rakudo\share\perl6\runtime\perl6-debug.moarvm:<main>:8)
from <unknown>:1 (C:\rakudo\share\perl6\runtime\perl6-debug.moarvm:<entry>:9)
or without debugger:
e:\src\prg\perl6>c:\rakudo\bin\perl6.bat -I. p6.p6
===SORRY!=== Error while compiling E:\src\prg\perl6\STD.pm6
Semicolon form of 'grammar' without 'unit' is illegal. You probably want to use 'unit grammar'
at E:\src\prg\perl6\STD.pm6:8
------> :ver<6.0.0.alpha>:auth<http://perl.org>;<HERE><EOL>
from p6.p6:2
STD.pm6 was the reference grammar/verifier maintained by Larry during the development of the various Perl 6 compilers (Rakudo, Pugs, Niecza, ...). It comes with a dedicated tool called viv that translates it to Perl 5. As far as I know, it never ran on any of the mainstream compilers.
With the 6.c language release, the torch of reference implementation has essentially passed on to Rakudo, which uses its own grammar written in NQP to parse Perl 6.
While this Grammar (in combination with the corresponding actions) can be used for manual parsing by importing these modules :from<NQP>, the more friendly approach (eg no need to declare $*LINEPOSCACHE) would be via the corresponding compiler object:
say nqp::getcomp('perl6').eval($source, :target<parse>).dump;
Other targets of interest might be :target<syntaxcheck> as well as the more low-level :target<ast> or for the curious perhaps even :target<mast>.
Working example from #perl6 conversation:
use nqp;
use Perl6::Grammar:from<NQP>;
use Perl6::Actions:from<NQP>;
my $source = q|say "hello world";|;
my $*LINEPOSCACHE;
my $p6c = Perl6::Grammar.parse($source, :actions(Perl6::Actions.new()));
say $p6c.dump

Haskell-src-exts throws TemplateHaskell error

I'm trying to use the haskell-src-exts package to parse Haskell modules. Currently, I'm trying to parse the acme-io package's module, but I keep getting this error no matter what parse mode I try:
*** Exception: fromParseResult: Parse failed at [System/IO/Unsafe/Really/IMeanIt] (1:57): TemplateHaskell is not enabled
The module mentioned makes no references to TemplateHaskell, not in it's LANGUAGE pragma, nor is there a $ anywhere in the source file.
I'm wondering if my parse mode has something to do with it - here it is:
defaultParseMode { parseFilename = toFilePath m
, baseLanguage = Haskell2010
, extensions = []
, ignoreLanguagePragmas = True
, ignoreLinePragmas = True
, fixities = Nothing
}
I've also tried to replace the extensions field with knownExtensions from the parsing suite, without any luck.
This is a duplicate question of this answer - using the parseFile function fixed the issue. However, the reader should note that haskell-src-exts uses different parsing than GHC - I ran into another similar issue right after this, because haskell-src-exts can't handle multi-param contexts without -XMultiParamTypeClasses, yet GHC can, borking the parser if you're scraping Hackage. Hint may be a better option, can't say for sure though.

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.

Resources