I am working with ANTLR 3.4 .I have defined a lexer rule like
Description:
'description'
;
If I use this rule I will not be able to use 'description' in my language since it is now a keyword.Is there any way by which I can write a rule for non reserved keyword. The rules in grammar looks like-
Lexer rule
Description
:
'description'
;
Protocol
:
'protocol'
;
Define
:
'define'
;
Equal
:
'='
;
Parser rule
mainrule
:
Define Protocol stringrule descrule? fields* finishrule
;
descrule
:
Description? stringrule?
;
fields
:
type stringrule Equal? stringrule?
stringrule
:
// rule which accept any string
;
Example:My language looks like this-
define protocol description 'Protocol for login'
int ip=192.168.0.0;
string description='remote user';
finish protocol;
Here ip and description are fields of protocol and protocol is having description(which is keyword).But I cannot use 'description' as field name as it is a keyword.