Asif Iqbal wrote:
Hi,
 
I am new to ANTLR. I am trying to write following grammer in ANTLR.

Read the 5 minute intro on the Wiki, then download the pre-existing examples (download page) and crib from them.

Basically your parser rules should start with a lower case letter and your lexer rules with an upper case letter. All your rules here start with upper case and so the lexer is processing them all and of course they are all therefore ambiguous.

Also, I recommend that you don't use 'literals' in your parsers when you are starting out, because until you grok the whole parser/lexer thing, they will confuse you. Define everything as a lexer token and you will be less confused.


Jim
 
//Grammer
grammar GLGrammer;
options
{
 output=AST;
 ASTLabelType=CommonTree;
 language=CSharp;
}
GLLanguage
 : GLQueries ';'
// :  (GLQueries ';') (';')*
 ;
 
GLQueries
 : ConfigurationStatement
// | InsertStatement
// | CreateStatement
// | DropStatement
// | ModifyStatement
// | PostStatement
 ; 
ConfigurationStatement
 : 'SET' SetKeywords
 ;
InsertStatement
 : 'INSERT' INTEGER
 ;
SetKeywords
 :  'DEBUG' 'ON'
  | 'CURRENCY' CURRENCYCODE
  | 'FISCAL' FiscalParameter
  | 'COA' 'LEVEL' INTEGER
  ;
FiscalParameter
 : ('YEAR' | 'MONTH') INTEGER
 ;
INTEGER 
 : ('0'..'9')+
 ;
FLOAT
 : ('0'..'9')* '.' ('0'..'9')+
 ;
DATETIME
  : '#' (~'#')* '#'
        ;
BOOLEAN
 : 'true'
 | 'false'
 ;
 
CURRENCYCODE
 : ('a'..'z' | 'A'..'Z') ('a'..'z' | 'A'..'Z') ('a'..'z' | 'A'..'Z')
 ;

IDENT
 : ('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '_' | '0'..'9')*
 ;

/* Ignore white spaces */ 
WS 
 :  (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}
 ;
//End Grammer
 
The issue is ANTLRWorks generating following error
[11:50:05] error(208): GLGrammer.g:23:1: The following token definitions can never be matched because prior tokens match the same input: ConfigurationStatement
Could not understand the issue. Please help.
 
Regards,
Asif
 

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
-~----------~----~----~----~------~----~------~--~---



List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to