antlr

Generate BNF diagrams from an antlr grammar?

家住魔仙堡 提交于 2019-12-10 10:41:34
问题 I may well be asking something not achievable here.. Maybe someone can point out either (a) What would be some steps (/tools?) to at least partially achieve creation of bnf diagrams from a (rather complex) antlr grammar (b) why (if it were the case) this simply can not be achieved. E.g. maybe since antlr is extended BNF and its recursive structure differs from bnf requirements.. Along those lines. 回答1: ANTLRWorks 1 works for generating diagrams, one at a time, for rule. for v4, ANTLRWorks 2

Slow ANTLR4 generated Parser in Python, but fast in Java

让人想犯罪 __ 提交于 2019-12-10 02:29:07
问题 I am trying to convert ant ANTLR3 grammar to an ANTLR4 grammar, in order to use it with the antlr4-python2-runtime. This grammar is a C/C++ fuzzy parser. After converting it (basically removing tree operators and semantic/syntactic predicates), I generated the Python2 files using: java -jar antlr4.5-complete.jar -Dlanguage=Python2 CPPGrammar.g4 And the code is generated without any error, so I import it in my python project (I'm using PyCharm) to make some tests: import sys, time from antlr4

What is minimal sample Gradle project for ANTLR4 (with antlr plugin)?

只愿长相守 提交于 2019-12-10 02:22:43
问题 I have created new Gradle project, added apply plugin: 'antlr' and dependencies { antlr "org.antlr:antlr4:4.5.3" to build.gradle . Created src/main/antlr/test.g4 file with the following content grammar test; r : 'hello' ID; ID : [a-z]+ ; WS : [ \t\r\n]+ -> skip ; But it doesn't work. No java source files generated (and no error occurred). What I missed? Project is here: https://github.com/dims12/AntlrGradlePluginTest2 UPDATE I found my sample is actually works, but it put code into \build

Parse a formula using ANTLR4

醉酒当歌 提交于 2019-12-10 00:10:30
问题 I am trying to parse a mathematical formula to a subset of LaTeX using ANTLR4. For example it should parse (a+4)/(b*10) to \frac{a+4}{b\cdot 10} . My simple grammar creates a tree like this: Now I am trying to implement parse tree listeners to somehow construct the LaTeX String while the tree is traversed. Here, I am failing because to construct a String like \frac{}{} it has to be built recursively. The parse tree walker, however, visits one tree node after the other (in a breadth-first way

Ignore some part of input when parsing with ANTLR

别来无恙 提交于 2019-12-09 20:34:48
问题 I'm trying to parse a language by ANTLR (ANTLRWorks-3.5.2). The goal is to enter complete input but Antlr gives a parse tree of defined parts in grammar and ignore the rest of inputs, for example this is my grammar : grammar asap; project : '/begin PROJECT' name module+ '/end PROJECT'; module : '/begin MODULE'name '/end MODULE'; name : IDENT ; IDENT : ('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'.'|':'|'-')*; Given input: /begin PROJECT HybridSailboat_2 /begin MODULE engine /begin A2ML

How to write grammer in Antlr4 for function with zero argument

十年热恋 提交于 2019-12-09 19:44:53
问题 I'm having function with arguments grammer like below lexer and parser: MyFunctionsLexer.g4 lexer grammar MyFunctionsLexer; FUNCTION: 'FUNCTION'; NAME: [A-Za-z0-9]+; DOT: '.'; COMMA: ','; L_BRACKET: '('; R_BRACKET: ')'; WS : [ \t\r\n]+ -> skip; MyFunctionsParser.g4 parser grammar MyFunctionsParser; options { tokenVocab=MyFunctionsLexer; } functions : function* EOF; function : FUNCTION '.' NAME '(' (function | argument (',' argument)*) ')'; argument: (NAME | function); But in parser is

Systematic way to generate ANTLR tree grammar?

我是研究僧i 提交于 2019-12-09 06:39:57
问题 I have a little bit large ANTLR parser grammar file and want to make a tree grammar for it. But, as far as I know this work of tree grammar generation can't be done automatically, i.e., I should generate it manually by copying parser grammar, removing some unnecessary code, etc. I want to know if there is a systematic way to generate a tree grammar file from a parser grammar file. P.S. I read an article that insists that 'Manual Tree Walking Is Better Than Tree Grammars'. Is this reliable

ANTLR @header, @parser, superClass option and basic file io (Java)

喜你入骨 提交于 2019-12-08 19:46:26
问题 I want to use parser actions with basic file io (Java), e. g. PrintWriter in an ANTLR grammar. Must I use the superClass option or can I use @header? In both cases how can I declare the PrintWriter-object and how must I handle the exceptions? 回答1: The option superClass=... is used to let your Parser extend a custom class. So, I don't think that is what you're after. Everything inside the @header section will be placed at the start of your Parser class. This is used to import classes: @header

antlr4: ATN version 2 expected 3

主宰稳场 提交于 2019-12-08 17:31:28
问题 When trying to use a generated grammar and lexer I get: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 2 (expected 3). What's wrong? 回答1: Your parser was generated with ANTLR 4.0, but you are trying to execute it with ANTLR 4.1. The most likely cause of this is using ANTLRWorks 2.0 to generate the parser, which internally uses ANTLR 4.0. I'm in the process of releasing ANTLRWorks 2.1 which will correct this mismatch. 来源: https://stackoverflow.com/questions/18180103

ANTLR: “missing attribute access on rule scope” problem

£可爱£侵袭症+ 提交于 2019-12-08 17:07:33
问题 I am trying to build an ANTLR grammar that parses tagged sentences such as: DT The NP cat VB ate DT a NP rat and have the grammar: fragment TOKEN : (('A'..'Z') | ('a'..'z'))+; fragment WS : (' ' | '\t')+; WSX : WS; DTTOK : ('DT' WS TOKEN); NPTOK : ('NP' WS TOKEN); nounPhrase: (DTTOK WSX NPTOK); chunker : nounPhrase {System.out.println("chunk found "+"("+$nounPhrase+")");}; The grammar generator generates the " missing attribute access on rule scope: nounPhrase " in the last line. [I am still