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

Jim O'Connor Jim.OConnor at microfocus.com
Thu Oct 9 07:21:47 PDT 2003


I would look at the options for token vocabularies.  Your Parser doesn't
know anything about the RDQL vocab exported by your lexer.  The IDL example
has an export in both the Lexer and Parser.  That might be your solution.

-----Original Message-----
From: bebopkim [mailto:bebopkim at yahoo.co.kr]
Sent: Thursday, October 09, 2003 10: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/ 



________________________________________________________________________
This e-mail has been scanned for viruses by MCI's Internet Managed Scanning
Services - powered by MessageLabs. For further information visit
http://www.mci.com
________________________________________________________________________

 

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




More information about the antlr-interest mailing list