[antlr-interest] Problem with '(' ')'

mzukowski at yci.com mzukowski at yci.com
Thu Oct 9 08:37:02 PDT 2003


Your token numbers might be out of sync.  Is the parser and lexer in the
same .g file?  If not, like Jim said, you need an importVocab in your
parser.

Monty

-----Original Message-----
From: bebopkim [mailto:bebopkim at yahoo.co.kr] 
Sent: Thursday, October 09, 2003 7:05 AM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Problem with '(' ')'

I have made simple RDQL parser and I got a problem. When I tried to 
parse a triple pattern, the parser gave me an error like this:

(?a, ?b, ?c)
IDENTIFIER
IDENTIFIER
IDENTIFIER
line 1:1: expecting LPAREN, found '('

I'm an ANTLR beginner. How can I solve this problem?

The parser's source code is below:
/*
 * @(#)_rdqlparser.g created on 2003. 9. 14.
 *
 */

/**
 * RDQL parser generating script
 *
 * @version $Id$
 * @author hjkim
 *
 */

class LocalRDQLParser extends Parser;

options {
	k = 4;
//	analyzerDebug = true;
//	codeGenDebug = true;
	
}

tokens {
	SELECT;
	VAR;
	COMMA;
	STAR;
	LPAREN;
	RPAREN;
	URI;
	NUMERIC_LITERAL;
	NULL_LITERAL;
	STRING_LITERAL1;
	STRING_LITERAL2;
	TRUE;
	FALSE;
}


//query :
//	 selectClause triplePatternClause { System.out.println
("query"); }
//	;
//
//
//selectClause :
//	  SELECT VAR (COMMA VAR)* | SELECT STAR
//	;
//
//triplePatternClause :
//	  WHERE triplePattern (COMMA triplePattern)*
//	;

triplePattern :
	  LPAREN varOrURI COMMA varOrURI COMMA varOrLiteral RPAREN
	{ System.out.println("TRIPLE Pattern!"); }
	;

varOrURI :
	  VAR
	| URI
	;

varOrLiteral :
	  VAR
	| literal
	;

literal :
	  URI
	| NUMERIC_LITERAL 
	| NULL_LITERAL
	| textLiteral
	| booleanLiteral
	;
	
textLiteral :
	  (STRING_LITERAL1 | STRING_LITERAL2)
	;

booleanLiteral : 
	  TRUE | FALSE
	;
	
class LocalRDQLLexer extends Lexer;

options { 
	k = 4;
    charVocabulary = '\u0000'..'\u007F';
    exportVocab = RDQL;
//    testLiterals = false;
	caseSensitive = false;
	caseSensitiveLiterals = false;
}

tokens {
	SELECT	= "select";
	FROM	= "from";
	WHERE	= "where";
	TRUE	= "true";
	FALSE	= "false";
	NULL_LITERAL =  "null";	
}

COMMA	: ',';
LPAREN	: '(';
RPAREN	: ')';
STAR	: '*';




VAR	: 
	'?' IDENTIFIER
//  	{ System.out.println("VAR"); }	
	;
	
STRING_LITERAL1	: 
	'\'' ( (~('\''|'\\'|'\n'|'\r')) | ('\\' ~('\n'|'\r')))* '\''
//	{ System.out.println("String Literal1"); }
	;
	
STRING_LITERAL2 :
	'"'  ( (~('"' |'\\'|'\n'|'\r')) | ('\\' ~('\n'|'\r')))* '"'
//	{ System.out.println("String Literal2"); }
	;

URI :
	'<' ( ~('>'|'?') )+ '>'
//	{ System.out.println("URI"); }
	;

NUMERIC_LITERAL : ('0'..'9')+ 
//	{ System.out.println("NUMBER"); }
	;
	

IDENTIFIER :
	('a'..'z'|'_'|'-'|'~'|'$'|'.') ('a'..'z'|'_'|'-
'|'~'|'$'|'.'|'0'..'9')*
	{ System.out.println("IDENTIFIER"); }
	;

WS :
	' ' | '\r' '\n' | '\n' | '\t' | '\r'
    {$setType(Token.SKIP);}
	;
	




 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list