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 <[email protected]> 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 > > List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en -~----------~----~----~----~------~----~------~--~---
