antlr

ANTLR no viable alternative at input '<EOF>'

I'm still on the learning path with ANTLR. I've built a grammar and for the most part it does what I expect, but I need it to be able to run silently (no output to stdout or stderr). Grammar grammar MyPredicate; options { output=AST; } parse : expression EOF ; expression : field WS? OPERATOR_BINARY WS? value ...

Why is ANTLR parsing skipping token?

I'm trying to do some very basic C++ function declaration parsing. Here is my rule for parsing an input parameter: arg : 'const'? 'unsigned'? t=STRING m=TYPEMOD? n=STRING -> ^(ARG $n $t $m?) ; STRING : ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'::')+ ; TYPEMOD : ('*' | '&')+ ; The problem is I'm trying to pass it something like: int *pa...

Antlr grammar with single quotes doubling as operators.

I am working on an Antlr grammar in which single quotes are used both as operators and in string literals, something like: operand: DIGIT | STRINGLIT | reference; expression: operand SQUOTE; STRINGLIT: '\'' ~('\\'|'\'')* '\''; Expressions like 1' parse correctly, but when there is input that matches ~('\\'|'\'')* after the quo...

Antlr grammar: declaring the grammatical context

I've been looking at: http://www.antlr.org/wiki/display/~admin/2008/04/11/Rewrite+rules There is the section on grammatical context that says: [classDef var]: // context is "field" type ID -> blort [... method var]: // context is "local" type ID -> blech which as I understand is a way for you to look at the past non-terminals t...

ANTLR3 C Target with C++ Exceptions

I have some experience with ANTLR 2's C++ target, but have been hesitant to spend much time on ANTLR 3 because of my fears about exception safety. Sadly, ANTLR 3 only has a C target which produces C which is "C++ compatible." This does not seem to include C++ exception safety, based on the following: You can probably use [exception...

ANTLR, C-styled macro definitions

What is the easiest (or the best) way to implement macro definitions in ANTLR? What I want is a mechanism similar to the one that is present in C/C++ language: #define FUNCTION(a, b) a+b #define PI 3.1415 How and when should I perform replacement? ...

Help ... LL Grammar And Recursive descent parser

I'm using ANTRL and this is my some grammar which give error to me. statement : (name)( | BECOMES expression | LPAREN (expression (COMMA expression)*)? RPAREN | SHIFTLEFT name LPAREN (expression ( COMMA expression )*)? RPAREN ) | OUTPUT LPAREN expression ( COMMA expression)* RPAREN | IF expression THEN state...

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

Why Nhibernate cannot create this simple query for me?

Hi, I cannot understand why this simple query is not created. I call this method from a test and it throws an exception complaining about line 1, column 7 where I cannot see anything wrong. public IList<Continent> GetContinentByName(string name) { ISession session = GetSession(); IQuery query = ...

When is it practical to use a parser generator?

I'm writing a simple text-template language for a web application I'm writing (think google's ctemplate). When finished, it'll feature only a small number of possible actions, simple stuff like "evaluate and execute", "evaluate and print", "evaluate and escape html", "comment". I was thinking of hand writing the whole parser from scratch...

Is there a utility which given an ANTLR grammar will produce matching strings?

I have an ANTLR grammar and I would like to fuzz my parser. ...

A small lisp like DSL that gets compiled into C/C++ code -- Antlr a good choice?

Creating a Lisp syntax like DSL - very small specific application - but very fast - code generation in C, Antlr a good choice? It is necessary for many reasons that it be very fast and it will internally call a lot of C++ APIs, hence I cannot write it in a language other than C/C++. The last time I did something in compilers was in sc...

antlr to generate python code is feasible?

the requirement is to generate several classes which inherits the base ORM class, and this class may have several static properties like columns and other things, and little bit python expressions that can be eval at run time for small business logic, my question is, it is feasible to use antlr for such kind of things, as I'm not much f...

ANTLR: MismatchedTokenException with similar literals

I have the following rule : A B; A : 'a_e' | 'a'; B : '_b'; Input: a_b //dont work a_e_b //works Why is the lexer having trouble matching this? When ANTLR matches the 'a_' in 'a_b' shouldnt it backtrack or use lookahead or something to see it cant match a token A and then decide to match token A as 'a' and then procede to matc...

What does ^ and ! stand for in ANTLR grammar

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

ANTLR, lack of method in C# target

I generated the C# code from tree grammar using ANTLR and I cannot find the method downup(). Is the sequence of calls: topdown(); bottomup(); equivalent to downup() method? Why the method does exist in Java but not in C#? And why do they (the authors) advise to override the following methods: protected override void Topdown() { topdo...

'Token collision' in Boolean Query Parser

I'm creating a simple boolean query parser. I would like to do something like this below. grammar BooleanQuery; options { language = Java; output = AST; } LPAREN : ( '(' ) ; RPAREN : ( ')' ); QUOTE : ( '"' ); AND : ( 'AND' | ' OR : ( 'OR' | '|' | 'OF' ); WS : ( ' ' | '\t' | '\r' | '\n') {$channel=HIDDEN;} ; WORD : (~( ' ' | '...

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

ANTLR, code generation

The problem is as follows: I have an AST tree, e.g.: ^(IF cond stmt) : { } Now, I would like to generate the code in the following order: if_begin cond stmt if_end So as you can see, IF code encloses the two additional rules. Hence I would like to know, how can I generate such code. I don't want to use return values of cond and s...