2 /* Sample replacement for DLGLexer */
3 /* Shows how to override DLG with your own lexer */
10 #include "config.h" /* include token defs */
11 #include "tokens.h" /* include token defs */
12 #include APARSER_H /* include all the ANTLR yuck */
13 #include "MyLexer.h" /* define your lexer */
14 typedef ANTLRCommonToken ANTLRToken;/* use a predefined Token class */
26 /* Recognizes Tokens IDENTIFIER and NUMBER */
27 ANTLRAbstractToken *MyLexer::
30 /* we will return a pointer to this next guy */
31 ANTLRToken *resultToken = new ANTLRToken;
33 ANTLRChar TokenBuffer[100];
34 /* This routine will just crash if tokens become
35 more than 99 chars; your code must of course
36 gracefully recover/adapt */
39 while ( c==' ' || c=='\n' ) c=getchar();
41 if (c==EOF) {resultToken->setType(Eof); return resultToken;}
44 /* Looks like we have ourselves a number token */
46 TokenBuffer[index++]=c;
49 TokenBuffer[index]='\0';
51 resultToken->setType(NUMBER);
52 resultToken->setText(TokenBuffer);
58 /* We have ourselves an IDENTIFIER token */
60 TokenBuffer[index++]=c;
63 TokenBuffer[index]='\0';
65 resultToken->setType(IDENTIFIER);
66 resultToken->setText(TokenBuffer);