antlr3

ANTLR grammar: parser- and lexer literals

What's the difference between this grammar: ... if_statement : 'if' condition 'then' statement 'else' statement 'end_if'; ... and this: ... if_statement : IF condition THEN statement ELSE statement END_IF; ... IF : 'if'; THEN: 'then'; ELSE: 'else'; END_IF: 'end_if'; .... ? If there is any difference, as this impacts on performa...

ANTLRv3 How to set a custom Lexer and Parser Class names

Is there a way to specify custom class name (meaning independent of the grammar name) for the ANTLRv3 generated Parser and Lexer classes? So in the case of grammar MDD; //other stufff Automatically it would crate MDDParser and MDDLexer, but i would like to have them for example as MDDBaseParser and MDDLexer. ...

How to do Map this or Add to calendar like gmail?

How would gmail have implemented this feature? What technologies go behind enabling such features? Is it related to natural language processing? Any pointers or programming resource would be useful? It could be language neutral or specific to any language?It could be in Java/Python. Do you think they do something with antlr etc., to achi...

How do I change the parent class in ANTLR-3?

By default, a parser generated using ANTLR-3 extends from org.antlr.runtime.Parser. How do I have it extend my custom class instead? ...

ANTLR lexing getting confused over '...' and floats

I think the ANTLR lexer is treating my attempt at a range expression "1...3" as a float. The expression "x={1...3}" is coming out of the lexer as "x={.3}" when I used the following token definitions: FLOAT : ('0'..'9')+ ('.' '0'..'9'+)? EXPONENT? | ('.' '0'..'9')+ EXPONENT? ; AUTO : '...'; When I change FLOAT to jus...

This antlr example is not working properly

Hi, This ANTLR example does not parse input "1;" . Can you explain why? It parses "11;". grammar TestGrammar; options { output=AST; } expr: mexpr (PLUS^ mexpr)* SEMI!; mexpr: atom (STAR^ atom)*; atom: INT; LPAREN: '('; RPAREN: ')'; STAR: '*'; PLUS: '+'; SEMI: ';'; protected DIGIT...

How to get current byte position of the parser in Antlr with c# target?

Hi, I am interested in the current byte position in the stream when parsing something using Antlr 3. I have seen there is a similar question but there was no real answer there. That is why I am trying again. I am not interested in token index, byte position in a line etc... Could you someone tell me that? It is obvious that some code ha...

ANTLR: using stringTemplate

(I'm a Noob with Antlr)... I'm having difficulties getting my grammar with StringTemplates. Basically I'm trying to write a little DSL. I can get my grammar the way I want (it parses correctly), but I can't get the generation of the target code to work with templates. So here's a snippet of my grammar: grammar Pfig; options { outp...

Help with parsing a log file (ANTLR3)

I need a little guidance in writing a grammar to parse the log file of the game Aion. I've decided upon using Antlr3 (because it seems to be a tool that can do the job and I figured it's good for me to learn to use it). However, I've run into problems because the log file is not exactly structured. The log file I need to parse looks lik...

antlr 3 ambiguity

Hello, I try to write some simple rules and I get this ambiguity rule: field1 field2; //ambiguity between nsf1 and nsf2 even if I use lookahead k=4 field1: nsf1 | whatever1...; field2: nsf2 | whatever2...; nsf1: 'N' 'S' 'F' '1'; //meaning: no such field 1 nsf2: 'N' 'S' 'F' '2'; //meaning: no such field 2 I understand the ambiguity,...

Parsing some particular statements with antlr3 in C target

Hello all! I have some questions about antlr3 with tree grammar in C target. I have almost done my interpretor (functions, variables, boolean and math expressions ok) and i have kept the most difficult statements for the end (like if, switch, etc.) 1) I would like interpreting a simple loop statement: repeat: ^(REPEAT DIGIT stmt); ...

Why does Antlr not generate a lexer java file?

Hi, Antlr3 does not generate Mylexer.java. I use AntlrWorks... when I have grammar starting like grammar mylexer; It does generate myParser.java It looks like a simple thing.. I wonder what may be the reason.. and the solution... I get no error message. ...

What happened to setASTNodeClass in Antlr 3?

Hi, What happened to setASTNodeClass in Antlr3? What needs to be used in Antlr3 instead? Thanks. ...

ANTLR: simple example from ANTLRWorks wizard doesn't work

Grammar: grammar test; WS : ( ' ' | '\t' | '\r' | '\n' ) {$channel=HIDDEN;} ; STRING : '"' ( ESC_SEQ | ~('\\'|'"') )* '"' ; fragment HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ; fragment ESC_SEQ : '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\') | UNICODE_ESC | OCTAL_ESC ;...

Netbeans and EOF

Hey there, Java, ANTLR and Netbeans newbie here. I have installed a jdk and netbeans. I started a new project on netbeans 6.8 and i have added the antlr-3.2.jar as a library. I also created a lexer and parser class using AntlrWorks. These classes are named ExprParser.java and ExprLexer.java. I copied them into a directory named p...

how to check an ANTLR token is only used once or less in the parser

In Antlr, if I have a rule for example: someRule : TOKENA TOKENB; it would accept : "tokena tokenb" if I would like TOKENA to be optional, I can say, someRule : TOKENA* TOKENB; then I can have : "tokena tokenb" or "tokenb" or "tokena tokena tokenb" but this also means it can be repeated more that once. Is there anyway I can say t...

Parsing ambiguous input with Antlr

I have been trying for a few days to parse some text that consists of text and numbers (I've called it a sentence in my grammar). sentence options { greedy=false; } : (ANY_WORD | INT)+; I have a rule that needs to parse a sentence that finishes with an INT sentence_with_int : sentence INT; ...

scanning binary files in antlr3

I would like to parse a binary file and specify the characters in hex format instead of unicode, is this possible? For instance: rule: '\x7F' ; Instead of: rule: '\u007F' ; Since I do not understand how unicode maps to one byte. ...

MSBuild ANTLR Integration failing building solution with dependent projects

I have a solution that is using the integration steps found on the ANTLR site to generate cs files from an ANTLR Grammar. Everything works as expected when running in Dev Studio, however, when building in MSBuild, the dependent projects are failing because MSBuild is treating the generated files as project references (i.e. assemblies). ...

why does 'a'..'z' in ANTLR match wildcards like $ or £

When I run the following grammer: test : WORD+; WORD : ('a'..'z')+; WS : ' '+ {$channel = HIDDEN;}; and I give the input "?test" why does antlr accept this as valid input? I thought the ('a'..'z') would only match characters within the lowercase alphabet? ...