antlr3

How do I exclude characters / symbols using ANTLR grammar?

I'm trying to write a grammar for various time formats (12:30, 0945, 1:30-2:45, ...) using ANTLR. So far it works like a charm as long as I don't type in characters that haven't been defined in the grammar file. I'm using the following JUnit test for example: final CharStream stream = new ANTLRStringStream("12:40-1300,15:123-18:59"...

Antlr - Object reference not set to an instance of an object

Hey, Does anyone know anything about how Antlr works? I'm getting an error on a dev server: [NullReferenceException: Object reference not set to an instance of an object.] Antlr.StringTemplate.CommonGroupLoader.LocateFile(String filename) +19 Antlr.StringTemplate.CommonGroupLoader.LoadGroup(String groupName, StringTemplateGroup s...

An antlr problem with embedded comments

Hi, I am trying to implement a nested comment in D. nestingBlockComment : '/+' (options {greedy=false;} :nestingBlockCommentCharacters)* '+/' {$channel=HIDDEN;}; // line 58 nestingBlockCommentCharacters : (nestingBlockComment| '/'~'+' | ~'/' ) ; //line 61 For me, it would be logical that this should work... This is the error...

ANTLR - Implicit AND Tokens In Tree

I’m trying to build a grammar that interprets user-entered text, search-engine style. It will support the AND, OR, NOT and ANDNOT Boolean operators. I have pretty much everything working, but I want to add a rule that two adjacent keywords outside of a quoted string implicitly are treated as in an AND clause. For example: cheese and ...

What does ^ and ! stand for in ANTLR grammar

I was having difficulty figuring out what does ^ and ! stand for in ANTLR grammar terminology. ...

ANTLR Serialization

What is the best strategy of making Abstract Syntax Trees serializable to an XML File? ...

Solving ANTLR Mutually left-recursive rules

the 'expr' rule in the ANTLR grammar below obviously mutually left-recursive. As a ANTLR newbie it's difficult to get my head around solving this. I've read "Resolving Non-LL(*) Conflicts" in the ANTLR reference book, but I still don't see the solution. Any pointers? LPAREN : ( '(' ) ; RPAREN : ( ')' ); AND : ( 'AND' | ' OR : ( 'OR' | ...

Convert ANTLR grammar to Bison / EBNF

Is there a tool for converting an ANTLR grammar to a Bison grmmar? ...

Using antlr to remove dead code

Hi! I am currently servicing an old VBA (visual basic for applications) application. I've got a legacy tool which analyzes that application and prints out dead variables. As there are more than 2000 of them I do not want to do this by hand. Therefore I had the idea to transform the separate codefiles which contain the dead variable acc...

Problem with antlr grammar (lexical)

I get a mismatched set exception when I try to parse "abc" (the quote marks are part of the input) Here is the (simplified) grammar - pretty much verbatim from the Java.g example and basically the same from other example grammars. Is there some bug in the latest version? Using 3.2 in the context of eclipse. Thanks in advance. grammar ...

Antlr AST generating (possible) madness.

Is the following even possible? I want to "reverse" the input given to antlr and make each token a child of the previous one. So, for the input (Assume each token is separated by the '.' char) : Stack.Overflow.Horse I would like my grammar to produce the following AST: Horse |---Overflow |---Stack So far, I've managed ...

Using ANTLR to identify global variable declarations in a JavaScript file

I've been using the ANTLR supplied ECMAScript grammar with the objective of identifying JavaScript global variables. An AST is produced and I'm now wondering what the based way of filtering out the global variable declarations is. I'm interested in looking for all of the outermost "variableDeclaration" tokens in my AST; the actual how-t...

Matching lexeme variants with Antlr3

I'm trying to match measurements in English input text, using Antlr 3.2 and Java1.6. I've got lexical rules like the following: fragment MILLIMETRE : 'millimetre' | 'millimetres' | 'millimeter' | 'millimeters' | 'mm' ; MEASUREMENT : MILLIMETRE | CENTIMETRE | ... ; I'd like to be able to accept any combinat...

Using ANTLR to parse JavaDoc comments

I'm attempting to parse one particular (home grown) JavaDoc tag in my JavaScript file and I'm struggling to understand how I can achieve this. Antlr is complaining as documented below: jsDocComment : '/**' (importJsDocCommand | ~('*/'))* '*/' <== See note 1 ; importJsDocCommand : '@import' gav ; gav : gavGroup ':...

How to do Unicode escape decoding in Antlr tokenizer

I've created a antlr grammar using AntlrWorks, and have created a localization tool for internal use. I would like to convert unicode escape sequences into the actual Java character while parsing, but am unsure of the best way to do this. Here are the token definitions in my grammar. Is there some way to specify an action for the fra...

ANTLR3 lexer precedence

I want to create a token from '..' in the ANTLR3 lexer which will be used to string together expressions like a..b // [1] c .. x // [2] 1..2 // [3] 3 .. 4 // [4] So, I have added, DOTDOTSEP : '..' ; The problem is that I already have a rule: FLOAT : INT (('.' INT (('e'|'E') INT)? 'f'?) | (('e'|'E') INT)? ('...

Java antlr3.2 problem with return values

hi, i have a problem setting/getting the right return values in my antlr grammar. I tried: expressionExp returns [String ref] : Number {$ref = null; } | ident=Identifier {$ref = $ident.text;} | '(' innerExpressionExp ')' ; .. and thought if it now have somethin like ref=expressionExp i get a null if i match a number and th...

ANTLR 3 parsing problem

Hello! I have written an ANTLR 3 grammar for parsing TaskJuggler III bookings files (see below). On line project prj "Sample project" "1.0" 2010-10-24-00:00-+0200 - 2010-11-23-09:00-+0100 { I'm getting following errors: line 1:42 mismatched character '-' expecting set '0'..'9' line 1:48 mismatched character ':' expecting...

ANTLR Lua long string grammar rules

I'm trying to create ANTLR parser for Lua. So i took grammar produced by Nicolai Mainero(available at ANTLR's site, Lua 5.1 grammar) and begin to work. Grammar is good. One thing not working: LONG STRINGS. Lua specification rule: Literal strings can also be defined using a long format enclosed by long brackets. We define an op...