Add another example
This commit is contained in:
parent
733dfffe75
commit
27540745fe
|
@ -0,0 +1,6 @@
|
||||||
|
MODULE = (M|m)odule
|
||||||
|
END = [Ee]nd
|
||||||
|
IF = if|If
|
||||||
|
IDENT = [a-zA-Z_][a-zA-Z_0-9]*
|
||||||
|
ignore = \n| |\t
|
||||||
|
UNKNOWN = .
|
|
@ -0,0 +1,37 @@
|
||||||
|
#include "KeywordsLexer.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
KeywordsLexer lex(std::cin);
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
KeywordsLexer::Token tok = lex.nextToken();
|
||||||
|
switch (tok.type) {
|
||||||
|
case KeywordsLexer::MODULE:
|
||||||
|
std::cout << "MODULE: ";
|
||||||
|
break;
|
||||||
|
case KeywordsLexer::END:
|
||||||
|
std::cout << "END: ";
|
||||||
|
break;
|
||||||
|
case KeywordsLexer::IF:
|
||||||
|
std::cout << "IF: ";
|
||||||
|
break;
|
||||||
|
case KeywordsLexer::IDENT:
|
||||||
|
std::cout << "IDENT: ";
|
||||||
|
break;
|
||||||
|
case KeywordsLexer::UNKNOWN:
|
||||||
|
std::cout << "UNKNOWN: ";
|
||||||
|
break;
|
||||||
|
case KeywordsLexer::nonmatching: case KeywordsLexer::ignore:
|
||||||
|
break; //These can never occur, just to satisfy the compiler...
|
||||||
|
}
|
||||||
|
std::cout << "\"" << tok.content << "\"" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (KeywordsLexer::NoMatch& err) {
|
||||||
|
std::cout << "'" << lex.peek() << "'" << " did not match" << std::endl;
|
||||||
|
}
|
||||||
|
catch (KeywordsLexer::NoMoreTokens& err) {
|
||||||
|
std::cout << "DONE" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue