antlr4

How can i see the live parse tree using Antlr4 Ide in Eclipse?

。_饼干妹妹 提交于 2019-12-06 19:31:28
问题 I'm new using Antlr4 but I know that exist a plugin for Eclipse. I have a simple question...After I created the g4 file how can I visualize the live parse tree in order to see the tree of an input expression? Thanks 回答1: Currently there is no provision for viewing live parse tree in ANTLR 4 IDE for Eclipse. Meanwhile, you can see the parse tree using -gui switch in the command line. It also provides a feature of saving the parse tree as PNG. 回答2: After installing Antlr4Ide plugin in Eclipse:

How to detect beginning of line, or: “The name 'getCharPositionInLine' does not exist in the current context”

倾然丶 夕夏残阳落幕 提交于 2019-12-06 13:29:29
I'm trying to create a Beginning-Of-Line token: lexer grammar ScriptLexer; BOL : {getCharPositionInLine() == 0;}; // Beginning Of Line token But the above emits the error The name 'getCharPositionInLine' does not exist in the current context As it creates this code: private void BOL_action(RuleContext _localctx, int actionIndex) { switch (actionIndex) { case 0: getCharPositionInLine() == 0; break; } } Where the getCharPositionInLine() method doesn't exist... Simplest approach is to just recognize an EOL as the corresponding BOL token. BC : '/*' .*? '*/' -> channel(HIDDEN) ; LC : '//' ~[\r\n]*

How Lexer lookahead works with greedy and non-greedy matching in ANTLR3 and ANTLR4?

五迷三道 提交于 2019-12-06 12:49:41
问题 If someone would clear my mind from the confusion behind look-ahead relation to tokenizing involving greery/non-greedy matching i'd be more than glad. Be ware this is a slightly long post because it's following my thought process behind. I'm trying to write antlr3 grammar that allows me to match input such as: "identifierkeyword" I came up with a grammar like so in Antlr 3.4: KEYWORD: 'keyword' ; IDENTIFIER : (options {greedy=false;}: (LOWCHAR|HIGHCHAR))+ ; /** lowercase letters */ fragment

Parse and return a list of doubles using ANTLR4

江枫思渺然 提交于 2019-12-06 11:04:38
问题 How can I parse a file containing a decimal numbers into a List<double> in C# using ANTLR4? A complete, working example would illustrate how all the pieces go together. The input file looks like this: 12.34 45.67 89.10 回答1: This is an updated version of an older answer to a different question, showing one way to do this task using C# and ANTLR4. The Grammar grammar Values; parse : (number ( LINEBREAK | EOF ) )* ; number : NUMBER ; NUMBER : DIGIT '.' DIGIT ; DIGIT : [0-9]+ ; WS : [ \t] ->

ANTLR 4 : How to know the existence of subpart in rule

陌路散爱 提交于 2019-12-06 09:35:45
问题 I have this code : varDeclaration : type ID ('=' expression)? ';' ; So, not always ('=' expression) exist. But, sometimes, I want to process this part, but don't know it exist or not in this context. I'm using ANTLR 4 (and often using Listener), how can I know this. Thanks :) 回答1: In your listener ( exitVarDeclaration ) or visitor ( visitVarDeclaration ) check whether ctx.expression() == null . If null, then ('=' expression) didn't exist. If non-null, then it did exist. 来源: https:/

Antlr and PL/I grammar

北城以北 提交于 2019-12-06 09:17:04
Right now we would like to have the grammar of PL/I, COBOL based on Antlr4. Is there anyone provide these grammars If not, can you please share your thought/experience on developing these grammars from scratch Thanks I assume you mean IBM PL/I and COBOL. (Not many other PL/Is around, but I don't think that really changes the answer much). The obvious place to look for mature ANTLR grammars is ANTLR3 grammar library ; no PL/1 or COBOL grammars there. The Antlr V4 (a very new, radical, backwards incompatible reengineering of ANTLR3) main page talks about Java and C#; no hint of PL/1 or COBOL

Python+ANTLR4: No module named antlr4

╄→гoц情女王★ 提交于 2019-12-06 08:53:24
I would like to use ANTLR4 with Python 2.7 and for this I did the following: I installed the package antlr4-4.6-1 on Arch Linux with sudo pacman -S antlr4 . I wrote a MyGrammar.g4 file and successfully generated Lexer and Parser Code with antlr4 -Dlanguage=Python2 MyGrammar.g4 Now executing for example the generated Lexer code with python2 MyGrammarLexer.py results in the error ImportError: No module named antlr4 . What could to be the problem? FYI: I have both Python2 and Python3 installed - I don't know if that might cause any trouble. You need to install antlr4 for python through pip : sudo

ANTLR4: implicit or explicit token definition

倖福魔咒の 提交于 2019-12-06 08:04:07
问题 What are the benefits and drawbacks of using explicit token definitions in ANTLR4? I find the text in single parentheses more descriptive and easier to use than creating a separate token and using that in place of the text. E.g.: grammar SimpleTest; top: library | module ; library: 'library' library_name ';' ; library_name: IDENTIFIER; module: MODULE module_name ';' ; module_name: IDENTIFIER; MODULE: 'module' ; IDENTIFIER: [a-zA-Z0-9]+; The generated tokens are: T__0=1 T__1=2 MODULE=3

ANTLR4 Flattening a ParserRuleContext Tree into an Array

穿精又带淫゛_ 提交于 2019-12-06 07:18:58
How to flatten a ParserRuleContext with subtrees into an array of tokens? The ParserRuleContext.getTokens(int ttype) looks good. but what is ttype ? Is it token type? What value to use if I want to include all token types? Bart Kiers ParserRuleContext.getTokens(int ttype) only retrieves certain child nodes of a parent: it does not recursively go into the parent-tree. However, it is easy enough to write yourself: /** * Retrieves all Tokens from the {@code tree} in an in-order sequence. * * @param tree * the parse tee to get all tokens from. * * @return all Tokens from the {@code tree} in an in

ANTLR4 extraneous input

江枫思渺然 提交于 2019-12-06 06:18:35
I have a problem with my ANTLR4. I'm trying to print AST from python 3 code but there are some errors and I don't know how to fix them. I wrote simple code for test: a=(1,2,3) print(a) I ran the program but this errors appeared: line 1:1 extraneous input '=' expecting {<EOF>, '.', '*', '(', '**', '[', '|', '^', '&', '<<', '>>', '+', '-', '/', '%', '//', '@'} line 2:0 extraneous input '\n' expecting {<EOF>, '.', '*', '(', '**', '[', '|', '^', '&', '<<', '>>', '+', '-', '/', '%', '//', '@'} line 3:0 extraneous input '\n' expecting {<EOF>, '.', '*', '(', '**', '[', '|', '^', '&', '<<', '>>', '+',