antlr4

How to profile an Antlr grammar

China☆狼群 提交于 2020-01-03 08:29:13
问题 I have an Antlr grammar that is currently about 1200 lines. It parses the language that I want, but for at least one construct it is prohibitively slow even for smaller input files. The execution time seems to be growing exponentially for each added element of the construct. I want to know if there are any good guidelines for debugging/profiling such performance problems. I have already tried with VisualVM and that gave be the name of the two methods closureCheckingStopState and closure_, but

How to implement error handling in ANTLR4

痞子三分冷 提交于 2020-01-01 09:24:11
问题 I have the following grammar for parsing first-order logic formulas applied over graphs: grammar Graph; /*------------------------------------------------------------------ * PARSER RULES *------------------------------------------------------------------*/ input : formula EOF ; formula : TRUE | FALSE | formula AND formula | formula OR formula | quantifier formula | ST condition ; condition : atom EQUALS QUOTE? (assignment | atom) QUOTE? ; quantifier : (FOREACH | EXISTS) variable IN domain ;

Is it possible to parse big file with ANTLR?

自闭症网瘾萝莉.ら 提交于 2020-01-01 09:19:17
问题 Is it possible to instruct ANTLR not to load entire file into memory? Can it apply rules one by one and generate topmost list of nodes sequentially, along with reading file? Also may be it is possible to drop analyzed nodes somehow? 回答1: Yes, you can use: UnbufferedCharStream for your character stream (passed to lexer) UnbufferedTokenStream for your token stream (passed to parser) This token stream implementation doesn't differentiate on token channels, so make sure to use ->skip instead of -

ANTLR and Eclipse (or any decent IDE)

故事扮演 提交于 2020-01-01 04:51:04
问题 I have been using ANTLR with Eclipse for some time using the ANTLRv3IDE plugin. While it is not perfect, and a bit outdated, it does its job reasonably well. Now I am looking to switch to ANTLRv4 for another DSL that I am creating. However, Eclipse support seems to be extremely thin. I decided to try out ANTLRWorks, which is a NetBeans plugin, but I could not get it to install (it seems to be locked to specific dated versions (201302132200 while I have something newer, still 7.3 as docs say)

ANTLRv4: non-greedy rules

旧时模样 提交于 2019-12-30 07:12:17
问题 I'm reading the definite ANTLR4 reference and have a question regarding one of the examples (p. 76): STRING: '"' (ESC|.)*? '"'; fragment ESC: '\\"' | '\\\\' ; The rule matches a typical C++ string - a char sequence included in "" , which can contain \" too. In my expectation, the rule STRING should match the smallest string possible because of the non-greedy construct. So if it sees a \" it would map \ to . and " to " at the end of the rule, since this would result in the smallest string

Syntax of semantic predicates in Antlr4

放肆的年华 提交于 2019-12-30 06:06:46
问题 In What is a 'semantic predicate' in ANTLR3? Bart Kiers gives a very well overview about the different semantic predicates in Antlr3. Too bad the syntax/semantics were seemingly changed in Antlr4, so this does not compile: end_of_statement : ';' | EOF | {input.LT(1).getType() == RBRACE}? => ; RBRACE : '}' ; Could someone please tell me how to do the third case of end_of_statement : Accept if the next token is a '}' but do not consume it. 回答1: There is now just a single type of semantic

Syntax of semantic predicates in Antlr4

放肆的年华 提交于 2019-12-30 06:06:10
问题 In What is a 'semantic predicate' in ANTLR3? Bart Kiers gives a very well overview about the different semantic predicates in Antlr3. Too bad the syntax/semantics were seemingly changed in Antlr4, so this does not compile: end_of_statement : ';' | EOF | {input.LT(1).getType() == RBRACE}? => ; RBRACE : '}' ; Could someone please tell me how to do the third case of end_of_statement : Accept if the next token is a '}' but do not consume it. 回答1: There is now just a single type of semantic

How to automatically generate lexer+parser with ANTLR4 and Maven?

╄→尐↘猪︶ㄣ 提交于 2019-12-30 02:08:08
问题 I'am new to ANTLR4, and it seems that there is no Eclipse-Plug-In for v4. So it would nice to build automatically the Java sources from the .g4 grammars. I have a simple, empty Maven-project with src/main/java, src/test/java. Where to place the .g4 files? How can I automatically build the grammars with Maven? My own POM-test failed: <repository> <id>mvn-public</id> <name>MVNRepository</name> <url>http://mvnrepository.com</url> </repository> ... <build> <plugins> <plugin> <groupId>org.antlr<

Is there a way to generate unit test to test my grammar

假如想象 提交于 2019-12-29 09:11:15
问题 I created my grammar using antlr4 but I want to test robustess is there an automatic tool or a good way to do that fast Thanks :) 回答1: The only way I found to create unit tests for a grammar is to create a number of examples from a written spec of the given language. This is neither fast, nor complete, but I see no other way. You could be tempted to create test cases directly from the grammar (writing a tool for that isn't that hard). But think a moment about this. What would you test then?

ANTLR4 lexer rules don't work as expected

元气小坏坏 提交于 2019-12-29 08:19:14
问题 I want to write a lexer rule about the month and the year, the rule is(with regular expression): "hello"[0-9]{1,2}"ever"([0-9]{2}([0-9]{2})?)? the "hello" and "ever" literals are just for debuging. that's say, one or two digits for month, and two or four digits for year. And what's more, the year part could be bypass. such as: Aug 2015 ->hello08ever2015 or hello8ever2015 or hello8ever15 or hello8ever or hello08ever; Oct 2015 -> hello10ever2015 or hello10ever15 or hello10ever; and my lexer