[antlr-interest] Simple ASP-like grammar
Dimitrios Kolovos
dskolovos at gmail.com
Tue Nov 29 16:10:02 PST 2005
Hi,
I am trying to crate a grammar for a simple language that contains two
kinds of things: Text inside [% %] and text outside it (something like a
simple version of ASP or JSP but inside or outside the brackets any type
of text can exist). An example file that I would like to parse would be:
Text1 [%Text2%] Text3
[%Text4%]
The tree I would expect to have is:
-Program
---Text1 (anyText)
---Text2 (tagged)
---Text3 (anyText)
---Text4 (tagged)
The grammar I have developed is compiled without errors or warnings.
However the parser returns the whole text as a single child of the root
AST node. I have tried to find similar grammars on the web but no luck.
My grammar follows:
header {
package org.xtgl.parse;
import java.util.*;
}
class XtglParser extends Parser;
options {
k = 2;
exportVocab = XtglParser;
buildAST = true;
}
tokens {
TAGGED;
ANYTEXT;
PROGRAM;
}
program
: (tagged|anyText)*
{#program = #(#[PROGRAM,"Program"], program);}
;
anyText
: AnyTextBlock^
{#anyText.setType(ANYTEXT);}
;
tagged
: "[%" AnyTextBlock^ "%]"
{#tagged.setType(TAGGED);}
;
class XtglLexer extends Lexer;
options {
k = 2;
exportVocab = XtglParser;
charVocabulary = '\0' .. '\u00FF';
}
AnyTextBlock
:
('\0' .. '\u00FF')+
;
Any ideas?
Cheers,
Dimitrios
--
Dimitrios S. Kolovos,
Research Associate,
Department of Computer Science,
The University of York,
Url: http://www-users.cs.york.ac.uk/~dkolovos
Phone: 01904434333
More information about the antlr-interest
mailing list