[antlr-interest] Bison-> Antlr 3 help

Jim Idle jimi at intersystems.com
Fri Oct 20 09:06:06 PDT 2006


You would need an identifier rule and a keyword_id rule, you might also want to use hoisted predicates if there are places where the keywords are not identifiers such as where an identifier is optional and can be logically followed by some keyword, but basically something akin to:

identifier: ID | ( options {k=1;} : (keyword_id)=>keyword_id) ;

keyword_id: KEYWORD1 | KEYWORD2 |KEYWORD3 ....

This won't work for everything though, your own grammar requirements will have to be built in to it of course to avoid all the ensuing ambiguities.

Jim

-----Original Message-----
From: Mike Aubury [mailto:mike.aubury at aubit.com] 
Sent: Friday, October 20, 2006 8:58 AM
To: antlr-interest at antlr.org
Cc: Jim Idle
Subject: Re: [antlr-interest] Bison-> Antlr 3 help

Cheer for that..
The idea with the 'CLOSE' 'SESSION' - was that I was (wrong) thinking it would 
do 'words' with strings (rather than single characters) in the quotes - I can 
see I'll need to do that with some whitespace in there...

Basically - the 
	close_session:
			CLOSE_SESSION

comes from a lex token ("CLOSE SESSION" {... return CLOSE_SESSION;}
(ok - its not quite that simple - but you get the idea)

>
> add_column_clause_ss :
> 	table_element_ss
> 	(BEFORE identifier)?
> 	;

The language is very verbose - that particular bit is part of the SQL ALTER 
statement - so at that point, BEFORE couldn't be an identifier - if 
the 'lexer' saw the word 'BEFORE' i'd want it as a 'reserved word', rather 
than the identifier..
In fact - if it can match to a reserved word at any point in the grammer - I'd 
want it to select that and not an 'ID' - is there any simple way to do that ? 



-- 
Mike Aubury


-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.408 / Virus Database: 268.13.8/489 - Release Date: 10/20/2006
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.408 / Virus Database: 268.13.8/489 - Release Date: 10/20/2006
 


More information about the antlr-interest mailing list