antlr

Tree parsers for compilers written in C++

I'd like to find a tree parser generator to help me transform ASTs for a compiler written in C++. After some quick research I found out about ANTLR (which can be targeted to work with C but not C++). I also found a website that warns against using ANTLR with C++: http://www.bearcave.com/software/antlr/antlr_treeparse.html. The article...

ANTLR: Grammar Test for Optional Parameter (using ? operator)

I have an ANTLR grammar and am defining a function in my language that allows an optional parameter. How can I check whether the optional parameter is passed in or not within the code generation block? I'm basically looking for the syntax to do something like this hypothetical tree grammar statement: myFunc returns [int retval] : 'myFu...

ANTLR (field=value), how to express this?

I'm a total lexer and parser newbie, so please have some patience. Eventually I want to be able to express LDAP style Query strings, e.g. '(foo=bar)', '(!foo=bar)', '(&(foo=bar)(!zip=zap))' and have a tree in the end which I could use to create the actual database query (or whatever) So I thought to start with the simplest form, to pars...

What do people do with Parsers, like antlr javacc?

Out of curiosity, I wonder what can people do with parsers, how they are applied, and what do people usually create with it? I know it's widely used in programming language industry, however I think this is just a tiny portion of it, right? ...

Difference between token definition and lexer tokens

What's the difference between defining a token in the tokens block and defining a token as a lexer index? ...

Parsing wikimedia markup - are EBNF-based parsers poorly suited?

I am attempting to parse (in Java) Wikimedia markup as found on Wikipedia. There are a number of existing packages out there for this task, but I have not found any to fit my needs particularly well. The best package I have worked with is the Mathclipse Bliki parser, which does a decent job on most pages. This parser is incomplete, how...

How to set up a local test/build machine?

Hello I am about to start a new personal project. It aims to be a pretty big one so I thought it would be a good idea to keep some sort of CVS. I have also read lot of interesting stuff about unit testing and I would like to include some system that automatically builds the project and runs a series of test after each check in. The cha...

Antlr hidden channel whitespace problem

Hello, I have the following Antlr grammar: grammar MyGrammar; doc : intro planet; intro : 'hi'; planet : 'world'; MLCOMMENT : '/*' ( options {greedy=false;} : . )* '*/' { $channel = HIDDEN; }; WHITESPACE : ( (' ' | '\t' | '\f')+ | // handle newlines ( '\r\n' // DOS/Windows | '\r' // Macintosh | '\...

Skip part of a tree when parsing an ANTLR AST

I'm using ANTLR 3 to create an AST. I want to have two AST analysers, one to use in production code and one to use in the Eclipse plugin we already have. However, the plugin doesn't require all information in the tree. What I'm looking for is a way to parse the tree without specifying all branches in the grammar. Is there a way to do so?...

How can I construct a clean, Python like grammar in ANTLR?

G'day! How can I construct a simple ANTLR grammar handling multi-line expressions without the need for either semicolons or backslashes? I'm trying to write a simple DSLs for expressions: # sh style comments ThisValue = 1 ThatValue = ThisValue * 2 ThisOtherValue = (1 + 2 + ThisValue * ThatValue) YetAnotherValue = MAX(ThisOtherValue, ...

Looking to Create Custom Domain Specific Language that Outputs HTML

I'm looking to create my own custom domain specific language that outputs HTML. Basically, I want to be able to create quizzes using my own markup, but have that compiled / generated into HTML. For example: > What is your favorite color? * Blue * Green * Red should output <form action="" method="post"> <ul> <li>What is your favori...

Are there any good tutorials that describe how to use ANTLR to parse boolean search strings

I need to parse a boolean search string of keywords and operators into a SQL query to be executed from C# code. I think something like ANTLR is what I need for this task, but I'm not sure how to do it. Are there any good tutorials on how to do this? Or maybe I need a different tool? An example of what I mean is below. The only operator...

Handling multiple return values in ANTLR

Hello, I have a simple rule in ANTLR: title returns [ElementVector<Element> v] @init{ $v = new ElementVector<Element>() ; } : '[]' | '[' title_args {$v.add($title_args.ele);} (',' title_args {$v = $title_args.ele ;})* ']' ; with title_args being: title_args returns [Element ele] : author {$ele = new Element(...

How to manipulate C# AST?

I am working on a Reverse Engineering school project, which requires to translate manipulate AST of compiled C# project. I have seen the post on "Translate C# code into AST?" in this website, but it doesn't look like the one I am looking for. According to what I knew, currently C# doesn't provide a library class that does sth like that f...

generating code to correct directory for specified package

I'm using ANTLRWorks, and have specified my java package using the @header action: @header {package com.xxx.xxx.xxx.compiler} However, when I generate the java code, it is generated to the root src directory rather than src/com/xxx/xxx/xxx/compiler. Consequently, it does not compile cleanly. How do I specify the correct directory to ...

Good parser generator (think lex/yacc or antlr) for .NET? Build time only?

Is there a good parser generator (think lex/yacc or antlr) for .NET? Any that have a license that would not scare lawyers? Lot’s of LGPL but I am working on embedded components and some organizations are not comfortable with me taking an LGPL dependency. I've heard that Oslo may provide this functionality but I'm not sure if it's a bui...

Antlr tree rewrite rules.

I'm trying to parse an expression like a IN [3 .. 5[, where the direction of the angle brackets determine whether the interval is inclusive or exclusive. I want this to be rewritten to an AST like NODE-TYPE | +------------+-----------+ | | | variable lower-bound upper-bound ...

Building own C# compiler using ANTLR: Compilation Unit

Hi, // Create a scanner that reads from the input stream passed to us CSLexer lexer = new CSLexer(new ANTLRFileStream(f)); tokens.TokenSource = lexer; // Create a parser that reads from the scanner CSParser parser = new CSParser(tokens); // start parsing at the compilationUnit rule CSParser.compilation_unit_return x = parser.compilat...

AS3 output from AntlrWorks seems incompatible with runtime SWC

I'm trying to use ANTLR to create a simple math parser targetting AS3 (Flash). I am using the latest version of AntlrWorks (1.2.3) on a Mac and have downloaded the runtime SWC from http://antlr.org/download/ActionScript/antlr3.swc. The generated code looks fine, but seems to be incompatible with the runtime. There are many compile-time ...

Parsing CSS with ANTLR - edge cases

I'm trying to parse CSS, or at least the basics, using ANTLR. I'm running into a few problems with my lexer rules though. The problem lies in the ambiguity between an ID selectors and hexadecimal color values. Using a simplified grammar for clarity, consider the following input: #bbb { color: #fff; } and the following parser rules: ...