]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/demo/Mac/antlr4-cpp-demo/main.cpp
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / demo / Mac / antlr4-cpp-demo / main.cpp
1 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2  * Use of this file is governed by the BSD 3-clause license that
3  * can be found in the LICENSE.txt file in the project root.
4  */
5
6 //
7 //  main.cpp
8 //  antlr4-cpp-demo
9 //
10 //  Created by Mike Lischke on 13.03.16.
11 //
12
13 #include <iostream>
14
15 #include "antlr4-runtime.h"
16 #include "TLexer.h"
17 #include "TParser.h"
18
19 using namespace antlrcpptest;
20 using namespace antlr4;
21
22 int main(int , const char **) {
23   ANTLRInputStream input(u8"๐Ÿด = ๐Ÿ + \"๐Ÿ˜Ž\";(((x * ฯ€))) * ยต + โˆฐ; a + (x * (y ? 0 : 1) + z);");
24   TLexer lexer(&input);
25   CommonTokenStream tokens(&lexer);
26
27   tokens.fill();
28   for (auto token : tokens.getTokens()) {
29     std::cout << token->toString() << std::endl;
30   }
31
32   TParser parser(&tokens);
33   tree::ParseTree *tree = parser.main();
34
35   std::cout << tree->toStringTree(&parser) << std::endl;
36
37   return 0;
38 }