[antlr-interest] Trying to get template output.

Phil Ritchie endigitalmind at yahoo.co.uk
Thu Aug 3 01:49:56 PDT 2006


Would a kind soul out there help me get stringtemplate output with my grammar below. I'm using antlrworks-1.0ea11. The simple record oriented grammar works and successfully parses test files. I've read "Language Translation Using ANTLR and StringTemplate" but despite several attempts, I'm getting nowhere - not a single bit of output. If someone would annotate my grammar and show me a sample *.stg file that would give me a working example it would help enormously with my understanding. Just one line of output would be great. I'm honestly not try to get someone to do my work for me - just looking for an example that's linked to my grammar. I've read the cminus example in the v3 examples folder as well but alas I must be dim.
//
// This is a serious attempt to get to grips with ANTLR
//
grammar learningGrammar;
options
{
output = template;
}
@header
{
import org.antlr.stringtemplate.*;
}
file
scope
{
List globals;
}
@init
{
$file::globals = new ArrayList();
}
: record
;
record : (title
  ident
  keywords
  question
  html
  response)+
;
title : 'Title: ' content
;
ident : 'ID: ' ID
;
keywords: 'Keywords: ' content
;
question: 'Question: ' content
;
html : 'HTML: ' BOOLEAN
;
response: 'Response: ' content
;
content : LETTER
;
BOOLEAN : 'yes' | 'no'
;
ID : ('0'..'9')+
;
LETTER : ('a'..'z' | 'A'..'Z' | '/' | ' ' | '<' | '>')+
;
WS : ('\t' | '\r' | '\n')+  { channel = 99; }
;


More information about the antlr-interest mailing list