antlr

Writing a custom Xtext/ANTLR lexer without a grammar file

夙愿已清 提交于 2019-12-04 03:49:27
I'm writing an Eclipse/Xtext plugin for CoffeeScript, and I realized I'll probably need to write a lexer for it by hand. CoffeeScript parser also uses a hand-written lexer to handle indentation and other tricks in the grammar. Xtext generates a class that extends org.eclipse.xtext.parser.antlr.Lexer which in turn extends org.antlr.runtime.Lexer . So I suppose I'll have extend it. I can see two ways to do that Override mTokens() . This is done by the generated code, changing the internal state. Override nextToken() which seems a natural approach, but then I'll have to keep track of the internal

Source of parsers for programming languages?

送分小仙女□ 提交于 2019-12-04 03:15:56
I'm dusting off an old project of mine which calculates a number of simple metrics about large software projects. One of the metrics is the length of files/classes/methods. Currently my code "guesses" where class/method boundaries are based on a very crude algorithm (traverse the file, maintaining a "current depth" and adjusting it whenever you encounter unquoted brackets; when you return to the level a class or method began on, consider it exited). However, there are many problems with this procedure, and a "simple" way of detecting when your depth has changed is not always effective. To make

Is there an existing ANTLR or IRONY grammar for R?

故事扮演 提交于 2019-12-04 02:24:14
Does anyone know if there is an existing existing ANTLR or IRONY grammar for R? Many thanks. I've built an R grammar for the early access "Honey Badger" ANTLR v4 release, if you'd like to give it a look. See the ANTLR v4 Examples page . Source for v4 is https://github.com/antlr/antlr4 . binary jar here: http://antlr.org/download/antlr-4.0ea-complete.jar For R you want http://www.antlr.org/wiki/download/attachments/28049418/R.g4 I'd guess a good place to look would be R to C Compiler (RCC) that was developed by John Garvin at Rice 来源: https://stackoverflow.com/questions/5705564/is-there-an

C# ANTLR grammar?

点点圈 提交于 2019-12-04 01:58:33
I'm looking for turn-key ANTLR grammar for C# that generates a usable Abstract Syntax Tree (AST) and is either back-end language agnostic or targets C#, C, C++ or D. It doesn't need to support error reporting. P.S. I'm not willing to do hardly any fix-up as the alternative is not very hard. RCIX This may be waaaay too late, but you can get a C# 4 grammar . Here's a C# grammar link, as well as an overview of C# and ANTLR . There are others for the other languages you mentioned here . The DMS Software Reengineering Toolkit provides a full, validated grammar for C# 1.2, 2.0 and 3.0 with generics

Is there a working C++ grammar file for ANTLR?

二次信任 提交于 2019-12-04 01:57:39
Are there any existing C++ grammar files for ANTLR? I'm looking to lex, not parse some C++ source code files. I've looked on the ANTLR grammar page and it looks like there is one listed created by Sun Microsystems here . However, it seems to be a generated Parser. Can anyone point me to a C++ ANTLR lexer or grammar file? C++ parsers are tough to build. I can't speak with experience about using ANTLR's C++ grammars. Here I discuss what I learned by reading the notes attached to the the one I did see at the ANTLR site; in essence, the author produced an incomplete grammar. And that was for just

Unparse AST < O(exp(n))?

梦想的初衷 提交于 2019-12-04 01:20:13
Abstract problem description: The way I see it, unparsing means to create a token stream from an AST, which when parsed again produces an equal AST. So parse(unparse(AST)) = AST holds. This is the equal to finding a valid parse tree which would produce the same AST. The language is described by a context free S-attributed grammar using a eBNF variant. So the unparser has to find a valid 'path' through the traversed nodes in which all grammar constraints hold. This bascially means to find a valid allocation of AST nodes to grammar production rules. This is a constraint satisfaction problem (CSP

Is it advisable to use tokens for the purpose of syntax highlighting?

老子叫甜甜 提交于 2019-12-03 21:43:06
I'm trying to implement syntax highlighting in C# on Android, using Xamarin. I'm using the ANTLR v4 library for C# to achieve this. My code, which is currently syntax highlighting Java with this grammar , does not attempt to build a parse tree and use the visitor pattern. Instead, I simply convert the input into a list of tokens: private static IList<IToken> Tokenize(string text) { var inputStream = new AntlrInputStream(text); var lexer = new JavaLexer(inputStream); var tokenStream = new CommonTokenStream(lexer); tokenStream.Fill(); return tokenStream.GetTokens(); } Then I loop through all of

Using ANTLR to parse a log file

北城余情 提交于 2019-12-03 19:42:23
问题 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

Getting started with ANTLR and avoiding common mistakes

梦想的初衷 提交于 2019-12-03 17:35:33
问题 I have started to learn ANTLR and have both the 2007 book "The Definitive ANTLR Reference" and ANTLRWorks (an interactive tool for creating grammars). And, being that sort of person, I started at Chapter 3. ("A quick tour for the impatient"). It's a fairly painful process especially as some errors are rather impenetrable (e.g. ANTLR: "missing attribute access on rule scope" problem which just means to me "you got something wrong"). Also I have some very simple grammars (3-4 productions only)

Generate EBNF from ANTLR

荒凉一梦 提交于 2019-12-03 16:48:29
Anybody know of a tool, that generates EBNF from ANTLR? ANTLR is already close to EBNF, but for documentation purpose I would like to have a clean EBNF description (without the Code in between). With antlrworks and this its already nice to get the syntax diagrams: java -cp antlrworks-1.1.4.jar org.antlr.works.Console -f yql.g -o output/ -sd eps but it would like to have a bare textual description, preferable text, tex, html, xml, or similar. I have an online tool that converts foreign grammars to W3C grammar notation. It has an ANTLR3 grammar parser, so maybe this gets close to what you were