antlr

Writing a subshell parsing rule on ANTLR

I'm trying to create a simple BaSH-like grammar on ANTLRv3 but haven't been able to parse (and check) input inside subshell commands. Further explanation: I want to parse the following input: $(command parameters*) `command parameters` "some text $(command parameters*)" And be able to check it's contents as I would with simple in...

Is Antlr a DSL generator and an alternative to Intentional Programming?

I am struck by the ambition and creativity of Charles Simonyi's efforts to establish the field of Intentional Programming, first at Microsoft and then with his own company. http://stackoverflow.com/questions/201386/what-exactly-is-intentional-programming http://en.wikipedia.org/wiki/Intentional_programming In this approach to softw...

How to handle escape sequences in string literals in ANTLR 3?

I've been looking through the ANTLR v3 documentation (and my trusty copy of "The Definitive ANTLR reference"), and I can't seem to find a clean way to implement escape sequences in string literals (I'm currently using the Java target). I had hoped to be able to do something like: fragment ESCAPE_SEQUENCE : '\\' '\'' { setText("'")...

Is ANTLR an appropriate tool to serialize/deserialize a binary data format?

I need to read and write octet streams to send over various networks to communicate with smart electric meters. There is an ANSI standard, ANSI C12.19, that describes the binary data format. While the data format is not overly complex the standard is very large (500+ pages) in that it describes many distinct types. The standard is ful...

Which Java oriented lexer parser for simple project (ANTLR, DIY, etc)

I am working on a small text editor project and want to add basic syntax highlighting for a couple of languages (Java, XML..just to name a few). As a learning experience I wanted to add one of the popular or non popular Java lexer parser. What project do you recommend. Antlr is probably the most well known, but it seems pretty complex...

ANTLR2 vs ANTLR3

Have you used either of these or both? Which do you prefer, and for what reason? For example, I learned v2 recently and am probably going to stick with it because of the high performance implementation provided by the netbeans team (yeah, I'm stuck with java). In this case would there be any compelling reason to switch? ...

How to use the grammar files generated by ANTLR?

I think this is a stupid question, but I'm just starting out with ANTLR. I put together the "SimpleCalc" grammar from their tutorials, and generated it with C as the target language. I got SimpleCalcParser.c/.h and SimpleCalcLexer.c/.h as the output, and I was able to compile these and build successfuly. But now, how do I actually use th...

Can ANTLR generate a parser class that is final?

I'm using ANTLR 3.1 and ANTLRWorks to generate a parser class in Java. The parser performs better if I mark the generated class with the Java final keyword. The problem is: I am adding this keyword manually after each time I re-generated the code from the ANTLR grammar. Is there anyway, in the grammar, of telling ANTLR to add the final k...

What's the best tool for generating a parser in Java for my own language grammar?

I'm developing a small programming language based mostly of the C99 standard and I've already written a fairly decent lexer in java and now I'm looking to generate a Java Parser from the grammar. I know there's Bison, but that seems to only generate C code. I'm looking for a application that will allow me to input my grammar and create a...

Lexer/parser tools

Which lexer/parser generator is the best (easiest to use, fastest) for C or C++? I'm using flex and bison right now, but bison only handles LALR(1) grammars. The language I'm parsing doesn't really need unlimited lookahead, but unlimited lookahead would make parsing a lot easier. Should I try Antlr? Coco/R? Elkhound? Something else? ...

What is a tree parser in ANTLR and am I forced to write one?

I'm writing a lexer/parser for a small subset of C in ANTLR that will be run in a Java environment. I'm new to the world of language grammars and in many of the ANTLR tutorials, they create an AST - Abstract Syntax Tree, am I forced to create one and why? ...

ANTLR and DSL parsing for dummies: whitespace handling

I am trying to develop a mini DSL for software configuration, using antlworks for prototyping. A typical source would look like: name: myname; value: myvalue; flag debug { value = debugvalue; } if flag(debug) { libname = foo_d; } else { libname = foo; } Now, I never got a formal course on parsing, so I am doing all this by tr...

ANTLR Grammar for Java Regular Expression syntax.

I'm currently working on a testing framework for regular expressions, and I need to be able to parse Java regular expressions into ASTs to be able to generate sample strings which match the given regex. I looked at the implementation of java.util.regex.Pattern but the code looks quite unwieldy (the emphasis was on speed over readability...

How to deal with list return values in ANTLR

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 ...

Writing a TemplateLanguage/VewEngine

Aside from getting any real work done, I have an itch. My itch is to write a view engine that closely mimics a template system from another language (Template Toolkit/Perl). This is one of those if I had time/do it to learn something new kind of projects. I've spent time looking at CoCo/R and ANTLR, and honestly, it makes my brain hurt,...

C# String to Expression Tree

This is a simplified version of the original problem. I have a class called Person: public class Person { public string Name { get; set; } public int Age { get; set; } public int Weight { get; set; } public DateTime FavouriteDay { get; set; } } ...and lets say an instance: var bob = new Person(){ Name = "Bob", ...

Need help with building C# example in ANTLR 2.7

Hi, I need to build the CSHARP V1 example which comes with ANTLR v 2.7.7. Command: D:\Comp\antlr\examples\csharp\csharp_v1>nant I am getting the following output: D:\Comp\antlr\examples\csharp\csharp_v1>D:\Comp\nant\bin\nant NAnt 0.85 (Build 0.85.2478.0; release; 10/14/2006) Copyright (C) 2001-2006 Gerry Shaw http://nant.sourcefor...

ANTLR equivalent to bison REJECT action ?

I'm trying to parse a list of Name=Value pairs, where the value can contain anything except whitespace (i.e. values can contain equal signs). The name is restricted to usual identifier characters. The problem is, the 'Value' token matches everything. For example, for the input: dude=sweet the parser will match the whole input with a ...

ANTLR: Parsing 2-digit numbers when other numeric literals are also possible

I'm writing a grammar for a moderately sized language, and I'm trying to implement time literals of the form hh:mm:ss. However, whenever I try to parse, for example, 12:34:56 as a timeLiteral, I get mismatched token exceptions on the digits. Does anyone know what I might be doing wrong? Here are the relevant rules as currently defined:...

Tutorial for walking ANTLR ASTs in C#?

Is anyone aware of tutorials for walking ANTLR-generated ASTs in C#? The closest I was able to find is this, but it's not terribly helpful. My goal is to walk through trees that I'm generating based on a domain-specific language that I'm working on, and to use the trees to output generated C# code. A Java-based tutorial would be helpfu...