[antlr-interest] problem with token

Prados Valiente Enrique Enrique.PradosValiente at reale.es
Fri Sep 3 00:02:33 PDT 2010


Hi,

I have a sql.g grammar, and I use token NULL = 'null';

I get error NoViableAltException

Error: False
Linea: 39 Char: 48
UnexpectedType 69
Reale.Parsers.SqlOracle
[@604,917:920='NULL',<69>,39:48]


Se produjo una excepción de tipo 'Antlr.Runtime.NoViableAltException'.
   en Reale.Parsers.SqlOracle.SQLOracleParser.columnValue() en e:\antlr\lexerexample\sqloracleparser.cs:línea 2335


nulo  :
	 NULL // this way doesn't work !!!
	//'NULL' // this way work !!!
	;


I show fragment of my grammar:


grammar SQLOracle;

options {
	language=CSharp2;
	backtrack=true;
	memoize=true;
	output=AST;
	//ASTLabelType=CommonTree;
	ASTLabelType=SqlOracleAST;
	
    //tokenVocab=FKVM;
	
}

...more...

constant 
:
	stringLiteral  
	| nulo
	//nonNegativeInteger 
	//| Real 
	//| intervalLiteral 
	//| HexLiteral
	// subset of ISO 8601 recommended for SQL Server 2005
	//| Iso8601DateTime 
	//| TIMESTAMP s = stringLiteral 
	// currency & system variables not supported
	;	
	
	
// SQL 92 allows string literals broken by whitespace/comments
// (as long as it contains a newline - we're more permissive than that,
// and also allow mixing ASCII parts into Unicode strings).
stringLiteral :
	singleStringLiteral ( singleStringLiteral )*
	;

singleStringLiteral  :
	UnicodeStringLiteral 
	| AsciiStringLiteral 
	;
		
		
   	
nulo  :
	 NULL // this way doesn't work !!!
	//'NULL' // this way work !!!
	;



...more...

NULL : 'null' ;

fragment
AsciiStringRun :
	// single-line literals only
	( '\t' | ' ' .. '&' | '(' .. '~' )+
	;

AsciiStringLiteral :
	'\'' { $text = ""; }
	( s = AsciiStringRun { $text = $s.text; } )? '\''
	( '\'' {
			$text = $text + "\'";
		} ( s = AsciiStringRun { $text = $text + $s.text; } )? '\''
	)*
	;

fragment
UnicodeStringRun :
	(~ '\'' )+
	;

UnicodeStringLiteral :
	'n' '\'' { $text = ""; }
	( s = UnicodeStringRun { $text = $s.text; } )? '\''
	( '\'' {
			$text = $text + "\'";
		} ( s = UnicodeStringRun { $text = $text + $s.text; } )? '\''
	)*
	;


Any suggestions, please


More information about the antlr-interest mailing list