antlr

Examples / tutorials for usage of javax.lang.model or ANTLR JavaParser to get information on Java Source Code

与世无争的帅哥 提交于 2019-12-03 16:32:32
I would like to create an automatic Flowchart-like visualization to simple Java Logic, for this I need to parse Java Source code, I have 2 candidates, ANTLR and javax.lang.model of Java 6. Neither are easy. I have yet to find a single working example that will be even remotely close to what I want to achieve. I want to find simple variable declarations, assignments, and flows (if, for, switch, boolean conditions etc) Is there a simple example or tutorial for either of these? I found very few ANTLR examples (non of them are working out of the box without significant "homework") and absolutely

Parsing SQL like syntax, design pattern

痞子三分冷 提交于 2019-12-03 16:13:10
问题 I am trying mock sql syntax to build a simple sql like interface to a key-value storage. The values are essentially POJOs An example would be select A.B.C from OBJ_POOL where A.B.X = 45 AND A.B.Y > '88' AND A.B.Z != 'abc'; OBJ_POOL is just a list of POJOs of the same class. In this example A would be the base class. Class A Class B String C Integer X String Y String Z Now A.B.C is equivalent A.getB().getC() I am using Antlr to parse the above statement to get an AST, and then hoping to use

ANTLR vs. Happy vs. other parser generators

和自甴很熟 提交于 2019-12-03 14:18:49
I want to write a translator between two languages, and after some reading on the Internet I've decided to go with ANTLR. I had to learn it from scratch, but besides some trouble with eliminating left recursion everything went fine until now. However, today some guy told me to check out Happy, a Haskell based parser generator. I have no Haskell knowledge, so I could use some advice, if Happy is indeed better than ANTLR and if it's worth learning it. Specifically what concerns me is that my translator needs to support macro substitution, which I have no idea yet how to do in ANTLR. Maybe in

In ANTLR 3, how do I generate a lexer (and parser) at runtime instead of ahead of time?

吃可爱长大的小学妹 提交于 2019-12-03 13:46:51
问题 I want to generate an antlr lexer at runtime -- that is, generate the grammar and from the grammar generate the lexer class, and its supporting bits at runtime. I am happy to feed it into the the java compiler, which is accessible at runtime. 回答1: Here's a quick and dirty way to: generate a combined (!) ANTLR grammar .g file given a String as grammar-source, and create a Parser & Lexer from this .g file, compile the these Parser & Lexer .java files, create instances of the Parser & Lexer

ANTLR and Eclipse (or any decent IDE)

筅森魡賤 提交于 2019-12-03 13:10:30
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) of dependencies). So, the question: Has anyone set up any Java IDE (preferably Eclipse, but I could be

ANTLR: call a rule from a different grammar

安稳与你 提交于 2019-12-03 13:04:05
问题 is it possible to invoke a rule from a different grammar? the purpose is to have two languages in the same file, the second language starting by an (begin ...) where ... is in the second language. the grammar should invoke another grammar to parse that second language. for example: grammar A; start_rule : '(' 'begin' B.program ')' //or something like that ; grammar B; program : something* EOF ; something : ... ; 回答1: Your question could be interpreted in (at least) two ways: separate rules

Removing Left Recursion in ANTLR

◇◆丶佛笑我妖孽 提交于 2019-12-03 12:51:06
问题 As is explained in Removing left recursion , there are two ways to remove the left recursion. Modify the original grammar to remove the left recursion using some procedure Write the grammar originally not to have the left recursion What people normally use for removing (not having) the left recursion with ANTLR? I've used flex/bison for parser, but I need to use ANTLR. The only thing I'm concerned about using ANTLR (or LL parser in genearal) is left recursion removal. In practical sense, how

Building own C# compiler using ANTLR: Compilation Unit

China☆狼群 提交于 2019-12-03 12:40:52
问题 // Create a scanner that reads from the input stream passed to us CSLexer lexer = new CSLexer(new ANTLRFileStream(f)); tokens.TokenSource = lexer; // Create a parser that reads from the scanner CSParser parser = new CSParser(tokens); // start parsing at the compilationUnit rule CSParser.compilation_unit_return x = parser.compilation_unit(); object ast = x.Tree; What can I do with the x which is of compilation_unit_return type, to extract its root, its classes, its methods etc? Do I have to

Is “Implicit token definition in parser rule” something to worry about?

微笑、不失礼 提交于 2019-12-03 11:39:29
问题 I'm creating my first grammar with ANTLR and ANTLRWorks 2. I have mostly finished the grammar itself (it recognizes the code written in the described language and builds correct parse trees), but I haven't started anything beyond that. What worries me is that every first occurrence of a token in a parser rule is underlined with a yellow squiggle saying "Implicit token definition in parser rule". For example, in this rule, the 'var' has that squiggle: variableDeclaration: 'var' IDENTIFIER ('='

Does anyone know of a way to debug tree grammars in ANTLRWorks

巧了我就是萌 提交于 2019-12-03 10:03:35
问题 The recommended pattern for ANTLR usage is to have the Parser construct an Abstract Syntax Tree, and then build Tree walkers (AKA tree grammars) to process them. I'm trying to get to the bottom of why my tree grammar isn't working and would love to use ANTLRWorks' debugger the same way I used it for the parser itself. The input to the parser is the "source code", but the input to a tree parser is the AST result of the parser. I don't see how to make that available as input to test the tree