[antlr-interest] need help command(query) language

Martijn Reuvers martijn.reuvers at gmail.com
Thu Oct 29 09:08:49 PDT 2009


Hi Kiso,

I would advise you to read the documentation on the site or buy one of
the available books:

http://pragprog.com/titles/tpantlr/the-definitive-antlr-reference
(specific for antlr)
http://pragprog.com/titles/tpdsl/language-implementation-patterns (for
language design & antlr)

A quick & dirty simple example:

grammar dbsample;

@members {
	String dbName;
}

start
	:	USE NAME other
		{
			dbName = $NAME.text;
		}
	;

other
	:	'...'  // Obviously needs to be something useful as statements etc.
		{
			System.out.println("You are using database=" + dbName);
		}
	;

USE
	:	'use'
	;
	
NAME
	:	('a'..'z' | 'A'..'Z')+
	;

WS:	('\t' | ' ' | '\r' | '\n'| '\u000C')+ { skip(); };


You clearly need to fill in the 'other' rule with something useful. By
using a grammar you already force the usage of 'Use databasename'
first. As input you could use: use mydb ...

Martijn


On Thu, Oct 29, 2009 at 4:35 AM, Siva B <sivaits4u at gmail.com> wrote:
> hi all,
> i need to write a language interpreter which should always start with a
> command
> like
> USE x_database;
> without executing the above i can't write SELECT  command
>
> similar way i need to execute the command language.
>
> if i run USE command i can remember(store ) the database name and i
> can run other commands(SELECT,INSERT UPDATE) well but if don't run the
> USE command and if i try to run other commands  that should give some
> warning.
> How can i do it.
> any help...
>
> I want to print simply like 'database is not selected'
>
> plz help me...
>
> Thanks,
> Kiso
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>


More information about the antlr-interest mailing list