Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Compiler Tools Pccts > ANTLR beginner
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 61 of 134
Post > Topic >>

ANTLR beginner

by Owen Anderson <resistor@[EMAIL PROTECTED] > Aug 23, 2004 at 07:47 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.

Any ANTLR experts want to help?

Thanks,

Owen



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




 1 Posts in Topic:
ANTLR beginner
Owen Anderson <resisto  2004-08-23 19:47:40 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 14:33:27 CDT 2008.