how to accept a string with white space and alpha numeric as an input to a parameter
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, October 7, 2004 04:26 AM

i am having a lot of parameters defined in the lexer , whose input accepts values . but one among the parameters should accept a string which may contain " alpha numeric characters along with a single white space in the input which may come at any place in the string ( for eg in first , middle or last )" the parameter should accept the value only if it satisfies the above mentioned conditions otherwise it should throw an exception as " invalid value for the parameter x ". i have tried hidden token stream also .but it throws errors. if anybody knows the solution let me know. i have given the source code for which i have tried. if anybody knows the answer let   More>>

i am having a lot of parameters defined in the lexer , whose input accepts values .


but one among the parameters should accept a string which may contain " alpha numeric characters along with a single white space in the input which may come at any place in the string ( for eg in first , middle or last )"


the parameter should accept the value only if it satisfies the above mentioned conditions otherwise it should throw an exception as
" invalid value for the parameter x ".

i have tried hidden token stream also .but it throws errors.

if anybody knows the solution let me know.
i have given the source code for which i have tried.
if anybody knows the answer let me know.



			
header {

import antlr.*;

}

class myparser extends Parser;

options {

k = 7;
defaultErrorHandler = false;


/*
try {
parser.startRule(); // parse as usual
myparser parser=new myparser(filter);
parser.setASTNodeClass("antlr.CommonASTwithHiddenTokens");

}

catch (Exception e) {
System.err.println(e.getMessage());
}
*/


}

startRule throws Exception
{
System.out.println(parser);
}
:
(createlexer
)EOF
;


createlexer throws exception : (WS)?
{
mylexer lexer =new mylexer(System.in);

lexer.setTokenObjectClass("mylexer");

lexer.setTokenObjectClass("antlr.CommonHiddenStreamToken");

TokenStreamHiddenTokenFilter filter=new TokenStreamHiddenTokenFilter(lexer);

System.out.println(filter.getHiddenAfter(end));

System.out.println(filter.getHiddenBefore(begin));

filter.hide(myparser.WS);

filter.hide(myparser.SL_COMMENT);

myparser parser=new myparser(filter);

}
;

class mylexer extends Lexer;
options {

k=10;

caseSensitiveLiterals = false;
caseSensitive = false;
charVocabulary = ' '..'~';
}

/*
mylexer lexer =new mylexer(System.in);

lexer.setTokenObjectClass("mylexer");

lexer.setTokenObjectClass("antlr.CommonHiddenStreamToken");

TokenStreamHiddenTokenFilter filter=new TokenStreamHiddenTokenFilter(lexer);

System.out.println(filter.getHiddenAfter(end));

System.out.println(filter.getHiddenBefore(begin));

filter.hide(myparser.WS);

filter.hide(myparser.SL_COMMENT);


*/


DECLS:(decl)+;

DECL:begin :INT ID end: SEMI
;

WS : (' ' | ' ')+;

SL_COMMENT : ('/')+;

   <<Less
About | Sitemap | Contact