[antlr-interest] Rookie attempt at ANTLR 3 (using the current ANTLRWorks under Window XP)

Terence Parr parrt at cs.usfca.edu
Thu Oct 26 09:54:01 PDT 2006


well, there is no rule at all so that's a problem.  But, ANTLR is  
warning you I think not generating an error, right?  Can't remember.
Terence
On Oct 25, 2006, at 1:30 PM, Foolish Ewe wrote:

> Hi Folks:
>
> I'm trying ANTLR 3 today, using ANTLRworks (so far it seems like  
> Bovet and Parr have some
> reallly neat stuff in there).
>
> I'm trying to compile the attached grammar in the tool and am  
> getting a message:
>
> Cannot generate the grammar because grammar TestGrammar : no start  
> rule (no rule can
> obviously be followed by EOF).
>
> This will probably out me to my coauthors and students, but I'm not  
> a big fan of the words
> obviously/easily or their variants :-).
>
> What does this message mean, how can I better convey to ANTLR that  
> startRule is the start rule?
>
> Thanks:
>
> Bill M.
> // Test hoisting and use of predicates to allow us to use  
> "undelimited strings"
> grammar TestGrammar;
>
> // I'm not using tokens in this langauge yet.
> //tokens = { }
>
> @members {
> 	public static void main(String[] args) throws Exception {
> 		TestGrammarLexer lex = new TestGrammmarLexer(new ANTLRFileStream 
> (args[0]));
> 		CommonTokenStream tokens = new CommonTokenStream(lex);
>
> 		SimpleCalc parser = new SimpleCalc(tokens);
> 		try {
> 			parser.startRule();
> 		} catch (RecognitionException e)  {
> 			e.printStackTrace();
> 		}
> 	}
>
> 	// see if we need to use this sort of flag or if parser based  
> checks are enough
> 	// public boolean recognizeKeyWords = true; // should we recognize  
> keywords?
>
> 	// is a token input.LT(i)'s lexeme at least minLength characters  
> long and a key word prefix match?
> 	public boolean kwpm(int i, String pattern, int minlength){
> 		booleean result = false;
> 		String lexeme = input.LT(i).getText().toLower(); // Poor man's  
> case insensitivity :-)
> 		if (lexeme.length() < minLength){ // lexeme too short?
> 			result = false;
> 		} else if (lexeme.length() > pattern.length()){ // lexeme too long?
> 			result = false;
> 		} else { // now we have to check the content
> 			result = pattern.startsWith(lexeme); // is the lexeme a prefix  
> of the pattern?
> 		}
> 		return result;
>
> _________________________________________________________________
> Use your PC to make calls at very low rates https:// 
> voiceoam.pcs.v2s.live.com/partnerredirect.aspx
>



More information about the antlr-interest mailing list