antlr

ANTLR4: Whitespace handling

老子叫甜甜 提交于 2019-12-03 09:57:22
I have seen many ANTLR grammars that use whitespace handling like this: WS: [ \n\t\r]+ -> skip; // or WS: [ \n\t\r]+ -> channel(HIDDEN); So the whitespaces are thrown away respectively send to the hidden channel. With a grammar like this: grammar Not; start: expression; expression: NOT expression | (TRUE | FALSE); NOT: 'not'; TRUE: 'true'; FALSE: 'false'; WS: [ \n\t\r]+ -> skip; valid inputs are ' not true ' or ' not false ' but also ' nottrue ' which is not a desired result. Changing the grammar to: grammar Not; start: expression; expression: NOT WS+ expression | (TRUE | FALSE); NOT: 'not';

ANTLR java test file can't create object of tree grammar

匿名 (未验证) 提交于 2019-12-03 09:19:38
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am creating a parser using ANTLR 3.x that targets java. I have written both parser grammar (for creating Abstract Syntax Tree, AST) and Tree Grammar (for performing operations on AST). Finally, to test both grammar files, I have written a test file in Java. Have a look at the below code, protocol grammar grammar protocol; options { language = Java; output = AST; } tokens{ //imaginary tokens PROT; INITIALP; PROC; TRANSITIONS; } @header { import twoprocess.Configuration; package com.javadude.antlr3.x.tutorial; } @lexer::header { package com

How do I install ANTLR IDE with Eclipse Juno and PDT (PHP)

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I develop in both PHP and Java. Eclipse PDT appears to require DLTK 4.0, which it has no problem getting. ANTLR IDE appears to require DLTK3. I've tried copying the plugins 3.0 into my Eclipse plugins / features directory: http://download.eclipse.org/technology/dltk/downloads/drops/R3.0/S-3.0.1-201108261011/ This worked on a machine without PDT, but I can't get it to work when I have PDT. I have also tried using the marketplace, but I get the same dependency errors. Note I'm on 64bit Linux. 回答1: Try to add the DLTK 3.0 repository and then

ANTLR JavaScript Target

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have been using ANTLR to generate a parser + tree grammar for a mark up language with Java target which works fine. Now I am trying to get the target in JavaScript to use it in my web browser. However, I have not been able to locate any good documentation on how to go about doing this. I am using eclipse with ANTLR IDE, and when i specify the language as JavaScript, I get the following errors. Multiple markers at this line (10): internal error: group JavaScript does not satisfy interface ANTLRCore: mismatched arguments on these templates

Generating an Abstract Syntax Tree for java source code using ANTLR

喜夏-厌秋 提交于 2019-12-03 08:40:05
问题 How Can I Generate an AST from java src code Using ANTLR? any help? 回答1: The setps to generate java src AST using antlr4 are: Install antlr4 you can use this link to do that. After installation download the JAVA grammar from here. Now generate Java8Lexer and Java8Parser using the command: antlr4 -visitor Java8.g4 This will generate several files such as Java8BaseListener.java Java8BaseVisitor.java Java8Lexer.java Java8Lexer.tokens Java8Listener.java Java8Parser.java Java8.tokens Java8Visitor

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

匿名 (未验证) 提交于 2019-12-03 08:28:06
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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. 文章来源: ANTLR 4 : How to know the existence of subpart in rule

How can I modify the text of tokens in a CommonTokenStream with ANTLR?

喜你入骨 提交于 2019-12-03 08:08:19
I'm trying to learn ANTLR and at the same time use it for a current project. I've gotten to the point where I can run the lexer on a chunk of code and output it to a CommonTokenStream. This is working fine, and I've verified that the source text is being broken up into the appropriate tokens. Now, I would like to be able to modify the text of certain tokens in this stream, and display the now modified source code. For example I've tried: import org.antlr.runtime.*; import java.util.*; public class LexerTest { public static final int IDENTIFIER_TYPE = 4; public static void main(String[] args) {

Systematic way to generate ANTLR tree grammar?

折月煮酒 提交于 2019-12-03 07:38:13
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 information? If so, would it be better for me to make a manual tree walker than writing an ANTLR tree

Antlr Extraneous Input

匿名 (未验证) 提交于 2019-12-03 07:36:14
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a grammar file BoardFile.g4 that has (relevant parts only): grammar Board; //Tokens GADGET : 'squareBumper' | 'circleBumper' | 'triangleBumper' | 'leftFlipper' | 'rightFlipper' | 'absorber' | 'portal' ; NAME : [A-Za-z_][A-Za-z_0-9]* ; INT : [0-9]+ ; FLOAT : '-'?[0-9]+('.'[0-9]+)? ; COMMENT : '#' ~( '\r' | '\n' )*; WHITESPACE : [ \t\r\n]+ -> skip ; KEY : [a-z] | [0-9] | 'shift' | 'ctrl' | 'alt' | 'meta' | 'space' | 'left' | 'right' | 'up' | 'down' | 'minus' | 'equals' | 'backspace' | 'openbracket' | 'closebracket' | 'backslash' |

Getting started with ANTLR and avoiding common mistakes

微笑、不失礼 提交于 2019-12-03 06:41:38
I have started to learn ANTLR and have both the 2007 book "The Definitive ANTLR Reference" and ANTLRWorks (an interactive tool for creating grammars). And, being that sort of person, I started at Chapter 3. ("A quick tour for the impatient"). It's a fairly painful process especially as some errors are rather impenetrable (e.g. ANTLR: "missing attribute access on rule scope" problem which just means to me "you got something wrong"). Also I have some very simple grammars (3-4 productions only) and simple input (2 lines) which when run give "OutOfMemory" error. The ANTLR site is useful but