antlr3

Replace token in ANTLR

偶尔善良 提交于 2019-12-04 17:27:30
I want to replace a token using ANTLR. I tried with TokenRewriteStream and replace, but it didn't work. Any suggestions? ANTLRStringStream in = new ANTLRStringStream(source); MyLexer lexer = new MyLexer(in); TokenRewriteStream tokens = new TokenRewriteStream(lexer); for(Object obj : tokens.getTokens()) { CommonToken token = (CommonToken)obj; tokens.replace(token, "replacement"); } The lexer finds all occurences of single-line comments, and i want to replace them in the original source too. EDIT: This is the grammar: grammar ANTLRTest; options { language = Java; } @header { package main; }

Ignore some part of input when parsing with ANTLR

☆樱花仙子☆ 提交于 2019-12-04 15:58:55
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 /include XCP_common_v1_0.aml "XCP" struct { taggedstruct Common_Parameters ; }; /end A2ML /end MODULE

Different lexer rules in different state

假如想象 提交于 2019-12-04 08:42:32
问题 I've been working on a parser for some template language embeded in HTML (FreeMarker), piece of example here: ${abc} <html> <head> <title>Welcome!</title> </head> <body> <h1> Welcome ${user}<#if user == "Big Joe">, our beloved leader</#if>! </h1> <p>Our latest product: <a href="${latestProduct}">${latestProduct}</a>! </body> </html> The template language is between some specific tags, e.g. '${' '}', '<#' '>'. Other raw texts in between can be treated like as the same tokens (RAW). The key

antlr global rule scope declaration vs @members declaration

天涯浪子 提交于 2019-12-04 04:28:04
Which one would you prefer to declare a variable in which case, global scope or @members declaration? It seems to me that they can serve for same purpose? UPDATE here is a grammar to explain what i mean. grammar GlobalVsScope; scope global{ int i; } @lexer::header{package org.inanme.antlr;} @parser::header{package org.inanme.antlr;} @parser::members { int j; } start scope global; @init{ System.out.println($global::i); System.out.println(j); }:R EOF; R:'which one'; Note that besides global (ANTLR) scopes, you can also have local rule-scopes, like this: grammar T; options { backtrack=true; }

How to resolve Antlr3 dependency hell

橙三吉。 提交于 2019-12-04 00:33:51
I have a asp.net MVC 4 project with MEF and RavenBD. When the project loads it throws this exception : Could not load file or assembly Antlr3.Runtime.dll I have found that both RavenDB and WebGrease (installed with MVC 4) use Antlr3. But WebGrease comes with its own Antlr3 dll, signed by Microsoft - PublicKeyToken 31bf3856ad364e35 Antlr3 default PublicKeyToken is eb42632606e9261f. RavenDB and WebGrease use the same version of Antlr3 3.3.1.7705 How can I resolve this problem? Unfortunately I did not found a solution to conflicting dependencies of same version with different signatures. But the

Are there any LL Parser Generators for Functional Languages such as Haskell or Scala?

强颜欢笑 提交于 2019-12-03 11:17:35
问题 I've noticed a distinct lack of LL parsers that create parsers in functional languages. The ideal find for what I've been looking for without success is something to generate a Haskell parser for an ANTLR-style LL(*) grammar (modulo minor reformatting of the grammar), and was surprised that every last parser generator with a functional language target I found was some kind of LR parser. I want to transition the parser of this language I'm working on which has functional features from ANTLR to

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) {

Building a library using autotools from cmake

风格不统一 提交于 2019-12-03 02:18:00
问题 This is my first try with cmake and I would like to have, if possible, some feedbacks about what I did since some problems remain. In the CMakeLists.txt of the library folder, I created two makefile targets: configure-antlr3c and antlr3c . The first target runs the autotools configuration shell script, the second one runs the make executable to build the library: # CMakeLists.txt in libantlr3c-3.1.3 add_custom_target( configure-antlr3c ${SHELL_EXECUTABLE} configure WORKING_DIRECTORY ${CMAKE

Different lexer rules in different state

不羁的心 提交于 2019-12-03 00:40:37
I've been working on a parser for some template language embeded in HTML (FreeMarker), piece of example here: ${abc} <html> <head> <title>Welcome!</title> </head> <body> <h1> Welcome ${user}<#if user == "Big Joe">, our beloved leader</#if>! </h1> <p>Our latest product: <a href="${latestProduct}">${latestProduct}</a>! </body> </html> The template language is between some specific tags, e.g. '${' '}', '<#' '>'. Other raw texts in between can be treated like as the same tokens (RAW). The key point here is that the same text, e.g. an integer, will mean differently thing for the parser depends on

Building a library using autotools from cmake

烈酒焚心 提交于 2019-12-02 15:48:40
This is my first try with cmake and I would like to have, if possible, some feedbacks about what I did since some problems remain. In the CMakeLists.txt of the library folder, I created two makefile targets: configure-antlr3c and antlr3c . The first target runs the autotools configuration shell script, the second one runs the make executable to build the library: # CMakeLists.txt in libantlr3c-3.1.3 add_custom_target( configure-antlr3c ${SHELL_EXECUTABLE} configure WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) add_custom_target( antlr3c ${MAKE} DEPENDS configure-antlr3c WORKING_DIRECTORY $