antlrworks

What is wrong with this grammar? (ANTLRWorks 1.4)

心已入冬 提交于 2019-12-04 16:20:27
I have the following code written in ANTLRWorks 1.4 grammar hmm; s : (put_a_in_b)|(put_out_a)|(drop_kick)|(drop_a)|(put_on_a); put_a_in_b : (PUT_SYN)(ID)(IN_SYN)(ID); put_out_a : (PUT2_SYN)(OUT_SYN)(ID) | (E1)(ID); drop_kick : ('drop')('kick')(ID); drop_a : (DROP_SYN)(ID); put_on_a : (E2)(ID); PUT_SYN : 'put' | 'place' | 'drop'; PUT2_SYN : 'put' | 'douse'; IN_SYN : 'in' | 'into' | 'inside' | 'within'; OUT_SYN : 'out'; E1 : 'extinguish'|'douse'; DROP_SYN : 'drop' | 'throw' | 'relinquish'; WS : ( ' ' | '\t' | '\r' | '\n' ) {$channel=HIDDEN;}; ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..

How to deal with list return values in ANTLR

て烟熏妆下的殇ゞ 提交于 2019-12-04 07:01:01
What is the correct way to solve this problem in ANTLR: I have a simple grammar rule, say for a list with an arbitrary number of elements. list : '[]' | '[' value (COMMA value)* ']' If I wanted to assign a return value for list, and have that value be the actual list of returned values from the production, what is the proper way to do it? The alternatives I'm entertaining are: create my own stack in the global scope to keep track of these lists Try to inspect the tree nodes below me and extract information that way Access it in some slick and cool way that I'm hoping to find out about in which

ANTLR and Eclipse (or any decent IDE)

筅森魡賤 提交于 2019-12-03 13:10:30
I have been using ANTLR with Eclipse for some time using the ANTLRv3IDE plugin. While it is not perfect, and a bit outdated, it does its job reasonably well. Now I am looking to switch to ANTLRv4 for another DSL that I am creating. However, Eclipse support seems to be extremely thin. I decided to try out ANTLRWorks, which is a NetBeans plugin, but I could not get it to install (it seems to be locked to specific dated versions (201302132200 while I have something newer, still 7.3 as docs say) of dependencies). So, the question: Has anyone set up any Java IDE (preferably Eclipse, but I could be

Is “Implicit token definition in parser rule” something to worry about?

微笑、不失礼 提交于 2019-12-03 11:39:29
问题 I'm creating my first grammar with ANTLR and ANTLRWorks 2. I have mostly finished the grammar itself (it recognizes the code written in the described language and builds correct parse trees), but I haven't started anything beyond that. What worries me is that every first occurrence of a token in a parser rule is underlined with a yellow squiggle saying "Implicit token definition in parser rule". For example, in this rule, the 'var' has that squiggle: variableDeclaration: 'var' IDENTIFIER ('='

Does anyone know of a way to debug tree grammars in ANTLRWorks

巧了我就是萌 提交于 2019-12-03 10:03:35
问题 The recommended pattern for ANTLR usage is to have the Parser construct an Abstract Syntax Tree, and then build Tree walkers (AKA tree grammars) to process them. I'm trying to get to the bottom of why my tree grammar isn't working and would love to use ANTLRWorks' debugger the same way I used it for the parser itself. The input to the parser is the "source code", but the input to a tree parser is the AST result of the parser. I don't see how to make that available as input to test the tree

ANTLRWorks debugging - the meaning of the different colors?

前提是你 提交于 2019-12-02 07:11:52
问题 I'm using the debugging mode of ANTLRWorks to test my c-grammar. Debugging in ANTLRWorks is really great for better understanding but I have a problem in understanding the different colors of the output tree. I'm using backtrack=true in my grammar. I thought that the red color means that the debugger goes the wrong way while green tells me that it is has gone the right way. But what about dark red and dark green? I added a picture of a "small tree" which only match the following input: int

ANTLR parsing MismatchedTokenException

♀尐吖头ヾ 提交于 2019-12-02 06:42:45
I'm trying to write a simple parser for an even simpler language that I'm writing. It's composed of postfix expressions. As of now, I'm having issues with the parser. When I run it on the input 2 2 * test >> I get a MismatchedTokenException. Also, how would I go about implementing a recursive postfix parser? Here's my code: grammar star; options { language=Python; output=AST; ASTLabelType=CommonTree; } tokens {DECL;} //start // : decl ; //decl // : type ID -> ^(DECL type ID) // ; program : (body)+ ; body : (nested WS)* | (var WS)* | (get WS)* ; var : nested ID '>>' ; get : ID '<<' ; /

ANTLR not throwing errors on invalid input

杀马特。学长 韩版系。学妹 提交于 2019-11-28 13:19:15
I'm using ANTLR to parse logical expressions in a Java tool I'm writing, and I'm having issues because passing invalid input strings to the generated ANTLR lexer and parser doesn't cause any exceptions. Instead of throwing a RecognitionException, like I would expect, the generated files just print the error message to the console and return as if no errors occurred, causing my program to crash when it runs into the empty data later. I used ANTLRWorks version 1.4.3 to generate the files, and it seems like there should be some sort of option to have it actually throw errors rather than print to

antlr3 - Generating a Parse Tree

最后都变了- 提交于 2019-11-27 23:21:02
I'm having trouble figuring out the antlr3 API so I can generate and use a parse tree in some javascript code. When I open the grammar file using antlrWorks (their IDE), the interpreter is able to show me the parse tree, and it's even correct. I'm having a lot of difficulties tracking down resources on how to get this parse tree in my code using the antlr3 runtime. I've been messing around with the various functions in the runtime and Parser files but to no avail: var input = "(PR=5000)", cstream = new org.antlr.runtime.ANTLRStringStream(input), lexer = new TLexer(cstream), tstream = new org

ANTLR not throwing errors on invalid input

≯℡__Kan透↙ 提交于 2019-11-27 07:36:05
问题 I'm using ANTLR to parse logical expressions in a Java tool I'm writing, and I'm having issues because passing invalid input strings to the generated ANTLR lexer and parser doesn't cause any exceptions. Instead of throwing a RecognitionException, like I would expect, the generated files just print the error message to the console and return as if no errors occurred, causing my program to crash when it runs into the empty data later. I used ANTLRWorks version 1.4.3 to generate the files, and