antlrworks

How to specify the exact number of occurance of a token in ANTLR?

I have to define the grammar of a file like the one shown below. //Sample file NameCount = 4 Name = a Name = b Name = c Name = d //End of file Now I am able to define tokens for NameCount and Name. But i have to define the file structure including the valid number of instances of token Name , which is the value after NameCount. I have ...

Compiling ANTLRWorks generated class files

I am using ANTLRWorks to create ANTLR grammars. I have a valid grammar and the parser and lexer source files are generated as well. I have also tried debugging the generated code and the output is as expected in the debugger output. But when I try to invoke the __Test__ class generated by the debugger nothing is coming up in the conso...

Can ANTLR generate a parser class that is final?

I'm using ANTLR 3.1 and ANTLRWorks to generate a parser class in Java. The parser performs better if I mark the generated class with the Java final keyword. The problem is: I am adding this keyword manually after each time I re-generated the code from the ANTLR grammar. Is there anyway, in the grammar, of telling ANTLR to add the final k...

How to deal with list return values in ANTLR

What is the correct way to solve this problem in ANTLR: I have a simple grammar rule, say for a list with an arbitrary number of elements. list : '[]' | '[' value (COMMA value)* ']' If I wanted to assign a return value for list, and have that value be the actual list of returned values from the production, what is the proper way to ...

ANTLR: Parsing 2-digit numbers when other numeric literals are also possible

I'm writing a grammar for a moderately sized language, and I'm trying to implement time literals of the form hh:mm:ss. However, whenever I try to parse, for example, 12:34:56 as a timeLiteral, I get mismatched token exceptions on the digits. Does anyone know what I might be doing wrong? Here are the relevant rules as currently defined:...

generating code to correct directory for specified package

I'm using ANTLRWorks, and have specified my java package using the @header action: @header {package com.xxx.xxx.xxx.compiler} However, when I generate the java code, it is generated to the root src directory rather than src/com/xxx/xxx/xxx/compiler. Consequently, it does not compile cleanly. How do I specify the correct directory to ...

AS3 output from AntlrWorks seems incompatible with runtime SWC

I'm trying to use ANTLR to create a simple math parser targetting AS3 (Flash). I am using the latest version of AntlrWorks (1.2.3) on a Mac and have downloaded the runtime SWC from http://antlr.org/download/ActionScript/antlr3.swc. The generated code looks fine, but seems to be incompatible with the runtime. There are many compile-time ...

Does anyone know of a way to debug tree grammars in ANTLRWorks

The recommended pattern for ANTLR usage is to have the Parser construct an Abstract Syntax Tree, and then build Tree walkers (AKA tree grammars) to process them. I'm trying to get to the bottom of why my tree grammar isn't working and would love to use ANTLRWorks' debugger the same way I used it for the parser itself. The input to the ...

Problem generating code with ANTLR 1.3 / ANTLRWorks

I have downloaded ANTLR 1.3 and ANTLRWorks and can generate rules and syntax diagrams OK. When I try to generate code (e.g. by GenerateCode in ANTLRWorks or with java org.antlr.Tool Temp.g I get error(100): C:\temp\Temp.g 0:0: syntax error: codegen: <AST>: 0:0: unexpected end of subtree I'm on Windows 7 beta, Java 1.6. I have not spe...

Will ANTLR Help? Different Suggestion?

Before I dive into ANTLR (because it is apparently not for the faint of heart), I just want to make sure I have made the right decision regarding its usage. I want to create a grammar that will parse in a text file with predefined tags so that I can populate values within my application. (The text file is generated by another applicati...

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

walk an ast in antlr 3

I'm a enthusiast AntlrWorks user. I built a very nice little DSL with it (and antlr of course) that lets me specify interesting data structures using a very simple english-like syntax. The next step is for me to help the user while they type and to do that I would like to have access to the parsing information in exactly the same way as ...

problem antlrworks code too large

In Antlrworks I get this error: [18:21:03] Checking Grammar Grammar.g... [18:21:26] Grammar.java:12: code too large [18:21:26] public static final String[] tokenNames = new String[] { [18:21:26] ^ [18:21:26] 1 error Using instead the generated code in a Java project works normally. What can be...

Visualizing an AST created with ANTLR (in a .Net environment)

Hi there. For a pet project I started to fiddle with ANTLR. After following some tutorials I'm now trying to create the grammar for my very own language and to generate an AST. For now I'm messing around in ANTLRWorks mostly, but now that I have validated that the parse tree seems to be fine I'd like to (iteratively, because I'm still ...

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

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

MismatchedTokenException in HTML subset grammar

I am writing an ANTLR grammar to recognize HTML block-level elements within plain text. Here is a relevant snippet, limited to the div tag: grammar Test; blockElement : div ; div : '<' D I V HTML_ATTRIBUTES? '>' (blockElement | TEXT)* '</' D I V '>' ; D : ('d' | 'D') ; I : ('i' | 'I') ; V : ('v' | 'V') ; HTML_ATTRIBUTES : ...

What does ^ and ! stand for in ANTLR grammar

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

What is wrong with this grammar? (ANTLRWorks 1.4)

I have the following code written in ANTLRWorks 1.4 grammar hmm; s : (put_a_in_b)|(put_out_a)|(drop_kick)|(drop_a)|(put_on_a); put_a_in_b : (PUT_SYN)(ID)(IN_SYN)(ID); put_out_a : (PUT2_SYN)(OUT_SYN)(ID) | (E1)(ID); drop_kick : ('drop')('kick')(ID); drop_a : (DROP_SYN)(ID); put_on_a : (E2)(ID); PU...

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