source: trunk/yao/share/antlr-2.7.7/examples/cpp/unicode/main.cpp @ 1

Last change on this file since 1 was 1, checked in by lnalod, 15 years ago

Initial import of YAO sources

  • Property svn:eol-style set to native
File size: 1003 bytes
Line 
1#include <iostream>
2#include <fstream>
3#include <exception>
4#include <antlr/ANTLRException.hpp>
5
6#include "L.hpp"
7
8using std::cin;
9using std::cerr;
10using std::endl;
11using std::istream;
12using std::ifstream;
13
14int main(int argc, char **argv)
15{
16        ifstream s;
17
18        if( argc == 1 )
19        {
20                cerr << "Usage: " << argv[0] << "<files>|-" << endl;
21                return 1;
22        }
23
24        try {
25                for( int i = 1; i < argc; i++ )
26                {
27                        istream *in = 0;
28                        if( argv[i][0] == '-' && strlen(argv[i]) == 1 )
29                                in = &cin;
30                        else
31                        {
32                                s.open(argv[i]);
33                                in = &s;
34                        }
35
36                        UnicodeCharBuffer input(*in);
37                        L lexer(input);
38                        lexer.done = false;
39
40                        while ( ! lexer.done )
41                        {
42                                antlr::RefToken t = lexer.nextToken();
43                                std::cout << "Token: " << t->getType() << " '" << t->getText() << "'" << std::endl;
44                        }
45                        s.close();
46                }
47        }
48        catch (antlr::ANTLRException& e) {
49                cerr << "parser exception: " << e.toString() << endl;
50                return 2;
51        }
52        catch (std::exception& e) {
53                cerr << "exception: " << e.what() << endl;
54                return 2;
55        }
56        return 0;
57}
Note: See TracBrowser for help on using the repository browser.