antlr

How to specify a target package for ANTLR?

别等时光非礼了梦想. 提交于 2019-11-30 10:43:28
If I call: java org.antlr.Tool -o outdir sources/com/example/Java5.g ...with antlr-3.1.3 the parser and lexer code will be generated in the directory outdir/sources/com/example . But the generated classes don't have any package statement. I need them to life in the package com.example . Is there a way to specify the target package? peter.murray.rust ANTLR provides a header tool which allows you to include package and imports. You include this in your *.g grammar file: @header { package org.xmlcml.cml.converters.antlr; import java.util.HashMap; } And you may need it in the Lexer as well: @lexer

Using ANTLR to parse a log file

早过忘川 提交于 2019-11-30 10:17:12
I'm just about starting with ANTLR and trying to parse some pattern out of a log file for example: log file: 7114422 2009-07-16 15:43:07,078 [LOGTHREAD] INFO StatusLog - Task 0 input : uk.project.Evaluation.Input.Function1(selected=["red","yellow"]){} 7114437 2009-07-16 15:43:07,093 [LOGTHREAD] INFO StatusLog - Task 0 output : uk.org.project.Evaluation.Output.Function2(selected=["Rocket"]){} 7114422 2009-07-16 15:43:07,078 [LOGTHREAD] INFO StatusLog - Task 0 input : uk.project.Evaluation.Input.Function3(selected=["blue","yellow"]){} 7114437 2009-07-16 15:43:07,093 [LOGTHREAD] INFO StatusLog -

ANTLR Parse tree modification

允我心安 提交于 2019-11-30 09:17:11
I'm using ANTLR4 to create a parse tree for my grammar, what I want to do is modify certain nodes in the tree. This will include removing certain nodes and inserting new ones. The purpose behind this is optimization for the language I am writing. I have yet to find a solution to this problem. What would be the best way to go about this? While there is currently no real support or tools for tree rewriting, it is very possible to do. It's not even that painful. The ParseTreeListener or your MyBaseListener can be used with a ParseTreeWalker to walk your parse tree. From here, you can remove nodes

解决Weblogic与Hibernate的jar冲突

余生长醉 提交于 2019-11-30 07:21:18
项目运行的时候,提示找不到org.hibernate.hql.ast.HqlToken这个类,可我jar包明明有啊,上网一搜,原来是Weblogic11已经带了antlr,所以没有用到了hibernate3相关的antlr-2.7.5H3.jar包,所以只要把antlr-2.7.5H3.jar的classpath提到weblogic.jar的前面就OK了 Linux中: 拷贝antlr-2.7.5H3.jar 到 ${WL_HOME}/server/lib,然后打开你domain的startWeblogic.sh文件 将 CLASSPATH=${CLASSPATH}${CLASSPATHSEP}${MEDREC_WEBLOGIC_CLASSPATH} 修改为 export HIBERNATE_CLASSPATH="${WL_HOME}/server/lib/antlr-2.7.5H3.jar" CLASSPATH=${HIBERNATE_CLASSPATH}${CLASSPATH}${CLASSPATHSEP}${MEDREC_WEBLOGIC_CLASSPATH} 就ok了 Windows中的写法有点不一样,大同小异,写法如下 set HIBERNATE_CLASSPATH=%WL_HOME%\server\lib\antlr-2.7.5H3.jar; set CLASSPATH

Parsing string interpolation in ANTLR

痴心易碎 提交于 2019-11-30 05:26:57
I'm working on a simple string manipulation DSL for internal purposes, and I would like the language to support string interpolation as it is used in Ruby. For example: name = "Bob" msg = "Hello ${name}!" print(msg) # prints "Hello Bob!" I'm attempting to implement my parser in ANTLRv3, but I'm pretty inexperienced with using ANTLR so I'm unsure how to implement this feature. So far, I've specified my string literals in the lexer, but in this case I'll obviously need to handle the interpolation content in the parser. My current string literal grammar looks like this: STRINGLITERAL : '"' (

ANTLR Parser with manual lexer

别等时光非礼了梦想. 提交于 2019-11-30 04:13:07
I'm migrating a C#-based programming language compiler from a manual lexer/parser to Antlr. Antlr has been giving me severe headaches because it usually mostly works, but then there are the small parts that do not and are incredibly painful to solve. I discovered that most of my headaches are caused by the lexer parts of Antlr, rather than the parser. Then I noticed parser grammar X; and realized that perhaps I could have my manually written lexer and then an Antlr generated parser. So I'm looking for more documentation on this topic. I guess a custom ITokenStream could work, but there appears

Nested Boolean Expression Parser using ANTLR

主宰稳场 提交于 2019-11-30 03:42:02
I'm trying to parse a Nested Boolean Expression and get the individual conditions within the expression separately. For e.g., if the input string is: (A = a OR B = b OR C = c AND ((D = d AND E = e) OR (F = f AND G = g))) I would like to get the conditions with the correct order. i.e., D =d AND E = e OR F = f AND G = g AND A = a OR B = b OR C = c I'm using ANTLR 4 to parse the input text and here's my grammar: grammar SimpleBoolean; rule_set : nestedCondition* EOF; AND : 'AND' ; OR : 'OR' ; NOT : 'NOT'; TRUE : 'TRUE' ; FALSE : 'FALSE' ; GT : '>' ; GE : '>=' ; LT : '<' ; LE : '<=' ; EQ : '=' ;

ANTLR 4 $channel = HIDDEN and options

此生再无相见时 提交于 2019-11-30 02:49:22
I need help with my ANTLR 4 grammar after deciding to switch to v4 from v3. I am not very experienced with ANTLR so I am really sorry if my question is dumb ;) In v3 I used the following code to detect Java-style comments: COMMENT : '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;} | '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;} ; In v4 there are no rule-specific options. The actions (move to hidden channel) are also invalid. Could somebody please give me a hint how to do it in ANTLR v4? The v4 equivalent would look like: COMMENT : ( '//' ~[\r\n]* '\r'? '\n' | '/*' .*? '*/' ) ->

Parsing Context Sensitive Language

五迷三道 提交于 2019-11-30 02:37:43
问题 i am reading the Definitive ANTLR reference by Terence Parr, where he says: Semantic predicates are a powerful means of recognizing context-sensitive language structures by allowing runtime information to drive recognition But the examples in the book are very simple. What i need to know is: can ANTLR parse context-sensitive rules like: xAy --> xBy If ANTLR can't parse these rules, is there is another tool that deals with context-sensitive grammars? 回答1: ANTLR parses only grammars which are

Mismatched input error in simple antlr4 grammar

不羁岁月 提交于 2019-11-29 22:58:24
问题 I'm trying to parse a simple subset of SQL using antlr4. My grammar looks like this: grammar Query; query : select; select : 'select' colname (',' colname)* 'from' tablename; colname : COLNAME; tablename : TABLENAME; COLNAME: [a-z]+ ; TABLENAME : [a-z]+; WS : [ \t\n\r]+ -> skip ; // skip spaces, tabs, newlines I am testing this with a simple java application as follows: import java.io.ByteArrayInputStream; import java.io.InputStream; import org.antlr.v4.runtime.*; import org.antlr.v4.runtime