antlr

How does ANTLR perform its character manipulation?

ANTLR 3 seems to use some sort of regex like manipulation in its rules, does anyone know if it uses a custom syntax and where the documentation for that is? ...

How do I use the Antlr generated junit file made by translating a gunit file

I am trying to make unit tests for multiple return values in Antlr. I have regular unit tests working using gunit. However, I am not too sure what to do with the junit Testgrammar.java file that is generated as per the instructions at http://www.antlr.org/wiki/display/ANTLR3/gUnit+-+Grammar+Unit+Testing I've tried running: java -cp "./...

ANTLR parse problem

I need to be able to match a certain string ('[' then any number of equals signs or none then '['), then i need to match a matching close bracket (']' then the same number of equals signs then ']') after some other match rules. ((options{greedy=false;}:.)* if you must know). I have no clue how to do this in ANTLR, how can i do it? An ex...

ANTLR "unexpected end of subtree"

Hey. I'm new to ANTLR. ANTLRWorks wizard wrrited for me the following code: grammar test; ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* ; INT : '0'..'9'+ ; FLOAT : ('0'..'9')+ '.' ('0'..'9')* EXPONENT? | '.' ('0'..'9')+ EXPONENT? | ('0'..'9')+ EXPONENT ; COMMENT : '//' ~('\n'...

antlr: is there a simple example ?

I'd like to get started with antlr, but after spending a few hours reviewing the examples at the antlr.org site, I still cant get a clear understanding of the grammar to java process. is there some simple example? something like a four operations calculator implemented with antlr going through the parser definition and all the way to ...

Erlang and Antlr

Is it possible to write an Antlr code generation target for Erlang? ...

How to get ANTLR to output hierarchical ASTs?

I have a Lua grammar, (minor modifications to get it to output for C#, just namespace directives and a couple of option changes) and when I run it on some sample input, it gives me back a tree with a root "nil" node and as childs what looks to be a tokenized version of the input code. It looks like ANTLR's tree grammars operate on hierar...

Need a calc example for ANTLR3

Hi/lo. I've succesfully installed ANTLR3 on my Windows and bound it to Visual Studio, but... Could anybody show me a working example of calculator in C++/ANTLR? The same as from distrib, which is written in Java. I have a trouble making it. I use std::map<std::string, double> for nametable, but one cannot load C++ headers from @header,...

CIL ANTLR Grammer?

Is there any .NET CIL (AKA MSIL) ANTLR grammer? Thank you! ...

Seeking very simple ANTLR error handling example when generating C code

I want to generate C code. I will not be reading from an input file, one line at a time *as, for instance, a compiler might). Rather, I will be parsing user input as it arrives, one line at a time. I would prefer to detect and handle bad input in the lexer/parser, e.g /* lexer tokens */ foo : "FOO"; bar : "BAR"; baz : "BAZ"; /* grammar...

How can we software-engineering antler walker, and its related java codes?

Antlr users usually create a parser that generates the AST(Abstract syntax tree), and a walker that walks through the AST and generate the desired outcomes. As we know, java(C++, python...etc) codes has to be injected into the .g walker files to carry out the execution. However, when the target gets complicated, say we are to develop a w...

Extending simple ANTLR grammer to support input variables

I'm still on my quest for a really simple language and I know now that there are none. So I'm writing one myself using ANTLR3. I found a really great example in this answer: Exp.g: grammar Exp; eval returns [double value] : exp=additionExp {$value = $exp.value;} ; additionExp returns [double value] : m1=multiplyE...

Markdown blockquote parsing with ANTLR

This has been something that's been bothering me for a while. How does one go about parsing the following text into the HTML below using ANTLR? I can't seem to wrap my head around this at all. Any Ideas? Markdown: > first line > second line > blockquote> <p>first line second line</p> <blockquote> <p>nested quote</p> </b...

Manually emit a token with ANTLR

Hello folks, I'm having a bit of trouble manually emitting a token with a lexer rule in ANTLR. I know that the emit() function needs to be used but there seems to be a distinct lack of documentation about this. Does anybody have a good example of how to do this? The ANTLR book gives a good example of how you need to do this to parse ...

How do I make a TreeParser in ANTLR3?

I'm attemping to learn language parsing for fun... I've created a ANTLR grammar which I believe will match a simple language I am hoping to implement. It will have the following syntax: <FunctionName> ( <OptionalArguments>+) { <OptionalChildFunctions>+ } Actual Example: ForEach(in:[1,2,3,4,5] as:"nextNumber") { Print(messa...

How do I match unicode characters in antlr

Hello, I am trying to pick out all tokens in a text and need to match all Ascii and Unicode characters, so here is how I have laid them out. fragment CHAR : ('A'..'Z') | ('a'..'z'); fragment DIGIT : ('0'..'9'); fragment UNICODE : '\u0000'..'\u00FF'; Now if I write my token rule as: TOKEN : (CHAR|DIGIT|UNICODE)+; I get ...

How can I tell antlr to match a tree starting with any token except for a given token?

I've got a basic preprocessor grammar with the following Tree Parser rules. What I'd like to figure out is if I can remove the syntactic predicates in the expand_item rule. The rule checks if it finds and identifier, if so it calls the identifier_expand rule to see if it's a macro name we know about. If it finds an expanded macro then...

Antlr left recursive problem

I have a left recursive issue in my Antlr grammar. While I think I understand why there is a problem I am unable to think of a solution. The issue is with the last line for my datatype rule. I have included the entire grammar for you to see: grammar Test; options {output=AST;ASTLabelType=CommonTree;} tokens {FUNCTION; ATTRIBUTES; C...

Antrl3 conditional tree rewrites

Hello again, Stackoverflow. Continuing on my journey into Antlr (Previous questions may provide additional clues on what I'm trying to achieve! Q1 - How do I make a tree parser and Q2 - Solving LL recursion problem) I've hit yet another roadblock I cannot flathom. Basically (I believe) the expression rule in my grammar needs to either ...

How can I keep track of original character positions in a string across transformations?

I'm working on an anti-plagiarism project for my CS class. This involves detecting plagiarism in computer science courses (programming assignments), through a technique described "Winnowing: Local Algorithms for Document Fingerprinting." Basically, I'm taking a group of programming assignments. Lets say one of the assignments looks lik...