Skip to content

Commit 24575b5

Browse files
committed
Updated the XML part with the latest version of ModelicaXML and FlatModelicaXML
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2377 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent a4ac4c3 commit 24575b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+47960
-0
lines changed

tools/xml/flatmodelicaxml/FlatModelicaLexer.cpp

Lines changed: 1507 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#ifndef INC_FlatModelicaLexer_hpp_
2+
#define INC_FlatModelicaLexer_hpp_
3+
4+
#include <antlr/config.hpp>
5+
/* $ANTLR 2.7.3: "flat_modelica_lexer.g" -> "FlatModelicaLexer.hpp"$ */
6+
#include <antlr/CommonToken.hpp>
7+
#include <antlr/InputBuffer.hpp>
8+
#include <antlr/BitSet.hpp>
9+
#include "FlatModelicaTokenTypes.hpp"
10+
#include <antlr/CharScanner.hpp>
11+
#line 1 "flat_modelica_lexer.g"
12+
13+
#ifdef WIN32
14+
#pragma warning( disable : 4267) // Disable warning messages C4267
15+
#endif
16+
//disable: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
17+
18+
#line 19 "FlatModelicaLexer.hpp"
19+
class CUSTOM_API FlatModelicaLexer : public ANTLR_USE_NAMESPACE(antlr)CharScanner, public FlatModelicaTokenTypes
20+
{
21+
#line 1 "flat_modelica_lexer.g"
22+
#line 23 "FlatModelicaLexer.hpp"
23+
private:
24+
void initLiterals();
25+
public:
26+
bool getCaseSensitiveLiterals() const
27+
{
28+
return true;
29+
}
30+
public:
31+
FlatModelicaLexer(ANTLR_USE_NAMESPACE(std)istream& in);
32+
FlatModelicaLexer(ANTLR_USE_NAMESPACE(antlr)InputBuffer& ib);
33+
FlatModelicaLexer(const ANTLR_USE_NAMESPACE(antlr)LexerSharedInputState& state);
34+
ANTLR_USE_NAMESPACE(antlr)RefToken nextToken();
35+
public: void mLPAR(bool _createToken);
36+
public: void mRPAR(bool _createToken);
37+
public: void mLBRACK(bool _createToken);
38+
public: void mRBRACK(bool _createToken);
39+
public: void mLBRACE(bool _createToken);
40+
public: void mRBRACE(bool _createToken);
41+
public: void mEQUALS(bool _createToken);
42+
public: void mASSIGN(bool _createToken);
43+
public: void mPLUS(bool _createToken);
44+
public: void mMINUS(bool _createToken);
45+
public: void mSTAR(bool _createToken);
46+
public: void mSLASH(bool _createToken);
47+
public: void mDOT(bool _createToken);
48+
public: void mCOMMA(bool _createToken);
49+
public: void mLESS(bool _createToken);
50+
public: void mLESSEQ(bool _createToken);
51+
public: void mGREATER(bool _createToken);
52+
public: void mGREATEREQ(bool _createToken);
53+
public: void mEQEQ(bool _createToken);
54+
public: void mLESSGT(bool _createToken);
55+
public: void mCOLON(bool _createToken);
56+
public: void mSEMICOLON(bool _createToken);
57+
public: void mPOWER(bool _createToken);
58+
public: void mWS(bool _createToken);
59+
public: void mML_COMMENT(bool _createToken);
60+
protected: void mML_COMMENT_CHAR(bool _createToken);
61+
public: void mSL_COMMENT(bool _createToken);
62+
public: void mIDENT(bool _createToken);
63+
protected: void mNONDIGIT(bool _createToken);
64+
protected: void mDIGIT(bool _createToken);
65+
protected: void mEXPONENT(bool _createToken);
66+
public: void mUNSIGNED_INTEGER(bool _createToken);
67+
public: void mSTRING(bool _createToken);
68+
protected: void mSCHAR(bool _createToken);
69+
protected: void mSESCAPE(bool _createToken);
70+
protected: void mESC(bool _createToken);
71+
private:
72+
73+
static const unsigned long _tokenSet_0_data_[];
74+
static const ANTLR_USE_NAMESPACE(antlr)BitSet _tokenSet_0;
75+
static const unsigned long _tokenSet_1_data_[];
76+
static const ANTLR_USE_NAMESPACE(antlr)BitSet _tokenSet_1;
77+
static const unsigned long _tokenSet_2_data_[];
78+
static const ANTLR_USE_NAMESPACE(antlr)BitSet _tokenSet_2;
79+
static const unsigned long _tokenSet_3_data_[];
80+
static const ANTLR_USE_NAMESPACE(antlr)BitSet _tokenSet_3;
81+
static const unsigned long _tokenSet_4_data_[];
82+
static const ANTLR_USE_NAMESPACE(antlr)BitSet _tokenSet_4;
83+
static const unsigned long _tokenSet_5_data_[];
84+
static const ANTLR_USE_NAMESPACE(antlr)BitSet _tokenSet_5;
85+
};
86+
87+
#endif /*INC_FlatModelicaLexer_hpp_*/
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/* Copyright (c)2000 Linköping University Sweden, All Rights Reserved
2+
/* Programming Environments Laboratory
3+
*******************************************************************************
4+
File : "FlatModelicaXML.cpp"
5+
Author : Adrian Pop 2005-05-26
6+
Description : Antlr Parser caller and XML serializer for Flat Modelica
7+
-------------------------------------------------------------------------------
8+
Source:
9+
Revision:
10+
Author: Adrian Pop
11+
Date: 2004-05-26
12+
*******************************************************************************
13+
*/
14+
15+
16+
//** HEADERS ************************************************************
17+
18+
// standard include files
19+
#include <iostream>
20+
#include <sstream>
21+
#include <cstdlib>
22+
#include <fstream>
23+
24+
// ModelicaParser related include file
25+
// the following header files are automatically generated by the antlr parser (Do not modify them)
26+
#include "Flat_Modelica_Lexer.hpp"
27+
#include "Flat_Modelica_Parser.hpp"
28+
#include "Flat_Modelica_Tree_Parser.hpp"
29+
#include "Flat_Modelica_ParserTokenTypes.hpp"
30+
#include "Flat_Modelica_Tree_ParserTokenTypes.hpp"
31+
#include "parse_tree_dumper.hpp"
32+
33+
// antlr related include files
34+
#include "antlr/AST.hpp"
35+
#include "antlr/CommonAST.hpp"
36+
#include "antlr/ASTFactory.hpp"
37+
#include "MyAST.h"
38+
39+
40+
using namespace std;
41+
42+
//-----------------------------------------------------------------------------
43+
// func : main function for the modelica optimizer
44+
// author : Adrian Pop 2003-10-25
45+
// organization : Linköping University Sweden, Programming Environment Laboratory
46+
//-----------------------------------------------------------------------------
47+
// the function accept as argument a flattened modelica file ad will generate as output the corresponding C files
48+
// for the Modelica Simulator
49+
int main( int argc, char* argv[] )
50+
{
51+
ifstream file;
52+
//ofstream wfile;
53+
54+
// check if the modelica file is present in the argument list
55+
if (argc < 2)
56+
{
57+
cerr << "Incorrect number of arguments\n";
58+
return 1;
59+
}
60+
61+
//open the file passed as an argument
62+
file.open(argv[1]);
63+
64+
//if the file cannot be opened
65+
if (!file)
66+
{
67+
cerr << "Could not open file: " << argv[1] << "\n";
68+
getchar();
69+
return 2;
70+
}
71+
72+
try
73+
{
74+
antlr::ASTFactory my_factory("MyAST", MyAST::factory);
75+
flat_modelica_lexer lexer(file);
76+
lexer.setFilename(argv[1]);
77+
flat_modelica_parser parser(lexer);
78+
parser.initializeASTFactory(my_factory);
79+
parser.setASTFactory(&my_factory);
80+
parser.stored_definition();
81+
//wfile.open("output.txt");
82+
//wfile << parser.getAST()->toStringList() << std::endl;
83+
antlr::RefAST ast = parser.getAST();
84+
//parse_tree_dumper dumper(std::cout);
85+
std::cout << std::flush;
86+
if (ast)
87+
{
88+
//dumper.dump(ast);
89+
flat_modelica_tree_parser walker;
90+
walker.initializeASTFactory(my_factory);
91+
walker.setASTFactory(&my_factory);
92+
std::string xmlFile(argv[1]);
93+
/*
94+
http://www.ida.liu.se/~adrpo/modelica/xml/modelicaxml-v2.dtd
95+
c:\\dev\\src\\modelicaxml\\modelicaxml-v2.dtd
96+
*/
97+
// set the doctype
98+
std::string docType(
99+
(argc > 2)?argv[2]:"http://www.ida.liu.se/~adrpo/modelica/xml/modelicaxml-v2.dtd");
100+
xmlFile += ".xml";
101+
walker.stored_definition(
102+
RefMyAST(ast),
103+
xmlFile,
104+
argv[1],
105+
docType);
106+
}
107+
else
108+
{
109+
//wfile << std::endl << "Parse error: <NULL> AST\n";
110+
std::cerr << std::endl << "Parse error: <NULL> AST\n";
111+
}
112+
}
113+
catch(antlr::ANTLRException& e)
114+
{
115+
std::cerr << "Parser/Lexer/Walker Exception: " << e.toString() << std::endl;
116+
file.close();
117+
std::cerr << "ERROR! File:" << argv[1] << std::endl;
118+
getchar();
119+
return EXIT_FAILURE;
120+
}
121+
catch(std::exception& e)
122+
{
123+
std::cerr << "Exception: " << e.what() << std::endl;
124+
file.close();
125+
std::cerr << "ERROR! File:" << argv[1] << std::endl;
126+
getchar();
127+
return EXIT_FAILURE;
128+
}
129+
130+
file.close();
131+
std::cout << "SUCCESS! File:" << argv[1] << std::endl;
132+
//wfile << std::endl << "SUCCESS! File:" << argv[1] << std::endl;
133+
//wfile.close();
134+
return EXIT_SUCCESS;
135+
}

0 commit comments

Comments
 (0)