|
| 1 | +#include "utils.hpp" |
| 2 | +#include "A007TestTraits.hpp" |
| 3 | +#include "a007Lexer.hpp" |
| 4 | +#include "a007Parser.hpp" |
| 5 | + |
| 6 | +#include <iostream> |
| 7 | +#include <sstream> |
| 8 | +#include <fstream> |
| 9 | + |
| 10 | +using namespace Antlr3Test; |
| 11 | +using namespace std; |
| 12 | + |
| 13 | +void test1(const char* input); |
| 14 | +void test2(const char* input); |
| 15 | +void test3(const char* input); |
| 16 | + |
| 17 | +int |
| 18 | +main (int argc, char *argv[]) |
| 19 | +{ |
| 20 | + test1("ABC"); |
| 21 | + test1("(ABC)"); |
| 22 | + test1("ABC AS 5"); |
| 23 | + test1("ABC AS(1,2,3,4,5,6)"); |
| 24 | + test1("(ABC,ABD,ABE,ABF)AS(1,2,3,4,5,6)"); |
| 25 | + |
| 26 | + test2("ABC"); |
| 27 | + test2("(ABC)"); |
| 28 | + test2("ABC AS 5"); |
| 29 | + test2("ABC AS(1,2,3,4,5,6)"); |
| 30 | + test2("(ABC,ABD,ABE,ABF)AS(1,2,3,4,5,6)"); |
| 31 | + |
| 32 | + test3("SAMPLE (4)"); |
| 33 | + test3("SAMPLE BLOCK(4,5)"); |
| 34 | + |
| 35 | + printf("finished parsing OK\n"); // Finnish parking is pretty good - I think it is all the snow |
| 36 | + |
| 37 | + return 0; |
| 38 | +} |
| 39 | + |
| 40 | +void test1(const char* input) |
| 41 | +{ |
| 42 | + a007LexerTraits::InputStreamType* istream = new a007LexerTraits::InputStreamType((const ANTLR_UINT8 *)input |
| 43 | + , antlr3::ENC_8BIT |
| 44 | + , strlen(input) |
| 45 | + , (ANTLR_UINT8*)"test1"); |
| 46 | + istream->setUcaseLA(true); |
| 47 | + |
| 48 | + a007Lexer* lxr = new a007Lexer(istream); |
| 49 | + a007LexerTraits::TokenStreamType* tstream = new a007LexerTraits::TokenStreamType(ANTLR_SIZE_HINT, lxr->get_tokSource()); |
| 50 | + a007Parser* psr = new a007Parser(tstream); |
| 51 | + { |
| 52 | + auto r1 = psr->test1(); |
| 53 | + std::cout << r1.tree->toStringTree() << std::endl; |
| 54 | + } |
| 55 | + |
| 56 | + delete psr; |
| 57 | + delete tstream; |
| 58 | + delete lxr; |
| 59 | + delete istream; |
| 60 | +} |
| 61 | + |
| 62 | +void test2(const char* input) |
| 63 | +{ |
| 64 | + a007LexerTraits::InputStreamType* istream = new a007LexerTraits::InputStreamType((const ANTLR_UINT8 *)input |
| 65 | + , antlr3::ENC_8BIT |
| 66 | + , strlen(input) |
| 67 | + , (ANTLR_UINT8*)"test2"); |
| 68 | + istream->setUcaseLA(true); |
| 69 | + |
| 70 | + a007Lexer* lxr = new a007Lexer(istream); |
| 71 | + a007LexerTraits::TokenStreamType* tstream = new a007LexerTraits::TokenStreamType(ANTLR_SIZE_HINT, lxr->get_tokSource()); |
| 72 | + a007Parser* psr = new a007Parser(tstream); |
| 73 | + { |
| 74 | + auto r1 = psr->test2(); |
| 75 | + std::cout << r1.tree->toStringTree() << std::endl; |
| 76 | + } |
| 77 | + |
| 78 | + delete psr; |
| 79 | + delete tstream; |
| 80 | + delete lxr; |
| 81 | + delete istream; |
| 82 | +} |
| 83 | + |
| 84 | +void test3(const char* input) |
| 85 | +{ |
| 86 | + a007LexerTraits::InputStreamType* istream = new a007LexerTraits::InputStreamType((const ANTLR_UINT8 *)input |
| 87 | + , antlr3::ENC_8BIT |
| 88 | + , strlen(input) |
| 89 | + , (ANTLR_UINT8*)"test3"); |
| 90 | + istream->setUcaseLA(true); |
| 91 | + |
| 92 | + a007Lexer* lxr = new a007Lexer(istream); |
| 93 | + a007LexerTraits::TokenStreamType* tstream = new a007LexerTraits::TokenStreamType(ANTLR_SIZE_HINT, lxr->get_tokSource()); |
| 94 | + a007Parser* psr = new a007Parser(tstream); |
| 95 | + { |
| 96 | + auto r1 = psr->test3(); |
| 97 | + std::cout << r1.tree->toStringTree() << std::endl; |
| 98 | + } |
| 99 | + |
| 100 | + delete psr; |
| 101 | + delete tstream; |
| 102 | + delete lxr; |
| 103 | + delete istream; |
| 104 | +} |
0 commit comments