antlr

antlr 4: Should all of these tokens be showing up in the AST?

大城市里の小女人 提交于 2019-12-11 08:58:46
问题 My ultimate goal is to parse a structured file as a tree of in-memory objects that I can then manipulate. The file format that I'm using is fairly sophisticated with about 200 keywords/tags, and this seemed like a good reason to learn about parser/lexer frameworks. Unfortunately, there are so many concepts (and hundreds of tutorials and guides) that the learning process so far feels like trying to drink from a fire hose. So I'm taking some very meager baby steps, starting with this example. I

rule has non-LL(*) decision due to recursive rule invocations

风流意气都作罢 提交于 2019-12-11 08:14:42
问题 I have an error (like said in the title) with one rule that i dont know how resolve. i have written the following rule : FunctionArguments returns FunctionArgs::IFunctionArguments : FunctionArgumentsNormal | FunctionArgumentsForIter ; FunctionArgumentsNormal returns FunctionArgs::IFunctionArguments : {FunctionArgs::FunctionArguments} args+=Expression (',' args+=Expression)* | {FunctionArgs::FunctionArguments} argNames+=NamedArguments (',' argNames+=NamedArguments)* ; FunctionArgumentsForIter

move to a new state after cosuming tokens in antlr4

自古美人都是妖i 提交于 2019-12-11 07:44:49
问题 i have following grammar root : sql_statements EOF | EOF ; sql_statements :( sql_statement )+ ; sql_statement : ddl_statement semicolon ; ddl_statement : alter_statement ; This is a initial snapshot of my grammar i have following test case aleter table user;alter table group_user; first statement has error hence i am getting error for both statements under sql_statements rule Failed to parse at line 1:1 due to mismatched input 'aleter' expecting ALTER Now i want to use Defaulterrorhandler

ANTLR Parsing - Matches Wrong Thing but Fix is EOF?

怎甘沉沦 提交于 2019-12-11 07:38:23
问题 I try to parse: return 3 + 4; My parse code (see below) parses it as the second rule ( statement statements program ) instead of the first rule. If I comment out the second rule, then the parser interprets it as the third rule ( functions statement program ). My "fix" that has worked so far is to make: master : program EOF ; Why does that fix my issue? Relevant Parse Code: program : statement { System.out.println("STATEMENT PROGRAM"); } | statement statements program { System.out.println(

goto statement in antlr?

橙三吉。 提交于 2019-12-11 07:01:43
问题 I would really appreciate if someone could give me advice,or point me to tutorial, or sample implementation, anything that could help me implement basic goto statement in ANTLR? Thanks for any help edit. ver2 of question: Say I have this tree structure: (BLOCK (PRINT 1) (PRINT 2) (PRINT 3) (PRINT 4) ) Now, I'm interested to know is there a way to select, say, node (PRINT 2) and all nodes that follow that node ((PRINT 2) (PRINT 3) (PRINT 4)) ? I'm asking this because I'm trying to implement

building a scala-java-antlr project in maven results with ClassDefNotFoundError on runtime

。_饼干妹妹 提交于 2019-12-11 06:59:42
问题 I'm trying to port mustache.scala to scala 2.10 , and make it built with maven with antlr3-maven-plugin instead of sbt. so far, i got this, and the code is compiled successfully. but at runtime, when i try to execute something simple like new Mustach("hello {{world}}!") , i get a java.lang.NoClassDefFoundError . the weird thing, is that at first, i got the NoClassDefFoundError for Node class. i didn't understand why the java classes were'nt in the compiled jar, but i was eager to test if it

Antlr AST generating (possible) madness

拜拜、爱过 提交于 2019-12-11 06:57:06
问题 Is the following even possible? I want to "reverse" the input given to antlr and make each token a child of the previous one. So, for the input (Assume each token is separated by the '.' char) : Stack.Overflow.Horse I would like my grammar to produce the following AST: Horse |---Overflow |---Stack So far, I've managed to reverse the nodes, but I'm unable to make them children of each other: function : ID PERIOD function -> function ID | ID ; ID : 'a'..'z'* ; 回答1: I don't think there's an easy

ANTLR: removing clutter

為{幸葍}努か 提交于 2019-12-11 06:54:57
问题 i'm learning ANTLR right now. Let's say, I have a VHDL code and would like to do some processing on the PROCESS blocks. The rest should be completely ignored. I don't want to describe the whole VHDL language, since I'm interested only in the process blocks. So I could write a rule that matches process blocks. But how do I tell ANTLR to match only the process block rule and ignore anything else? 回答1: I know next to no VHDL, so let's say you want to replace all single line comments in a (Java)

How do you specify the access specifier on an ANTLR v3 generated parser or lexer?

*爱你&永不变心* 提交于 2019-12-11 06:47:51
问题 Using ANTLR v3 and the CSharp2 language specifier, is there any way to indicate that you want the generated lexer or parser to be internal versus the default of public? The namespace is specified with: @lexer::namespace {My.Namespace} and I would assume something similar exists for the access specifier, but I have been unable to find it. 回答1: This thread on the antlr-interest mailing list talks about it. At the time of writing they are adding access specifiers to rules, but don't support

write a grammar rule name in unicode [ANTLR 4]

穿精又带淫゛_ 提交于 2019-12-11 06:38:54
问题 I am still a beginner in ANTLR 4 and I was wondering if there is a way to write a grammar rule name in unicode. For example, the following rule is fine: atomExp returns [double value] : n=Number {$value = Double.parseDouble($n.text);} | '(' exp=additionExp ')' {$value = $exp.value;} ; However, let's say I want to write the same rule but instead of writing its name as "atomExp" , I want to write the name as an Arabic word "تعبير" تعبير returns [double value] : n=Number {$value = Double