1 | //! \file yaogen.cpp |
---|
2 | //! \brief Implementation of the main YAO code generator. |
---|
3 | //! \version 2007/10/01 (yyyy/mm/dd) |
---|
4 | //! \author Luigi Nardi <luiginardi(at)gmail.com> |
---|
5 | // |
---|
6 | // This description is part of YAO, a framework for variational assimilation in |
---|
7 | // numerical models. |
---|
8 | // Copyright (c) 2001-onwards LOCEAN. All rights reserved. |
---|
9 | // |
---|
10 | // This program may be redistributed and/or modified under the terms of the GNU |
---|
11 | // General Public License as published by the Free Software Foundation, either |
---|
12 | // version 2 of the license, or (at your option) any later version. |
---|
13 | // |
---|
14 | // This program is provided AS IS and WITHOUT ANY WARRANTY, including any |
---|
15 | // implied warranty of DESIGN, MERCHANTABILITY or FITNESS FOR A PARTICULAR |
---|
16 | // PURPOSE. |
---|
17 | |
---|
18 | #include <cstring> |
---|
19 | #include <iostream> |
---|
20 | #include "help/FilePath.hpp" |
---|
21 | #include "Translator.hpp" |
---|
22 | #include "help/Display.hpp" |
---|
23 | |
---|
24 | #include <antlr/TokenStreamRecognitionException.hpp> |
---|
25 | |
---|
26 | using namespace antlr; |
---|
27 | using namespace std; |
---|
28 | using namespace yao; |
---|
29 | |
---|
30 | int main(int argc, char* argv[]){ |
---|
31 | // cout << endl << endl << "YAO version " << VERSION << " - " << SYSTEM << " (Copyright (c) 2001-onwards LOCEAN)." << endl; |
---|
32 | |
---|
33 | int exitStatus = EXIT_FAILURE; |
---|
34 | FilePath filename; |
---|
35 | |
---|
36 | try{ |
---|
37 | // Check argument count. |
---|
38 | if(argc <= 1) |
---|
39 | throw runtime_error("no file specified"); |
---|
40 | |
---|
41 | // Check if help menu is required. |
---|
42 | if(strcmp(argv[1], "-h") == 0){ |
---|
43 | Display::displayHelp(); |
---|
44 | exit(EXIT_SUCCESS); |
---|
45 | } |
---|
46 | |
---|
47 | filename = argv[1]; |
---|
48 | if(filename.getExtension().empty()) |
---|
49 | filename += ".d"; |
---|
50 | |
---|
51 | // Initilization of the lexer and lexing (wrapped from the object tokenizer) |
---|
52 | Tokenizer tokenizer(filename); |
---|
53 | // Initialization of the parser and parsing (wrapped from the object tokenizer) |
---|
54 | Translator translator(tokenizer); |
---|
55 | // Code generation of the files Y1ProjectName.h and Y2ProjectName.h |
---|
56 | translator.generateCode(); |
---|
57 | exitStatus = EXIT_SUCCESS; |
---|
58 | //cout << "End application" << endl; |
---|
59 | } |
---|
60 | catch (RecognitionException& e){ |
---|
61 | cerr << "error: " << e.getFilename() << ":" << e.getLine() << ": " << e.getMessage() << endl; |
---|
62 | } |
---|
63 | catch (ANTLRException& e){ |
---|
64 | cerr << "error: " << filename << ": " << e.getMessage() << endl; |
---|
65 | } |
---|
66 | catch (exception& e){ |
---|
67 | cerr << "error: " << e.what() << endl; |
---|
68 | } |
---|
69 | |
---|
70 | return exitStatus; |
---|
71 | } |
---|