Need help with first ANTLR grammar
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Owen_Anderson
Posted On:   Monday, August 23, 2004 06:00 PM

Hey, I'm an ANTLR beginner looking for some help with my first ANTLR grammar. I'm defining the grammar for a statement that looks more or less like a Java package statement, except that the keyword is 'module'. So an example input file should look like this: module my.module.this; And the final program should output "my.module.this". However, I can't get the generated C++ to compile. It gives me errors on a not being defined. Here's what I have: class DParser extends Parser; parse : moduleDecl ; moduleDecl : MODULE a:(ID (DOT ID)* ) { cout < < a->getText(); }    More>>

Hey, I'm an ANTLR beginner looking for some help with my first ANTLR grammar.



I'm defining the grammar for a statement that looks more or less like a Java package statement, except that the keyword is 'module'. So an example input file should look like this:



module my.module.this;



And the final program should output "my.module.this". However, I can't get the generated C++ to compile. It gives me errors on a not being defined.



Here's what I have:



			
class DParser extends Parser;

parse :
moduleDecl
;

moduleDecl :
MODULE
a:(ID (DOT ID)* ) { cout < < a->getText(); }
SEMI
;

class DLexer extends Lexer;

SEMI :
';'
;

DOT :
'.'
;

ID :
( 'a'..'z' | 'A'..'Z' | '_' )
( 'a'..'z' | 'A'..'Z' | '_' | '0'..'9')*
;

MODULE :
"module"
;
   <<Less
About | Sitemap | Contact