antlr

antlr2 return multiple values

落爺英雄遲暮 提交于 2020-01-06 14:16:35
问题 How to make a rule return multiple values in antlr2.For example: declSpecifiers returns [int mods] : ( storageClassSpecifier | typeQualifier | typeSpecifier)+ ; I have some other information besides 'mods' to return.What should I do? 回答1: In ANTLR v3.x, you can include multiple return values by listing them in the brackets. declSpecifiers returns [int mods, Object otherInfo] : ( storageClassSpecifier | typeQualifier | typeSpecifier)+ ; The generated code will return a generated class

Combining Antlr 3.5.2 with StringTemplate 4 for code generation

怎甘沉沦 提交于 2020-01-05 13:09:37
问题 Current project I'm working on is limited to using antlr 3.5.2, but I would like to use the featureset of StringTemplate 4 for our code generation. Can antlr 3.5.2 generate a java treewalker that uses StringTemplate 4? (e.g. a tree grammer with output=template that results in a java file with ST* references instead of StringTemplate*) 回答1: The output=template option only supports StringTemplate 3. You can still support StringTemplate 4, but it would require using embedded actions or a hand

antlr4 multiline string parsing

大兔子大兔子 提交于 2020-01-05 09:02:38
问题 If I have a ONELINE_STRING fragment rule in an antlr4 lexer that identifies a simple quoted string on one line, how can I create a more general STRING rule in the lexer that will concatenate adjacent ONELINE_STRING's (ie, separated only by whitespace and/or comments) as long as they each start on a different line? ie, "foo" "bar" would be parsed as two STRING tokens, "foo" followed by "bar" while: "foo" "bar" would be seen as one STRING token: "foobar" For clarification: The idea is that

AntlrWorks & language grammar errors

放肆的年华 提交于 2020-01-05 07:50:12
问题 Working on a game project that involves a scripting language that I want to interpret into a virtual machine code that can be executed directly. I've included the grammar below. All the lexer rules are displaying properly in the syntax diagram, but when I click on the bodies of any of the parser rules, I get "Cannot display rule "X" because start state is not found" for a given parser rule X. I'm not really sure why ANTLR is complaining about not having a start state. The grammar should

What is the ANTLR4 equivalent of a ! in a lexer rule?

荒凉一梦 提交于 2020-01-05 02:51:13
问题 I'm working on converting an old ANTLR 2 grammar to ANTLR 4, and I'm having trouble with the string rule. STRING : '\''! ( ~('\'' | '\\' | '\r' | '\n') )* '\''! ; This creates a STRING token whose text contains the contents of the string, but does not contain the starting and ending quotes, because of the ! symbol after the quote literals. ANTLR 4 chokes on the ! symbol, ( '!' came as a complete surprise to me (AC0050) ) but if I leave it off, I end up with tokens that contain the quotes,

ANTLR4 does not find grammar on import

柔情痞子 提交于 2020-01-05 01:58:06
问题 I am trying to split my ANTLR4 grammar in multiple files so i can test them more easily, i am using gradle as a build tool in a java project. Both grammar compile correctly by separate but when i add the import to my main grammar i get the next compilation error error(110): kanekotic/specflow/rider/SpecflowFeature.g4:3:7: can't find or load grammar SpecflowScenario the inherited grammar looks like: grammar SpecflowScenario; @header { package kanekotic.specflow.rider; } scenario : 'Scenario: '

Handling errors in ANTLR 4

房东的猫 提交于 2020-01-04 14:11:38
问题 After following the accepted answer's instructions of Handling errors in ANTLR4 question I stuck up with the following error. CustomErrorListener.java:11: cannot find symbol symbol : variable REPORT_SYNTAX_ERRORS location: class CustomErrorListener I understood that ways to handle errors in ANTLR4 were different from ANTLR3, and based on the aforementioned question and its answers I ended up implementing the following error listener. public class DescriptiveErrorListener extends

General stategy for designing Flexible Language application using ANTLR4

非 Y 不嫁゛ 提交于 2020-01-04 09:04:01
问题 Requirement: I am trying to develop a language application using antlr4. The language in question is not important. The important thing is that the grammar is very vast ( easily >2000 rules!!! ). I want to do a number of operations Extract bunch of informations. These can be call graphs, variable names. constant expressions etc. Any number of transformations: if a loop can be expanded, we go ahead and expand it If we can eliminate dead code we might choose to do that we might choose to rename

How can I get information out of a tree parser using the ANTLR tree grammar syntax?

╄→гoц情女王★ 提交于 2020-01-04 06:49:26
问题 I have successfully built a parser/lexer that creates an AST for my language. Yeah!! I am now onto the "interpreter" stage. I say interpreter in quotes because the language is declarative as isn't really being executed like a procedural language might. It is being translated into Java objects that are used later on in the run of my application. As I am walking my AST I need to translate the tree nodes into Java objects. These Java objects are used else where in my program. I understand how to

ANTLR: How to skip multiline comments

丶灬走出姿态 提交于 2020-01-04 04:12:19
问题 Given the following lexer: lexer grammar CodeTableLexer; @header { package ch.bsource.ice.parsers; } CodeTabHeader : OBracket Code ' ' Table ' ' Version CBracket; CodeTable : Code ' '* Table; EndCodeTable : 'end' ' '* Code ' '* Table; Code : 'code'; Table : 'table'; Version : '1.0'; Row : 'row'; Tabdef : 'tabdef'; Override : 'override' | 'no_override'; Obsolete : 'obsolete'; Substitute : 'substitute'; Status : 'activ' | 'inactive'; Pkg : 'include_pkg' | 'exclude_pkg'; Ddic : 'include_ddic' |