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
...
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...
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...
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...
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...
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?
...
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...
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 ...
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 =
...
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...
I have an ANTLR grammar and I would like to fuzz my parser.
...
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...
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...
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...
I was having difficulty figuring out what does ^ and ! stand for in ANTLR grammar terminology.
...
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...
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 : (~( ' ' | '...
What is the best strategy of making Abstract Syntax Trees serializable to an XML File?
...
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' | ...
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...