antlr

ANTLR parser hanging at proxy.handshake call

我只是一个虾纸丫 提交于 2020-01-02 05:14:05
问题 I am attempting to get a basic ECMAScript parser working, and found a complete ANTLR grammar for ECMAScript 3, which appears to compile ok and produces the appropriate Lexer/Parser/Walker Java files. (Running inside ANTLR IDE plugin for Eclipse 3.5) However, when actually trying to use it with some simple test code (following guide on ANTLR wiki), it just hangs when trying to create the parser: CharStream MyChars = new ANTLRFileStream(FileName); // FileName is valid ES3Lexer MyLexer = new

Returning multiple values in ANTLR rule

霸气de小男生 提交于 2020-01-02 03:29:10
问题 I have an ANTLR rule like this receive returns[Evaluator e,String message] : RECEIVE FILENAME {$e= new ReceiveEvaluator($FILENAME.text);} ; I have added a new return message and I want to put the file content in that. One way I could do is make the evaluator return the String when I walk the tree by calling the evaluate() method. I was wondering if I could do it strightaway here - but am not aware how to set multiple return values and access them later. Thanks Hari 回答1: Here's how to set- and

Is there a valid alternative to ANTLR written in C#? [closed]

送分小仙女□ 提交于 2020-01-02 03:16:07
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . ANTLR is a great piece of software, but, in my opinion, is a little bit uncomfortable for a C# programmer (the C# porting is out of date, the parser antlr-3.1.3.jar required java, etc) I'm looking for a "more C# native" language tool in order to parse a simple json-like grammar, any suggestion? 回答1: I've used

In ANTLR, how do you specify a specific number of repetitions?

▼魔方 西西 提交于 2020-01-02 01:26:10
问题 I'm using ANTLR to specify a file format that contains lines that cannot exceed 254 characters (excluding line endings). How do I encode this in the grammer, short of doing: line : CHAR? CHAR? CHAR? CHAR? ... (254 times) 回答1: This can be handled by using a semantic predicate. First write your grammar in such a way that it does not matter how long your lines are. An example would look like this: grammar Test; parse : line* EOF ; line : Char+ (LineBreak | EOF) | LineBreak // empty line! ;

How to make CMake target executed whether specified file was changed?

不羁岁月 提交于 2020-01-02 00:41:06
问题 I'm trying to use ANTLR in my C++ project. I made a target for running ANTLR generator for specified grammar and made main prjct dependent from it. ADD_CUSTOM_TARGET(GenerateParser COMMAND ${ANTLR_COMMAND} ${PROJECT_SOURCE_DIR}/src/MyGrammar.g -o ${PROJECT_SOURCE_DIR}/src/MyGrammar ) ADD_LIBRARY(MainProject ${LIBRARY_TYPE} ${TARGET_SOURCES} ${TARGET_OPTIONS}) ADD_DEPENDENCIES(MainProject GenerateParser) The problem is that ANTLR generator running every time I build project and consumes enough

Is it possible to parse big file with ANTLR?

自闭症网瘾萝莉.ら 提交于 2020-01-01 09:19:17
问题 Is it possible to instruct ANTLR not to load entire file into memory? Can it apply rules one by one and generate topmost list of nodes sequentially, along with reading file? Also may be it is possible to drop analyzed nodes somehow? 回答1: Yes, you can use: UnbufferedCharStream for your character stream (passed to lexer) UnbufferedTokenStream for your token stream (passed to parser) This token stream implementation doesn't differentiate on token channels, so make sure to use ->skip instead of -

ANTLR and Eclipse (or any decent IDE)

故事扮演 提交于 2020-01-01 04:51:04
问题 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)

ANTLR parsing MismatchedTokenException

拜拜、爱过 提交于 2019-12-31 04:37:07
问题 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 :

Writing language converter in ANTLR

最后都变了- 提交于 2019-12-30 10:33:47
问题 I'm writing a converter between some dialects of the same programming language. I've found a grammar on the net - it's complex and handles all the cases. Now I'm trying to write the appropriate actions. Most of the input is just going to be rewritten to output. What I need to do is parse function calls, do my magic (rename function, reorder arguments, etc) and write it. I'm using AST as output. When I come across a function call, I build a custom object structure (from classes defined in my

Automatically parsing PHP to separate PHP code from HTML

一曲冷凌霜 提交于 2019-12-30 09:43:10
问题 I'm working on a large PHP code base; I'd like to separate the PHP code from the HTML and JavaScript. (I need to do several automatic search-and-replaces on the PHP code, and different ones on the HTML, and different on the JS). Is there a good parser engine that could separate out the PHP for me? I could do this using regular expressions, but they're not perfect. I could build something in ANTLR, perhaps, but a good already existing solution would be best. I should make clear: I don't want