Institutionen för datavetenskap Department of Computer and Information Science

Size: px
Start display at page:

Download "Institutionen för datavetenskap Department of Computer and Information Science"

Transcription

1 Institutionen för datavetenskap Department of Computer and Information Science Master Thesis A Template-Based Java Code Generator for OpenModelica and MetaModelica By Manokar Munisamy LIU-IDA/LITH-EX-A--14/022 SE

2 Linköping University Department of Computer and Information Science Master Thesis A Template-Based Java Code Generator for OpenModelica and MetaModelica By Manokar Munisamy LIU-IDA/LITH-EX-A--14/022 SE Supervisor: Lena Buffoni (fd Olena Rogovchenko) Department of Computer and Information Science Examiner: Peter Fritzson Department of Computer and Information Science

3 Abstract The current OpenModelica Complier (OMC) translates Modelica models into executable C- code through several stages. The Code Generator is the final stage of the compiler which generates target C-code from the optimized sorted equations. Recently, the Code Generator in OMC has been rewritten using the OpenModelica text template language. This gives a more concise and easier to understand code generator. Modeling and simulation is becoming increasingly used in several application areas. There is demand for the OpenModelica Complier (OMC) to generate code in languages like C#, CSharp, XML, JAVA and so on. In this thesis work, we implement a Java code generator to translate the internal equation-based models in OpenModelica and its extension MetaModelica into a Java code representation. To create the Java code generator we used the OpenModelica text template language, also called Susan. This work is an important step on the way to finalize a full version of a Java Code Generator for the OpenModelica Complier (OMC).

4 Acknowledgments I take this opportunity to thank my examiner Prof. Peter Fritzson and my supervisor Dr. Olena Rogovchenko for this thesis opportunity, and for guidance. I also thank my technical supervisor Martin Sjölund and give special thanks to Prof. Hans Georg Schaathun from høgskolen i Ålesund (Aalesund University College) for his continuous support through skype meetings. Finally I thank my friends and family for their support. 4

5 Contents Contents... 5 Chapter Introduction Motivation Problem Statement Goals Methodology Intended Readers Thesis Outline... 9 Chapter Background Modelica and OpenModelica OpenModelica Compiler Phases and Modules The OpenModelica Compiler Phases The OpenModelica Compiler Modules MetaModelica Numerical Integration Introduction to Numerical Integration Euler Integration Event Handling Events Run-time Algorithm The Susan Template Language Chapter Design and Implementation Java Code Generation Root Template Java Specific File Template simulationfileheader Template modelclassname Template addglobalinitialization Template

6 3.1.6 modelclassconstructortemplate functionboundparameters Template functionode Template functiondae Template functions Template mainfunction Template daeexp Template Java runtime system SimModel SimData EulerSolver Chapter Testing Modelica Test Models Verification Test Performance Test Improvements from previous version Chapter Conclusion and Future Work Conclusion Future Work User Guide References Appendix A Sample Results B Simulation Time C Implementation code

7 Chapter 1 Introduction In this chapter, we provide an overview and motivation for this thesis work. We also explain the methodology which we use to achieve our goals. In the next section, we have stated the goals and problem statement in this chapter. Finally, we present the outline of this thesis work. 1.1 Motivation In modern technology, modeling and simulation plays a vital role in many industries. Industries need a multi domain modeling and simulation language and tool for their application development such as: mechanical, robotics, automotive, aerospace, electrical, hydraulic, control subsystems, process oriented applications and many more. Modelica is a non-proprietary, object oriented, mathematical and equation based language. The Modelica language is used for modeling and simulating the above mentioned applications/models. OpenModelica is an open-source Modelica-based modeling and simulation environment intended for industrial and academic usage. OpenModelica is growing fast and contains different subsystems such as OMC, OMShell, OMNotebook, OMEdit, OMWeb, OMOptim, MDT, ModelicaML, and OMPython. The idea of creating this thesis work came from some users of OpenModelica, including University of Ålesund, who are using the Java platform for software development and simulation. They have a need for a simulator which is running as a Java application. Therefore there is a need for OpenModelica to be able to generate Java code as an alternative to C code. 1.2 Problem Statement The OpenModelica Compiler, code generator has recently (two years ago) been rewritten using the OpenModelica text template based language, Susan [2.6]. A previous master thesis project developed a subset text template based code generator. This work extends that to cover a larger part of the language, to create a Java Run-time that supports event handling, and to also support code generation for MetaModelica to Java. Thus the first problem is that, 7

8 Problem 1: How to implement a template based Java code generator for OpenModelica and MetaModelica? After Java code is generated, we need a runtime system to simulate the model. Currently there exists a C runtime system but now we also need a Java runtime system to simulate. Thus the second problem is that, 1.3 Goals Problem 2: How to implement a Java runtime system to simulate Java coded models? The main goals of this thesis work are the following: To further develop a template based Java code generator for OpenModelica Complier OMC. o further develop a Java Runtime System to simulate the models. To perform the example test cases that demonstrate the possibility of OMC to generate Java code for Modelica models, and track the performance with other the programming language. 1.4 Methodology The methodology used for the development of thetemplate Based Java code generator and Java runtime system for OpenModelica is based upon: Literature Study A literature study is the basic for the initiation of this thesis work. The OpenModelica project was studied as along with already existing code generation thesis works made for different languages such as C, C++, C# and XML code generation, as well as previous master thesis with limited code generation from Modelica to Java in OpenModelica. Also, some publications and documentations on OpenModelica were studied which are related to this thesis work. Taking part in Intense Modelica Course and OpenModelica workshop helped to a large extent to learn more about the Modelica language. Implementation The implementation leads to obtain a deeper understanding about the problems and its proposed solutions. The Java code generator and Java runtime system were developed using Susan template language and Java respectively. 1.5 Intended Readers The intended readers of this thesis work are people with general idea in Modelica language, Susan template language, OpenModelica modeling and simulation environment. However, interested readers with basic knowledge of compiler construction and programming can understand as well. 8

9 1.6 Thesis Outline The rest of this thesis is organized as follows. Chapter 2: Background studies on the Modelica, OpenModelica, MetaModelica, complier phases and modules, numerical integration for solver and Susan template language. Chapter 3: Explains the design and implementation of Template Based Java Code Generator and Java Runtime System for OpenModelica/MetaModelica. Chapter 4: Demonstrates the different test case and simulation to show the performance of the implementation. Chapter 5: Concludes the thesis work and discussion of possible future work. 9

10 10

11 Chapter 2 Background In this chapter, some theoretical background and technology needed for the implementation is described. Initially, an overview of Modelica and OpenModelica for modeling and simulation environment is given. In the section 2.2, an introduction to compiler construction and its phases is described along with the modules of OMC. In the next section, the Run-time algorithms for numerical integration and event handling are discussed. Finally, the Susan template language is described which is used for the implementation of this thesis work. 2.1 Modelica and OpenModelica Modeling and simulation plays a vital role in many industries, because modeling and simulation gives an overview of the actual system before it is implemented in the real world. There are many modeling and simulation tools are available. In this thesis work, we focus in OpenModelica and its extension MetaModelica. Modelica is an object oriented and equation based language for modeling and simulation of multi domain such as mechanical, electrical, hydraulic, control subsystems etc. The Modelica Association is a non-profit organization which supports the development of the open standard Modelica and the open source Modelica Standard Library. The OpenModelica is an open source project for Modelica based modeling, compilation and simulation environment. The major development of OpenModelica is done in Linköping University, PELAB. OpenModelica is supported by non-profit organization, Open Source Modelica Consortium (OSMC). There are many development is in under construction, recently new version of OpenModelica1.9.0 beta 4 has been released including the different tools as shown below in the figure

12 Figure 2.1: The overall architecture of the OpenModelica environment An OpenModelica Compiler (OMC) The OMC translates Modelica source code to an executable C code for simulation. An interactive session handler (OMShell) An OMShell provides a command interface to OMC. The OpenModelica Notebook (OMNotebook) OMNotebook gives a tutorial for Modelica. In addition, Modelica models can be written and simulated on it. The OpenModelica Development Environment (OMDev) The OMDev is a tool for building OMC. A Modelica eclipse plugin (MDT-Modelica Development Tooling) MDT is used for Modelica development, code browsing, and simulation. Modelica Debugger The Modelica debugger used for debugging an extended algorithm subset of Modelica by using eclipse for displaying and positioning. Graphical model editor The OpenModelica Connection Editor (OMEdit) is used for graphical model editing, plotting and browsing of the Modelica standard library. 2.2 OpenModelica Compiler Phases and Modules The OpenModelica Compiler Phases A Modelica Compiler - The OMC translates Modelica source code to executable C code for simulation by several phases. In this section, we give a short description for every phase with the help of OpenModelica compiler phases shown in figure below. 12

13 Figure 2.2.1: The OpenModelica compiler translation phases Phases of compiler are as follows: 1. The first phase of the compiler is Scanner (input: symbols, output: tokens), which produce tokens from the Modelica model symbols. 2. The second phase of the compiler is Parser (input: tokens, output: abstract syntax tree), which translates the tokens to flattened model with list of variables, equation, function. 3. The Analyzer (input: abstract syntax tree, output: error messages, abstract syntax tree), which is used for type checking, import statements, handling of inheritance, modifications and all other object oriented operations are also performed in this phase. 4. Optimization (input: abstract syntax tree, output: (optimized) abstract syntax tree), which gives the Optimized sorted equation. 5. Code Generator is an important phase of the compiler (input: abstract syntax tree, output: executable code). Code generation generates the final code (this is typically architecture specific, one has to consider memory issues, etc.) 6. In the last phase of OMC, the code generator generates C code which is then pass to a C compiler to produce executable code for simulation. 13

14 Interested readers to know the detailed compiler phases are encouraged to go through the Compliers Principles, Techniques, & Tools book[3] The OpenModelica Compiler Modules The OMC has around 40 modules. The brief descriptions of each module can be found in the OpenModelica system documentation and figure2.2.2a shown below for a quick reference. Figure 2.2.2a: Module connections and data flows in the OMC In this section, we will describe only the most important modules of OMC and its short description, see also figure 2.2.2b below. 1. The parser generates Abstract Syntax (Absyn) which is then converted into a simplified intermediate form (SCode). 2. The code instantiation module (Inst) calls Lookup to find a name in an environment. It also generates the Differential Algebraic Equation (DAE) representation which is simplified by DAELow. 3. The Ceval module performs compile time or interactive expression evaluation and returns values. 4. The static module performs static semantic and type checking. 5. SimCode is the data structure for representing solved equation code which then can be used to generate different target code in code generation phase. 14

15 2.3 MetaModelica Figure 2.2.2b: The OpenModelica compiler most important modules MetaModelica is a unified equation-based modeling language specifically designed for OMC development. MetaModelica is an extended subset of Modelica used for the development of OMC. There are some extended features such as local equations, pattern equations, match expressions and high level data structures are matchcontinue, uniontype, list and the option type. The MetaModelica uniontype construct used to specify the type of each node in the AST. It declares one or more record members. The structure of uniontype may be recursive (i.e., the records are allowed to contain uniontype members). See the listing 2.3 for an example on how to declare an expression uniontype of six record types. uniontype Exp record INT Integer value; end INT; record ADD Exp lhs; Exp rhs; end ADD; record SUB Exp lhs; Exp rhs; end SUB; record MUL Exp lhs; Exp rhs; end MUL; record DIV Exp lhs; Exp rhs; end DIV; record NEG Exp exp1; end NEG; end Exp; Listing 2.3: Exp Abstract syntax definition using MetaModelica Uniontype constructs The AST representation of the expression 10+3*8 by using the Exp abstract syntax definition is shown below in the Figure

16 ADD INT MUL 10 INT INT Figure 2.3: AST of 10+8*3 in the language Exp See the listing 2.3.b for an example on how to declare a match constructs in MetaModelica. function eval input Exp in_exp; output Real out_real; algorithm out_real := match in_exp local Real v1,v2,v3; Exp e1,e2; case RCONST(v1) then v1; case ADD(e1,e2) equation v1 = eval(e1); v2 = eval(e2); v3 = v1 + v2; then v3; case SUB(e1,e2) equation v1 = eval(e1); v2 = eval(e2); v3 = v1 - v2; then v3; case MUL(e1,e2) equation v1 = eval(e1); v2 = eval(e2); v3 = v1 * v2;then v3; case DIV(e1,e2) equation v1 = eval(e1); v2 = eval(e2); v3 = v1 / v2; then v3; case NEG(e1) equation v1 = eval(e1); v2 = -v1; then v2; end match; end eval; Listing 2.3.b: MetaModelica match constructs 2.4 Numerical Integration In this section, we explain the numerical integration procedure and methods used in this thesis work to solve the ODE equations in solver Introduction to Numerical Integration One of the inputs to the final code generation step, with the limited set of models used in this thesis, is a set of explicit ODEs on the form: with initial conditions: x' (t )= f ( x(t ),u(t ),t ). (2.1) x(t= t 0 )= x 0.. (2.2)

17 In equation (2.1) x is the state vector, u is the input vector, and t represents time. We are not considering any input to our Modelica model while simulation so we may skip the u(t) part from equation (2.2) and thus form a new equation (2.3). The new equation can be written as: x' (t )= f ( x(t ),t ).. (2.3) Our task is to calculate the state vector x and derivative x' of these states of the specified time t. We can get the value of state vector x by analytically calculating them one by one but is not possible in all cases specially if there are many time stamps and multiple state variables. The alternative is to use the numerical integration methods. By using the numerical integration methods, we can get the approximated values. Although it is not always possible to get the accurate results but approximated values very close to the accurate ones. The approximated values can be calculated at any given point using Taylor-Series expansion for every element of xi: x i (t +h)= x i (t )+ dx i (t ) dt By plugging in equation (2.3) we get:.h+ d2 x i (t ). h2 dt 2 2! (2.4) x i (t +h)= x i (t )+f i (t ).h+ df i(t ). h2 dt 2! (2.5) Euler Integration Euler integration is the first-order numerical procedure for solving ODEs. The Euler integration algorithm is formed by taking only the linear part from the Taylor Series equation (2.5), such as: xi(t*+ h) xi(t*) + x'i(t*). h.(2.6) We use the approximation sign here instead of the equal sign, this is because we are just taking the linear part and ignoring the rest of the Taylor equation of (2.5). Now the above equation (2.6) scheme is very simple comparatively to Taylor series equation (2.5) because it doesn't hold any higher-order derivatives. We call this integration scheme Forward Euler algorithm since this numerical integration algorithm depends only on the past values of states and state derivatives unlike Backward Euler 3 [3]. Recall equation (2.2), with initial conditions, x(t = t0) = x0, we can write the rest of steps as follows: step 1a: x'(t0) = f(x(t0); t0) step 1b: x(t0 + h) = x(t0) + h. x'(t0) step 2a: x' (t0 + h) = f(x(t0 + h); t0 + h) step 2b: x(t0 + 2h) = x(t0 + h) + h. x'(t0 + h) 17

18 step 3a: x' (t0+ 2h) = f(x(t0 + 2h); t0 + 2h) step 3b: x(t0 + 3h) = x(t0 + 2h) + h. x'(t0 + 2h) x(t) x' Actual Value Approximated Value time t t+h Figure 2.4: Numerical integration using the Forward Euler method. Backward Euler integration scheme depends on past as well as current values of variables. *Note this integration is not discussed in this thesis. 2.5 Event Handling In this section, we address about events and how we handle events in run-time system Events An event (or discrete changes) is simply something that happens. Events are associated with a point in time, state and conditional equation. The An Event in Modelica is something that happens and has the following four properties: taken from [2 ] A point in time that is instantaneous, i.e., has zero duration. An event condition that switches from false to true for the event to happen. A set of variables that are associated with the event, i.e., are referenced or explicitly changed by equations associated with the event. Some behavior associated with the event, expressed as conditional equations that become active or are deactivated at the event. Instantaneous equations are special case of conditional equations that are active only at events. The short definitions of different events are given below: Timed event: An event is triggered by time and the corresponding event-action takes place. An example is shown below, when time >=10.0 then event-action1; end when; State event: An event takes place in a particular state that triggers an action. Conditional Event: An event takes place after satisfying a condition which triggers an action. An example is shown below, when event-conditions then 18

19 event-action1; event-action2; end when; Run-time Algorithm The following flowchart is shown in the figure 2.5 gives an overview of how an event is handled in the run time system. The each and every step of the flowchart is described below. First of all the simulation must be initialized consistently. By use of the initial conditions the initial values for the entire system can be determined. This will also execute all initial events at time. After the initialization the main simulation loop starts with the continuous integration step that calculates the states and state derivatives with its size value. With the new values of states and state derivatives, the functions Solver and CSVBuilder can be evaluated. Thus, the entire continuous system is determined. The continuous integration step is accepted if no event has occurred then the values can be saved and the next step can be performed. If an event has occurred then the value of condition changes, an event occurred within the interval and. Then the exact time has to be detected. The continuous part is evaluated at the time just before the event and all values are saved to provide them to the pre() operator. Then the entire system is evaluated by the functions again. At this point the event is handled and the further events are handling by loop. The main simulation loop will repeat until it reaches the end time. This helps us to get the simulation time for Run-time system. 19

20 Figure 2.5: Schematic Flowchart for Run-time System. 20

21 2.6 The Susan Template Language In this section, we explain the Susan template language which is used in implementation of Java code generator. Susan is a functional, strongly typed, expression oriented template language which is specifically designed for OMC with the following main advantages are: Increases readability Compiled to reach maximum performance Provides a full vehicle for different target code generation such as C++, Java, C# etc... Susan template expressions can consists of conditional expressions, match-expressions, function calls, iterator expressions, and etc. For more expressions and its complete description refer the Susan template guide. The match expression in the template language is used for distinction of AST structure nodes declared in MetaModelica union types. See the listing 2.6 for an example of how pattern matching against a tree structure of figure 2.6. ADD INT MUL 10 INT INT Figure 2.6: AST of 10+8*3 in the language Exp template exp(exp inexp) match inexp case INT( ) then value case ADD( ) then '<%exp(lhs)%> + <%exp(rhs)%>' case SUB( ) then '<%exp(lhs)%> - <%exp(rhs)%>' case MULT( ) then '<%exp(lhs)%> * <%exp(rhs)%>' case DIV( ) then '<%exp(lhs)%> / <%exp(rhs)%>' case NEG( ) then '- <%exp(exp1)%> ' end exp; Listing 2.6: Template exp - Pattern matching example The template function exp is recursive. The scope of the INT constructor is automatically opened by using INT( ) pattern to make its field (i.e., value) available, and the ADD, SUB, MUL, DIV and NEG constructors are opened automatically by using the ADD( ), SUB( ),

22 MUL( ), DIV( ) and NEG( ) pattern respectively. 22

23 Chapter 3 Design and Implementation This chapter describes the design and implementation of this thesis work. Initially, we present the process of Java code generator design and implementation in OMC. Secondly, we present the process of Java runtime system design and implementation for simulation. 3.1 Java Code Generation To design a Java code generator with the basic block diagram as shown in Figure 3.1a. Java code generator takes the input as Modelica model and process in the generator to produce an output as Java code corresponding to the Modelica model. Modelica Model (testmodel.mo) Input Output Figure 3.1a: Block diagram for Java code generator Code generator generates the Java code from the modelica model though OMC. The block diagram for OpenModelica Compiler for Java Code Generation is shown in the figure 3.1b. below. Code generator is depends directly on the SimCode s solved equations (SimCodeTV). So, the SimCodeTV module is important to understand, SimCodeTV is data structure for solved equations. SimCodeTV contains many data structure representation, but in this section we describe only some data structure. Modelica Model Java Code Generator Java Coded Model (testmodel.java) OMC Front End DAELow SimCodeTV Code Generator Solved Equations Java Code Simulation Figure 3.1b: Block diagram for OpenModelica Compiler for Java Code Generation 23

24 Java code generation is implemented by passing the correct data structure into SimCodeTV data structure as function template in Susan template language. The main functions of Java code generation templates are described in the following sections Root Template Root template is top level of code generation, it generates java file which is also a target file can be used for simulation in Java Runtime System. It also consists of main function which is simulationfile( as shown below in the listing template translatemodel(simcode "Generates Java code and Makefile for compiling and running a simulation of a Modelica model." match simcode case SIMCODE(modelInfo=modelInfo as MODELINFO( )) then let()= textfile(simulationfile(, '<%filenameprefix%>.java') "" //empty result for true case //this top-level template always returns an empty result //since generated texts are written to files directly end translatemodel; Listing 3.1.1: Root template for Java Code generation Java Specific File Template In this section, we are going to elaborate more on the main funtion simulationfile(. This main template function consists of set of templates which is used to generate a Java file as complete Java executable file. The file consists of necessary packages, class declaration, variable declarations, constructor, functions, external functions and main class declaration. The main template simulationfile( is defined as shown below template in the simulationfile(simcode listing "Generates code for main Java file for simulation target." match simcode case SIMCODE(modelInfo = MODELINFO( )) then <%simulationfileheader(%> <%modelclassname(%> <%addglobalinitialization(modelinfo, %> <%modelclassconstructor(%> <%functioninput(modelinfo, %> <%functionoutput(modelinfo, %> <%functionboundparameters(parameterequations, %> <%functionode(odeequations, %> <%functiondae(allequations, whenclauses, relations, %> <%functions(modelinfo.functions, recorddecls, %> <%mainfunction(%> end simulationfile; 24

25 Listing 3.1.2: Main temaple for Java specific file in Java Code generation simulationfileheader Template This Java code generation template is responsible for importing the necessary packages, which are used in the Java file, as header for the Java file. The header template is shown below in the listing , and an example is shown in the Listing 3.1.4a. template simulationfileheader(simcode "Generates header part of simulation file." match simcode case SIMCODE(modelInfo=MODELINFO( ), extobjinfo=extobjinfo( )) then package CodegenJava; // solver package name import java.io.ioexception; import java.math.*; import java.lang.thread.state; import java.util.vector; end simulationfileheader; Listing 3.1.3: simulationfileheader template for Java Code generation modelclassname Template This Java code generation template corresponds to the model class declaration and initializing Data object with necessary parameters. In this model class declaration template, declares class name as model name, number of states, output file name and initializing a new SimData as data object. As shown below in the listing template modelclassname(simcode "Generates model class name of simulation file." match simcode case SIMCODE(modelInfo=MODELINFO(varInfo = vi as VARINFO( )), extobjinfo=extobjinfo( )) then let noofstates = if vi.numalgvars then vi.numalgvars else vi.numstatevars /* Simulation code for <%dotpath(modelinfo.name)%> generated by the OpenModelica Compiler public class <%dotpath(modelinfo.name)%> extends SuperModel // name of the given model static int n= <%noofstates%>; // n --> number of states static String filename = "<%dotpath(modelinfo.name)%>_result.txt"; /* Simulation output file */ public static SimData localdata = new SimData(n, 0, 0); /* Initializing a Data Object*/ end modelclassname; Listing 3.1.4: modelclassname template for Java Code generation Example 1: Representation of simulationfileheader and modelclassname declaration are shown in the listing 3.1.4b., for the below model is shown in the listing 3.1.4a. In the below model AddReal.mo, consists of two algebraic parameters and an algebraic 25

26 variables. It also consists of an ODEs equation with an external function called addreal1_. model AddReal1 parameter Real a=2.3; parameter Real b=4.5; Real c; equation c = addreal1_(a, b); end AddReal1; Listing 3.1.4a. Model AddReal1.mo package CodegenJava; // solver package name import java.io.ioexception; import java.math.*; import java.lang.thread.state; import java.util.vector; simulationfileheader /* Simulation code for AddReal1 generated by the OpenModelica Compiler beta4+dev public class AddReal1 extends SuperModel /* name of the given model */ static int n= 1; // n --> number of states static String filename = "AddReal1_result.txt"; /* Simulation output file */ public static SimData localdata = new SimData(n, 0, 0); /* Initializing a Data Object */ Listing 3.1.4b:Example of simulationfileheader and modelclassname declaration addglobalinitialization Template This Java code generation template corresponds to the initialization of global variables and parameters. In this template, we declare algebraic variable parameter lists such as variables, parameters, integer variables, integer parameters, string variables, string parameters and external objects under separate subsections in order to easy understand for the users. The example is shown in the listing 3.1.6a modelclassconstructortemplate This Java code generation template corresponds to the declaration of a constructor. In this template, the generation of class constructor with the state initialization as in model or set as default for the equations. The example is shown in the listing 3.1.6a. Example 2: Representation of global initialization and constructor as shown in the listing 3.1.6a. for the model AddReal.mo mentioned in listing 3.1.4a. /* Algebraic Vars */ double c[] = new double [1]; /* c */ /* Algebraic Parameter */ GlobalInitialization double a = 2.3; /* a */ double b = 4.5; /* b */ public AddReal1() // constructor /* States Initialization Ordinary equations */ localdata.x/*state*/.add(0,0.0); /* $dummy */ /* States Initialization algebraic equations */ localdata.x/*state*/.add(0,0.0); /* c */ 26

27 Listing 3.1.6a:Example of global initialization and constructor for AddReal1.mo functionboundparameters Template In this function BoundParameters, the parameters for state algebraic equations are bounded with corresponding state derivatives. This function is being called in functionode, functiondae to update the algebraic equations. The parameter equations are either SES_SIMPLE_ASSIGN or SES_ALGORITHM defined as shown below in the listing template functionboundparameters(list<simeqsystem> parameterequations, SimCode let &tmp = buffer "" public void BoundParameters() <% parameterequations > saeq as SES_SIMPLE_ASSIGN( ) => equation_(saeq, contextother, simcode, &tmp) ;separator="\n"%> <% parameterequations > eq as SES_ALGORITHM( ) => equation_(eq, contextother, simcode, &tmp) ;separator="\n"%> end functionboundparameters; Listing 3.1.7: functionboundparameters Template for Java code generation Example 3: Representation of bound parameter is shown in the listing 3.1.7b. for the below model EquationFor6.mo. In this model, there are three algebraic variables with three simple algebraic equations respectively and shown in the listing 3.1.7a. class EquationFor6 Real a[3]; equation for i loop a[i] = i; end for; end EquationFor6; // Result: // class EquationFor6 // Real a[1]; // Real a[2]; // Real a[3]; // equation // a[1] = 1.0; // a[2] = 2.0; // a[3] = 3.0; // end EquationFor6; // endresult Flattened Model Listing 3.1.7a: EquationFor6.mo 27

28 public void BoundParameters() localdata.xdot /*statederivative*/.add(0,1.0); //a[1] = 1.0; localdata.xdot /*statederivative*/.add(1,2.0); //a[2] = 2.0; localdata.xdot /*statederivative*/.add(2,3.0); //a[3] = 3.0; Listing 3.1.7b:Example of bound parameter function for EquationFor6.mo functionode Template This Java code generation template is an important function for the simulation. In this template, only the statecontequations implemented. If the model consists of ordinary differential equation then the corresponding equation_ will be executed. The equation_ template is the root template for the entire equations such as SES_SIMPLE_ASSIGN, SES_ARRAY_CALL_ASSIGN, SES_ALGORITHM, SES_WHEN. StatesAssign template is useful for declaring the variables locally. Finally BoundParameters function will be called to update the changes in statederivative if any. The functionode template is defined as shown in the listing and its representation of functionode is shown in the listing 3.1.9a. for BouncingBall.mo model. template functionode(list<list<simeqsystem statecontequations, SimCode match simcode case SIMCODE(modelInfo = MODELINFO(varInfo=VARINFO(numStateVars=numStateVars), vars=simvars( ))) then match modelinfo case MODELINFO(varInfo=VARINFO(numStateVars=numStateVars), vars=simvars( )) then let &tmp = buffer "" public void functionode() <%StatesAssign("states", vars.statevars, ;separator="\n"%> <%StatesAssign("states", vars.algvars, ;separator="\n"%> <%statecontequations > eqs => (eqs > it => equation_(it, contextother, simcode, &tmp) ;separator="\n") ;separator="\n"%> BoundParameters(); end functionode; Listing 3.1.8: functionode Template for Java code generation 28

29 3.1.9 functiondae Template In this template, all type of equations with when-clauses is implemented. For every equation, the corresponding equation_ will be executed. StatesAssign template is useful for declaration of variables locally. The functiondae template is defined as shown in the listing and its representation of functiondae is shown in the listing 3.1.9a. for BouncingBall.mo model. template functiondae(list<simeqsystem> allequationspluswhen, list<simwhenclause> whenclauses, list<zerocrossing> relations, SimCode "Generates function in simulation file." match simcode case SIMCODE(modelInfo = MODELINFO(varInfo=VARINFO(numStateVars=numStateVars), vars=simvars( ))) then match modelinfo case MODELINFO(varInfo=VARINFO(numStateVars=numStateVars), vars=simvars( )) then let &vardecls = buffer "" /*BUFD*/ let &tmp = buffer "" public void functiondae() <%StatesAssign("states", vars.statevars, ;separator="\n"%> <%StatesAssign("states", vars.algvars, ;separator="\n"%> <%allequationspluswhen > eq => equation_(eq, contextsimulationdiscrete, simcode, &tmp) ;separator="\n"%> <%whenclauses > when hasindex i0 => genreinits(when, relations, contextother, &vardecls, ;separator="\n" %> end functiondae; Listing 3.1.9: functiondae Template for Java code generation Example 4: Representation of functionode and functiondae are shown in the listing 3.1.9b. for the BouncingBall.mo as shown in listing 3.1.9a. This model contains two basic equations and when equation as discrete issues suitable for functionode and functiondae. model BouncingBall "The bouncing ball model" constant Real g = 9.81; // Gravitational acceleration parameter Real c = 0.9; // Elasticity constant of ball parameter Real radius = 0.1; // Radius of the ball Real height(start = 1); // height above ground of the ball center Real velocity(start = 0); // Velocity of the ball equation der(height) = velocity; der(velocity) = -g; when height <= radius then reinit(velocity, -c*pre(velocity)); end when; end BouncingBall; Listing 3.1.9a: BouncingBall.mo 29

30 public void functionode() double velocity = localdata.getstate().elementat(0); double height = localdata.getstate().elementat(1); localdata.xdot.add(0,-9.81); localdata.xdot.add(1,velocity); BoundParameters(); public void functiondae() double velocity = localdata.getstate().elementat(0); double height = localdata.getstate().elementat(1); localdata.xdot.add(0,-9.81); localdata.xdot.add(1,velocity); //(height <= radius) "Condition Relation" if (height <= radius) velocity = ((-c) * velocity); Listing 3.1.9b:Example of functionode and functiondae for BouncingBall.mo functions Template In this template, Java code generation for user defined functions and external functions. The root template for this functionjava is functions template which contains the list of functions list<function>. This template is the root for the following templates such as user defined functions, external functions and the record constructor. The functionjava template is defined as shown in the listing template functionjava(function fn, list<recorddeclaration> recorddecls, SimCode "Generates the body for a function." match fn case fn as FUNCTION( ) then regularfunction(fn, case fn as EXTERNAL_FUNCTION( ) then externalfunction(fn, case fn as RECORD_CONSTRUCTOR( ) then recordsjava(recorddecls) end functionjava; Listing : Functions and external functions Template for Java code generation Example 5: Representation of external function is shown in the listing a. for the AddReal.mo model, which consists of a ODEs equation with an external function called addreal1_ in C language. 30

31 function addreal1_ input Real x; input Real y; output Real res; external "C"; end addreal1_; model AddReal1 parameter Real a=2.3; parameter Real b=4.5; Real c; equation c = addreal1_(a, b); end AddReal1; AddReal1.mo public void BoundParameters() /*Function Call*/ localdata.xdot/*statederivative*/.add(0, addreal1 (a,b)); public double addreal1 (double arg_x, double arg_y) /*Function*/ double res; double x = arg_x; double y = arg_y; return res = addreal1_(x,y); /*externalfunction*/ Listing a:Example of external functions for AddReal1.mo mainfunction Template This Java code generation template corresponds to the main class declaration and invokes the EulerSolver with correct parameters. It is shown below in the listing template mainfunction(simcode match simcode case SIMCODE(modelInfo = MODELINFO( )) then public static void main(string[] args) throws IOException <%dotpath(modelinfo.name)%> temp = new <%dotpath(modelinfo.name)%>(); temp.functionode(); /* Invoke the Solver with correct parameters */ EulerSolver.main(localData.stepsize, localdata, temp, filename); end mainfunction; Listing : mainfunction Template for Java code generation Example 9: Representation of main function for the class model is shown in the listing a. for the AddReal1.mo. 31

32 public static void main(string[] args) throws IOException AddReal1 temp = new AddReal1(); temp.functionode(); /* Invoke the Solver with correct parameters */ EulerSolver.main(localData.stepsize, localdata, temp, filename); Listing a:Example of global initialization and constructor for AddReal1.mo daeexp Template This Java code generation template is the root template for all the expressions. The expressions which are used in models are flattened, and those expressions exp match the corresponding case in this template in order to translate into a Java code. This template is defined below in the listing template daeexp(exp exp, Context context, Text &preexp /*BUFP*/, SimCode "Generates code for an expression." match exp case e as ICONST( ) then integer case e as RCONST( ) then real case e as SCONST( ) then daeexpsconst(string, context, &preexp /*BUFC*/, case e as BCONST( ) then if bool then "true" else "false" case e as ENUM_LITERAL( ) then index case e as CREF( ) then daeexpcrefrhs(e, context, &preexp, case e as BINARY( ) then daeexpbinary(e, context, &preexp /*BUFC*/, case e as UNARY( ) then daeexpunary(e, context, &preexp /*BUFC*/, /**************************** Some code removed here *************** *******************************************************************/ case e as CAST( ) then daeexpcast(e, context, &preexp /*BUFC*/, case e as ASUB( ) then daeexpasub(e, context, &preexp /*BUFC*/, case e as TSUB( ) then '<%daeexp(exp, context, &preexp, %>' case e as SIZE( ) then daeexpsize(e, context, &preexp /*BUFC*/, case e as BOX( ) then daeexpbox(e, context, &preexp /*BUFC*/, case e as UNBOX( ) then daeexpunbox(e, context, &preexp /*BUFC*/, case e as SHARED_LITERAL( ) then '_OMC_LIT<%index%>' // META_TUPLE // META_OPTION // METARECORDCALL else error(sourceinfo(), 'Unknown expression: <%ExpressionDump.printExpStr(exp)%>') end daeexp; Listing :daeExp template for Java code generation 32

33 The interested readers who wants to know more about Java code generator implemention are welcome to go though the full implemention code in the section Appendix B Implementation code. 3.2 Java runtime system Java Runtime System takes the java files as input and returns the simulation results to verify the model. Runtime system is needed for every specific programming language. The block diagram for Java Runtime System is shown below in the Figure 3.2a. Java coded model (testmodel.java) Input Java Runtime System Output Simulation test results Figure 3.2a: Block diagram for Java Runtime System The class diagram for Java Runtime System is shown below in the Figure 3.2b, and consists of SimModel Java coded model which is generated from Java code generator. SimData The dynamic data for a simulation at a given time. Solver: Euler's method for numerical integration. Super Model This is the superclass for any model class generated from Modelica. Static Model A ModelicaModel with its static information. Modelica Variable Static information about a single variable in the model. Modelica Equation: A single equation in the Modelica model. Super Model SimModel (testmodel.java) EulerSolver Output SimData testmodel_result.txt Static Model Modelica Equation Figure 3.2b: Class Diagram for Java Runtime System 33 Modelica Variable

34 The description of the class diagram and its implementation is discussed in the following sections SimModel The SimModel is a Java coded model which is generated by using Java code generator for the corresponding modelica model. The Java code model contains the packages, class declaration, variable declaration, class constructor, functions, external functions and the main class declaration. The sample Java code for modelica models are given in the section Appendix A for some test models SimData SimData class is being initialized by the model class declaration object in SimModel. After the initialization, this class is ready for simulation at a given time. This class contains the values of state and state derivative in appropriate format for the solver. The state and state derivatives are initialize as Vector type as Double for better efficiency for runtime system. This class also contains default simulation settings. This SimData implementation is shown in the listing package jrt; import java.util.*; import org.jscience.physics.amount.* ; import javax.measure.quantity.* ; georg@schaathun.net***/ public class SimData double time ; int size; double start; double stepsize; double stop; /* Initialize as Vector type as Double*/ Vector<Double> x = new Vector<Double>(); Vector<Double> xdot = new Vector<Double>() ; public SimData( int xdim, int mdim, int zdim ) // simulation default settings size = xdim; start = 0.0; stepsize = 0.002; stop = 1.0; /*** Advance to next time step, advancing time by dt.***/ public void advance( double dt ) time = time+dt; /*** Get the continuous state vector ***/ public Vector<Double> getstate() return x ; ************************ to be continued 34

35 /*** Get the continuous state derivative vector.***/ public Vector<Double> getder() return xdot ; /*** Get current time.***/ public double gettime() return time ; /*** Set the continuous state vector and update time.***/ public void updatestate( Vector<Double> x ) this.x = x ; Listing 3.2.1:SimData for Java Runtime System EulerSolver Java runtime system uses Euler's numerical integration method. The EulerSolver main class is invoked by SimModel s main-function with necessary parameters. By using those parameters, the solver main class initializes the output result file (testmodel_result.txt). And the values of state and state derivative values by using SimData object. In the main simulation loop, the solver function and CSVBuilder function is being called for simulate the model. The function Solver() takes the appropriate parameters in order to do the numerical integration. There are two main operations in the Solver function, one is the setting of state values in the size loop. And the other is the function-call of functionode (). The state vectors are compute by using below equation: states[i] = states[i] + statesderivatives[i] * (step); This method is implemented and shown in the listing This function helps to get the state and statesderivatives values which is set for the operations and generates the output result file by using CSVBuilder function. Finally there is an small calculation for simulation time for the model. The outline of the code for time stamp is given below. // for time measurement long startsimulationtime = System.currentTimeMillis(); // simulation loop // end simulation time measurements long endsimulationtime = System.currentTimeMillis(); // simulation time calculation System.out.println("Simulation took: " + (endsimulationtime - startsimulationtime)+ " milliseconds.\n"); 35

36 public static void Solver( SimData data,supermodel model, double dt ) throws IOException Vector<Double> x = data.getstate() ; Vector<Double> xdot = data.getder() ; for(int i=0;i<x.size();i++) x.set(i, x.get(i)+ xdot.get(i)*dt); data.advance( dt ) ; model.functionode(); Listing 3.2.2: Solver Function of EulerSolver.Java for Java Runtime System For EulerSolver, SuperModel, StaticModel and it s ModelicaEquation, Modelica Variable. The interested readers who wants to know more about Java Runtime System implemention are welcome to go though the full implemention code in section Appendix C Java Runtime System. 36

37 Chapter 4 Testing In this chapter, we provide different test cases conducted to test the implementation of the thesis work. 4.1 Modelica Test Models We have tested around 250 test case models and all the models were successfully generated. We have taken almost all the types of Modelica language constructs from the OpenModelica test suite. The listing.4 shown below is the general description of subset from the OpenModelica test suite. The detailed listing is shown in Appendix B with the model name and its simulation time for both Java Runtime System and C Runtime System. Test Cases Section 38 algorithmsfunctions Description In this section, we have tested all type of Algorithms and functions such as inline function, function call, function evaluations. 56 array In this section, we have tested for Arrays, array declarations, array operations such as array addition, division, multiplication, subtraction, xpowers, and etc,. 37 built-in-functions In this section, we have generated Java code for the builtin-functions which are Acos, Asin, Atan, Cos, Cosh, Log, Log10, Sqrt, Sin, Sinh, Sign, Tan, Tanh, Transpose, Ceil and etc,. 9 declarations In this section, we perform to test the Constant declarations, DeclarationEquations. 32 Equations In this section, we have tested all type of equations with When, for, if condition equations and some hybrid models which is taken from book [2]. 23 extends In this section, Some extends models like Colors, Moonlanding, Multiplex, StepAdvanced and some more models are tested. 37

38 7 external-functions In this section, we have tested the different external functions for instance AddReal1, ExternalFunctionArray, ExternalFunctionBuiltin, etc. 13 records In this section, we have tested record construct of Modelica language such as RecordAssignment, RecordConstants, and RecordVariability. 30 MetaModelica models In this section, we have tested all type MetaModelica such as List, match, partialfunction and uniontype. Listing 4: Modelica Test Models In this section, we have chosen one model from OpenModelica and another model from MetaModelica to showcase the implementation of Java code generator and its Java Runtime system works fine. The verification and performance test methods are used for testing the generated models Verification Test The following method is used to verify the test results: Generate the simulation output for both C Runtime System (testmodel_res.csv) and Java Runtime System (testmodel_resjava.csv). By executing the file Script.mos, a graph is generated. We can verify the model using this graph. html := diffsimulationresultshtml("/*any one attribute*/ ", "testmodel_res.csv", "testmodel_resjava.csv"); writefile("b.html",html);geterrorstring(); system("cp " + getinstallationdirectorypath() + "/share/doc/omc/testmodels/dygraph-combined.js."); system("chromium-browser b.html &"); Script.mos Performance Test The following method is used for testing the performance of models: By executing the file Script_table.mos, a table is generated. The table consists of model name and its simulation time. The flag +s +simcodetarget=java is used for Java Runtime System. The flag +s +simcodetarget=c is used for C Runtime System. By using these tables, we can compare the simulation time of models for both C Runtime System and Java Runtime System. 38

39 Model 1: BouncingBall.mo: Script_table.mos The BouncingBall model contains the two basic equations of motion relating height and velocity as well as the acceleration caused by the gravitational force. At the bounce instant the velocity is suddenly reversed and slightly decreased, i.e.,veclocity(after bounce) = - c*veclocity(before bounce), which is accomplished by the special reinit synatactic form.. This model suitable for functionode and functiondae. This model is a good example of a hybrid system for which the when-equation is appropriate when modeled. And this discrete model handles the event handling. The full Java code generation of this model is given in section Appendix A. Verification Test: mofiles := "testmodel1.mo", "testmodel2.mo"; system("rm -f log.csv"); writefile(file + ".mos", " loadfile(\""+file+"\"); names:=getclassnames(); name:=names[1]; res:=simulate(name); t:=res.timesimulation; writefile(\"log.txt\",typenamestring(name) + \",\" + String(t) + \"\\n\",append=true); ") for file in mofiles; runscript(file + ".mos") for file in mofiles; Figure 4.1.1a: Graph for BouncingBall.mo 39

40 From this graph, we can conclude that the projection of BouncingBall for both JCG and CCG are almost same. Thus the model is successfully generated using JCG and simulated using JRS. Performance Test: Simulation Time For: C Runtime System Java Runtime System BouncingBall.mo seconds seconds The following model is an example of MetaModelica. Model 2: PartialFn12.mo This model consists of an equation section with the function call of TestFn(x). This function section has another function call. The full Java code generation of this model is given in the section Appendix A. partial function PartFn input Real x; output Real y; end PartFn; function FullFn extends PartFn; input Real extrareal1; input Real extrareal2; algorithm y := x * ((extrareal1 + extrareal2) / 2.0); end FullFn; function CallerFn input Real inreal; input PartFn inpartfn; output Real outreal; algorithm outreal := inpartfn(inreal) * 2.0; end CallerFn; function TestFn input Real inreal; output Real outreal; algorithm outreal := 0; for i in 1:10 loop outreal := outreal + CallerFn(inReal, function FullFn(1.5,7.5)); end for; end TestFn; model PartialFn12 Real x; Real y; equation x = 2.0; y = TestFn(x); end PartialFn12; 40

41 Verification Test: Figure 4.1.1b: Graph for PartialFn12.mo From this graph, we can conclude that the projection of PartialFn for both JCG and CCG are almost same. Thus the model is successfully generated using JCG and simulated using JRS. Performance Test: Simulation Time For: C Runtime System Java Runtime System PartialFn12.mo seconds seconds The following bar chart shows the performance of models in JRS and CRS. The performance of Java Runtime System varies from C Runtime System, because C code executes more directly on the hardware platform whereas Java runs on a JVM. Thus the C compiler compiles the code directly into the machine code while the Java compiler compiles into the byte code which is understandable by JVM. Due to this, Java Runtime System takes more time to execute than C Runtime System. In contrast for some models, Java Runtime System executes in lesser time than C Run time System. 41

42 Figure 4.1: Bar Chart Graph for Equations Subset 4.2 Improvements from previous version When we started this thesis work, we used the thesis report of Template-Based Java Code Generator and Java Runtime System for OpenModelica by Inam Ul Haq. A. As the development of Template-Based Java Code Generator began from his thesis work and listed below the improvements made in this thesis work. Design: We started the design of Java Code Generator and Java Runtime System in order to get better efficiency, and to handle hybrid models such as event handling, external functions, records and MetaModelica constructs. With the help of Prof. Hans Georg Schaathun, the new design of Java Runtime System is created and the detailed class diagram is given in the chapter 3. Implementation: Java Code Generator We have implemented the Java Code Generator for the whole Openmodelica and Metamodelica constructs. The previous version of the Java Code Generator did not cover the following features: Algebraic loops Hybrid Models (Event Handling) Algebraic Arrays External functions Records MetaModelica constructs such as match, List and PartialFunctions. 42

43 But, we have implemented the complete Java Code Generator for the entire Modelica constructs, which are not supported in the previous version. Java Runtime System: The OpenModelica has changed a lot during the period of two years and this leads to some changes in simcodetv. As we mentioned before, simcodetv contains all the data structures which are required for the code generation. So the previous version of Java Code Generator and Java Runtime System does not support the latest version of Openmodelica. Therefore we couldn t use the previous version of Java Runtime System anymore. This leads to the new design of Java Runtime System based on the previous version. We have implemented the complete Java Runtime System which supports the latest version of Java Code Generator. Testing: We have used the script files for verification testing and performance testing, which were not used in the previous version. It is used to test the group of models which makes the testing process easier and efficient. The produced results are very accurate and clear, which is used to compare the simulation time of Java Runtime System with C Runtime System. We have used a total of 250 test cases which are passed successfully, from which we can conclude that the entire Modelica constructs are covered. The previous version does not cover the entire Modelica constructs. 43

44 44

45 Chapter 5 Conclusion and Future Work This chapter concludes the work conducted in this thesis work and discussion the possible directions for future work. 5.1 Conclusion In this thesis work, we have implemented an extended version of the previous subset Java Code Generator by using Susan template based language. We have tested around 250 test cases which cover almost all types of Modelica language constructs. This code generation will be helpful to open the OpenModelica Java code generator to a wide range of users both academic and commercial. 5.2 Future Work The current version of SimCodeTv is unstable and the Java Code Generation is fully dependent on the SimCodeTv. If the SimCodeTv is modified in future then the Java Code Generation will be interrupted. Thus in order to support the Java Code Generation, a stable SimCodeTv can be implemented. Another task for future work is to implement a Click-on button in OMEdit which makes exporting models to an Java format from OpenModelica straightforward for users. To implement a click-on button in OMEdit. 45

46 46

47 User Guide 1. Install OpenModelica Compiler. Follow the instructions found in 2. Compiling a model and generate Java code The following step compiles a model to a Java code generation. - Open the mingw terminal if you are a windows user and normal terminal for linux user - In the terminal window go to the path where your model file found(c:/<%path to.mo file%>). - Go to omc path (<%path to omc%>/omc) and write the flag +s +simcodetarget=java <%your.mo file%>.mo> This is demonstrated in the following example, where +s +simcodetarget=java is the flag specific for Java code generation and Circle.mo is the model name. Once compilation has completed successfully a Java file will have been generated and can be found in the same directory as your model found. 47

Technical Overview of OpenModelica and its Development Environment

Technical Overview of OpenModelica and its Development Environment Technical Overview of OpenModelica and its Development Environment Adrian Pop 2010-02-08 Open Source Modelica Consortium Programming Environment Laboratory Department of Computer and Information Science

More information

OpenModelica Compiler (OMC) Overview

OpenModelica Compiler (OMC) Overview OpenModelica Compiler (OMC) Overview, Adrian Pop, Peter Aronsson OpenModelica Course at INRIA, 2006 06 08 1 OpenModelica Environment Architecture Eclipse Plugin Editor/Browser Emacs Editor/Browser Interactive

More information

OpenModelica Compiler (OMC) Overview

OpenModelica Compiler (OMC) Overview OpenModelica Compiler (OMC) Overview, Adrian Pop, Peter Aronsson OpenModelica Course, 2006 11 06 1 OpenModelica Environment Architecture Eclipse Plugin Editor/Browser Emacs Editor/Browser Interactive session

More information

version 0.3

version 0.3 Modelica Text Template Language Susan Users Guide 2011-04-07 version 0.3 Summary This is the Modelica text template language Susan Users guide. Revisions v0.3 2011-04-07 v6 Pavol Privitzer. Introduced

More information

OpenModelica Environment and Modelica Overview

OpenModelica Environment and Modelica Overview OpenModelica Environment and Modelica Overview, Adrian Pop OpenModelica Course, 2007 03 19 1 OpenModelica Goal: comprehensive modeling and simulation environment for research, teaching, and industrial

More information

Meta-Programming with Modelica. Model Transformations

Meta-Programming with Modelica. Model Transformations Meta-Programming with Modelica for Meta-Modeling Modeling and Model Transformations, Adrian Pop OpenModelica Course, 2007 02 05 1 Extensibility and Modularity of Modeling Tools Modeling and simulation

More information

Modelica Environments and OpenModelica

Modelica Environments and OpenModelica Environments and Open 1 Peter Fritzson Dymola Dynasim (Dassault Systemes) Sweden First tool on the market Main focus on automotive industry www.dynasim.com 2 Peter Fritzson 1 Simulation X ITI Germany Mechatronic

More information

Modelica Meta-Programming and Symbolic Transformations

Modelica Meta-Programming and Symbolic Transformations Modelica Meta-Programming and Symbolic Transformations MetaModelica Programming Guide Version June 2007 Preliminary Incomplete Draft, 2007-06-20 Peter Fritzson 3 4 Peter Fritzson Modelica Meta-Programming

More information

EXPRESSING REQUIREMENTS IN MODELICA

EXPRESSING REQUIREMENTS IN MODELICA EXPRESSING REQUIREMENTS IN MODELICA Lena Buffoni and Peter Fritzson Linköping University SE-581 83 Linköping Sweden ABSTRACT As cyber-physical systems grow increasingly complex, the need for methodologies

More information

OpenModelica Development Environment with Eclipse Integration for Browsing, Modeling, and Debugging

OpenModelica Development Environment with Eclipse Integration for Browsing, Modeling, and Debugging OpenModelica Development Environment with Eclipse Integration for Browsing, Modeling, and Debugging Adrian Pop, Peter Fritzson, Andreas Remar, Elmir Jagudin, David Akhvlediani PELAB Programming Environment

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

Meta-Programming and Language Modeling with MetaModelica 1.0

Meta-Programming and Language Modeling with MetaModelica 1.0 Technical Reports in Computer and Information Science Report number 2011:9 Meta-Programming and Language Modeling with MetaModelica 1.0 by Peter Fritzson and Adrian Pop {peter.fritzson, adrian.pop}@liu.se

More information

Modelica Based Parser Generator with Good Error Handling

Modelica Based Parser Generator with Good Error Handling Arunkumar Palanisamy 1, Adrian Pop 1, Martin Sjölund 1, Peter Fritzson 1 1 PELAB Programming Environment Laboratory Department of Computer and Information Science Linköping University, SE-581 83 Linköping,

More information

Towards Modelica 4 Meta-Programming and Language Modeling with MetaModelica 2.0

Towards Modelica 4 Meta-Programming and Language Modeling with MetaModelica 2.0 Technical Reports in Computer and Information Science Report number 2011:10 Towards Modelica 4 Meta-Programming and Language Modeling with MetaModelica 2.0 by Peter Fritzson, Adrian Pop, and Martin Sjölund

More information

Simulation and Benchmarking of Modelica Models on Multi-core Architectures with Explicit Parallel Algorithmic Language Extensions

Simulation and Benchmarking of Modelica Models on Multi-core Architectures with Explicit Parallel Algorithmic Language Extensions Simulation and Benchmarking of Modelica Models on Multi-core Architectures with Explicit Parallel Algorithmic Language Extensions Afshin Hemmati Moghadam Mahder Gebremedhin Kristian Stavåker Peter Fritzson

More information

Towards Comprehensive Meta-Modeling and Meta-Programming Capabilities in Modelica

Towards Comprehensive Meta-Modeling and Meta-Programming Capabilities in Modelica Towards Comprehensive Meta-Modeling and Meta-Programming Capabilities in Modelica Peter Fritzson, Adrian Pop, Peter Aronsson PELAB Programming Environment Lab, Dept. Computer Science Linköping University,

More information

Institutionen för datavetenskap Department of Computer and Information Science

Institutionen för datavetenskap Department of Computer and Information Science Institutionen för datavetenskap Department of Computer and Information Science Final thesis K Shortest Path Implementation by RadhaKrishna Nagubadi LIU-IDA/LITH-EX-A--13/41--SE 213-6-27 Linköpings universitet

More information

Comp 311: Sample Midterm Examination

Comp 311: Sample Midterm Examination Comp 311: Sample Midterm Examination October 29, 2007 Name: Id #: Instructions 1. The examination is closed book. If you forget the name for a Scheme operation, make up a name for it and write a brief

More information

A Portable Debugger for Algorithmic Modelica Code

A Portable Debugger for Algorithmic Modelica Code A Portable Debugger for Algorithmic Modelica Code Adrian Pop, Peter Fritzson PELAB Programming Environment Lab, Dept. Computer Science Linköping University, S-581 83 Linköping, Sweden {adrpo, petfr}@ida.liu.se

More information

Technical Overview of OpenModelica and its Development Environment

Technical Overview of OpenModelica and its Development Environment Technical Overview of OpenModelica and its Development Environment Adrian Pop 2017-02-06 Open Source Modelica Consortium Programming Environment Laboratory Department of Computer and Information Science

More information

CSCI 171 Chapter Outlines

CSCI 171 Chapter Outlines Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures

More information

CS 360 Programming Languages Interpreters

CS 360 Programming Languages Interpreters CS 360 Programming Languages Interpreters Implementing PLs Most of the course is learning fundamental concepts for using and understanding PLs. Syntax vs. semantics vs. idioms. Powerful constructs like

More information

The return Statement

The return Statement The return Statement The return statement is the end point of the method. A callee is a method invoked by a caller. The callee returns to the caller if the callee completes all the statements (w/o a return

More information

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras Module No. #01 Lecture No. #1.1 Introduction to MATLAB programming

More information

Model-Based Dynamic Optimization with OpenModelica and CasADi

Model-Based Dynamic Optimization with OpenModelica and CasADi Model-Based Dynamic Optimization with OpenModelica and CasADi Alachew Shitahun PELAB Programming Environment Lab, Dept. Computer Science Linköping University, SE-581 83 Linköping, Sweden Vitalij Ruge Mathematics

More information

Technical Overview of OpenModelica and its Development Environment

Technical Overview of OpenModelica and its Development Environment Technical Overview of OpenModelica and its Development Environment Adrian Pop 2012-02-06 Open Source Modelica Consortium Programming Environment Laboratory Department of Computer and Information Science

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

Open a file from the selection of demonstration examples provided using the [Demo] button on the File-Open dialogue.

Open a file from the selection of demonstration examples provided using the [Demo] button on the File-Open dialogue. Simfit Tutorials and worked examples for simulation, curve fitting, statistical analysis, and plotting. http://www.simfit.org.uk In the unlikely event that the model you want to plot, simulate or fit is

More information

Technical Overview of OpenModelica and its Development Environment

Technical Overview of OpenModelica and its Development Environment Technical Overview of OpenModelica and its Development Environment Adrian Pop 2013-02-04 Open Source Modelica Consortium Programming Environment Laboratory Department of Computer and Information Science

More information

Sprite an animation manipulation language Language Reference Manual

Sprite an animation manipulation language Language Reference Manual Sprite an animation manipulation language Language Reference Manual Team Leader Dave Smith Team Members Dan Benamy John Morales Monica Ranadive Table of Contents A. Introduction...3 B. Lexical Conventions...3

More information

int a; class x { public int a; class x { float b; Asda ad public int a; Asa asad Aac sdscfcc c a

int a; class x { public int a; class x { float b; Asda ad public int a; Asa asad Aac sdscfcc c a class x { public int a; class x { float b; public int func (int a,int b); int a; class x { Asa asad float b; public Asda ad int func int a; Asd (int ad a,int cc b); class x { Asa asad float b; Aac sdscfcc

More information

Jim Lambers ENERGY 211 / CME 211 Autumn Quarter Programming Project 4

Jim Lambers ENERGY 211 / CME 211 Autumn Quarter Programming Project 4 Jim Lambers ENERGY 211 / CME 211 Autumn Quarter 2008-09 Programming Project 4 This project is due at 11:59pm on Friday, October 31. 1 Introduction In this project, you will do the following: 1. Implement

More information

Java Software Solutions for AP Computer Science 3rd Edition, Lewis et al. 2011

Java Software Solutions for AP Computer Science 3rd Edition, Lewis et al. 2011 A Correlation of AP Computer Science 3rd Edition, Lewis et al. 2011 To the INTRODUCTION This document demonstrates how AP (Advanced Placement) Computer Science, 3rd Edition 2011, Lewis et al. meets the

More information

CS 211 Programming Practicum Fall 2018

CS 211 Programming Practicum Fall 2018 Due: Wednesday, 11/7/18 at 11:59 pm Infix Expression Evaluator Programming Project 5 For this lab, write a C++ program that will evaluate an infix expression. The algorithm REQUIRED for this program will

More information

Computer Science 1 Ah

Computer Science 1 Ah UNIVERSITY OF EDINBURGH course CS0077 COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS Computer Science 1 Ah Resit Examination Specimen Solutions Date: Monday 1st September 2003 Time: 09:30 11:00

More information

C++ Important Questions with Answers

C++ Important Questions with Answers 1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children

More information

Computational Physics

Computational Physics Computational Physics Python Programming Basics Prof. Paul Eugenio Department of Physics Florida State University Jan 17, 2019 http://hadron.physics.fsu.edu/~eugenio/comphy/ Announcements Exercise 0 due

More information

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,

More information

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

Ordinary Differential Equation Solver Language (ODESL) Reference Manual Ordinary Differential Equation Solver Language (ODESL) Reference Manual Rui Chen 11/03/2010 1. Introduction ODESL is a computer language specifically designed to solve ordinary differential equations (ODE

More information

Integrated Model-Driven Development Environments for Equation-Based Object-Oriented Languages

Integrated Model-Driven Development Environments for Equation-Based Object-Oriented Languages Integrated Model-Driven Development Environments for Equation-Based Object-Oriented Languages Adrian Pop Programming Environment Laboratory Department of Computer and Information Science Linköping University

More information

VALLIAMMAI ENGINEERING COLLEGE

VALLIAMMAI ENGINEERING COLLEGE VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 603 203 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK B.E. - Electrical and Electronics Engineering IV SEMESTER CS6456 - OBJECT ORIENTED

More information

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement Outline Expression Evaluation and Control Flow In Text: Chapter 6 Notation Operator evaluation order Operand evaluation order Overloaded operators Type conversions Short-circuit evaluation of conditions

More information

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java

More information

Enhancing the RAMSAS method for Systems Reliability Analysis through Modelica

Enhancing the RAMSAS method for Systems Reliability Analysis through Modelica 7th MODPROD Workshop on Model-Based Product Development February 05-06, 2013 Linköping University, Sweden Enhancing the RAMSAS method for Systems Reliability Analysis through Modelica Alfredo Garro and

More information

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led CENTER OF KNOWLEDGE, PATH TO SUCCESS Website: PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO 2010 Course: 10550A; Duration: 5 Days; Instructor-led WHAT YOU WILL LEARN This course teaches you

More information

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 2 Basic MATLAB Operation Dr Richard Greenaway 2 Basic MATLAB Operation 2.1 Overview 2.1.1 The Command Line In this Workshop you will learn how

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Towards a Text Generation Template Language for Modelica

Towards a Text Generation Template Language for Modelica Towards a Text Generation Template Language for Modelica Peter Fritzson *, Pavol Privitzer +, Martin Sjölund *, Adrian Pop * + Institute of Pathological Physiology, First Faculty of Medicine, University

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

Technical Overview of OpenModelica and its Development Environment

Technical Overview of OpenModelica and its Development Environment Technical Overview of OpenModelica and its Development Environment Adrian Pop 2016-02-01 Open Source Modelica Consortium Programming Environment Laboratory Department of Computer and Information Science

More information

SMPL - A Simplified Modeling Language for Mathematical Programming

SMPL - A Simplified Modeling Language for Mathematical Programming SMPL - A Simplified Modeling Language for Mathematical Programming Mihály Csaba Markót November 3, 2008 1 Purpose and Scope This working paper describes SMPL, an initiative of a Simplified Modeling Language

More information

The OpenModelica Modeling, Simulation, and Development Environment

The OpenModelica Modeling, Simulation, and Development Environment The OpenModelica Modeling, Simulation, and Development Environment Peter Fritzson, Peter Aronsson, Håkan Lundvall, Kaj Nyström, Adrian Pop, Levon Saldamli, David Broman PELAB Programming Environment Lab,

More information

Towards Run-time Debugging of Equation-based Object-oriented Languages

Towards Run-time Debugging of Equation-based Object-oriented Languages Towards Run-time Debugging of Equation-based Object-oriented Languages Adrian Pop and Peter Fritzson Programming Environments Laboratory Department of Computer and Information cience Linköping University

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

A Short Summary of Javali

A Short Summary of Javali A Short Summary of Javali October 15, 2015 1 Introduction Javali is a simple language based on ideas found in languages like C++ or Java. Its purpose is to serve as the source language for a simple compiler

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

and its Development Environment

and its Development Environment Technical Overview of OpenModelica and its Development Environment Adrian Pop 2015-02-02 Open Source Modelica Consortium Programming Environment Laboratory Department of Computer and Information Science

More information

Scheme Quick Reference

Scheme Quick Reference Scheme Quick Reference COSC 18 Fall 2003 This document is a quick reference guide to common features of the Scheme language. It is not intended to be a complete language reference, but it gives terse summaries

More information

A Tour of the Cool Support Code

A Tour of the Cool Support Code A Tour of the Cool Support Code 1 Introduction The Cool compiler project provides a number of basic data types to make the task of writing a Cool compiler tractable in the timespan of the course. This

More information

Modern Programming Languages. Lecture LISP Programming Language An Introduction

Modern Programming Languages. Lecture LISP Programming Language An Introduction Modern Programming Languages Lecture 18-21 LISP Programming Language An Introduction 72 Functional Programming Paradigm and LISP Functional programming is a style of programming that emphasizes the evaluation

More information

Object-Based Programming. Programming with Objects

Object-Based Programming. Programming with Objects ITEC1620 Object-Based Programming g Lecture 8 Programming with Objects Review Sequence, Branching, Looping Primitive datatypes Mathematical operations Four-function calculator Scientific calculator Don

More information

Course Outline. Introduction to java

Course Outline. Introduction to java Course Outline 1. Introduction to OO programming 2. Language Basics Syntax and Semantics 3. Algorithms, stepwise refinements. 4. Quiz/Assignment ( 5. Repetitions (for loops) 6. Writing simple classes 7.

More information

Chapter 9. Exception Handling. Copyright 2016 Pearson Inc. All rights reserved.

Chapter 9. Exception Handling. Copyright 2016 Pearson Inc. All rights reserved. Chapter 9 Exception Handling Copyright 2016 Pearson Inc. All rights reserved. Last modified 2015-10-02 by C Hoang 9-2 Introduction to Exception Handling Sometimes the best outcome can be when nothing unusual

More information

Control Structures. Outline. In Text: Chapter 8. Control structures Selection. Iteration. Gotos Guarded statements. One-way Two-way Multi-way

Control Structures. Outline. In Text: Chapter 8. Control structures Selection. Iteration. Gotos Guarded statements. One-way Two-way Multi-way Control Structures In Text: Chapter 8 1 Control structures Selection One-way Two-way Multi-way Iteration Counter-controlled Logically-controlled Gotos Guarded statements Outline Chapter 8: Control Structures

More information

Method Invocation. Zheng-Liang Lu Java Programming 189 / 226

Method Invocation. Zheng-Liang Lu Java Programming 189 / 226 Method Invocation Note that the input parameters are sort of variables declared within the method as placeholders. When calling the method, one needs to provide arguments, which must match the parameters

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 04: Exception Handling MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Creating Classes 2 Introduction Exception Handling Common Exceptions Exceptions with Methods Assertions

More information

Project 6 Due 11:59:59pm Thu, Dec 10, 2015

Project 6 Due 11:59:59pm Thu, Dec 10, 2015 Project 6 Due 11:59:59pm Thu, Dec 10, 2015 Updates None yet. Introduction In this project, you will add a static type checking system to the Rube programming language. Recall the formal syntax for Rube

More information

WA1278 Introduction to Java Using Eclipse

WA1278 Introduction to Java Using Eclipse Lincoln Land Community College Capital City Training Center 130 West Mason Springfield, IL 62702 217-782-7436 www.llcc.edu/cctc WA1278 Introduction to Java Using Eclipse This course introduces the Java

More information

Variables and Operators 2/20/01 Lecture #

Variables and Operators 2/20/01 Lecture # Variables and Operators 2/20/01 Lecture #6 16.070 Variables, their characteristics and their uses Operators, their characteristics and their uses Fesq, 2/20/01 1 16.070 Variables Variables enable you to

More information

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018 CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2018 Typical workflow concrete syntax (string) "(fn x => x + x) 4" Parsing Possible errors / warnings

More information

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Lecture 13. Notation. The rules. Evaluation Rules So Far

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Lecture 13. Notation. The rules. Evaluation Rules So Far Lecture Outline Operational Semantics of Cool Lecture 13 COOL operational semantics Motivation Notation The rules Prof. Aiken CS 143 Lecture 13 1 Prof. Aiken CS 143 Lecture 13 2 Motivation We must specify

More information

Functions in C C Programming and Software Tools

Functions in C C Programming and Software Tools Functions in C C Programming and Software Tools N.C. State Department of Computer Science Functions in C Functions are also called subroutines or procedures One part of a program calls (or invokes the

More information

INTRODUCTION TO C++ FUNCTIONS. Dept. of Electronic Engineering, NCHU. Original slides are from

INTRODUCTION TO C++ FUNCTIONS. Dept. of Electronic Engineering, NCHU. Original slides are from INTRODUCTION TO C++ FUNCTIONS Original slides are from http://sites.google.com/site/progntut/ Dept. of Electronic Engineering, NCHU Outline 2 Functions: Program modules in C Function Definitions Function

More information

Computing Fundamentals 2 Introduction to CafeOBJ

Computing Fundamentals 2 Introduction to CafeOBJ Computing Fundamentals 2 Introduction to CafeOBJ Lecturer: Patrick Browne Lecture Room: K408 Lab Room: A308 Based on work by: Nakamura Masaki, João Pascoal Faria, Prof. Heinrich Hußmann. See notes on slides

More information

ADMINISTRATIVE MANAGEMENT COLLEGE

ADMINISTRATIVE MANAGEMENT COLLEGE First Semester ADMINISTRATIVE MANAGEMENT COLLEGE BACHELOR OF COMPUTER APPLICATION COURSE OUTCOME (CO) Problem solving techniques Using C CO 1: Understand the basic concepts of programming, software and

More information

Zheng-Liang Lu Java Programming 45 / 79

Zheng-Liang Lu Java Programming 45 / 79 1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 45 / 79 Example Given a radius

More information

Math Modeling in Java: An S-I Compartment Model

Math Modeling in Java: An S-I Compartment Model 1 Math Modeling in Java: An S-I Compartment Model Basic Concepts What is a compartment model? A compartment model is one in which a population is modeled by treating its members as if they are separated

More information

Operational Semantics. One-Slide Summary. Lecture Outline

Operational Semantics. One-Slide Summary. Lecture Outline Operational Semantics #1 One-Slide Summary Operational semantics are a precise way of specifying how to evaluate a program. A formal semantics tells you what each expression means. Meaning depends on context:

More information

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Notation. The rules. Evaluation Rules So Far.

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Notation. The rules. Evaluation Rules So Far. Lecture Outline Operational Semantics of Cool COOL operational semantics Motivation Adapted from Lectures by Profs. Alex Aiken and George Necula (UCB) Notation The rules CS781(Prasad) L24CG 1 CS781(Prasad)

More information

More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements

More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements More Things We Can Do With It! More operators and expression types More s 11 October 2007 Ariel Shamir 1 Overview Variables and declaration More operators and expressions String type and getting input

More information

Semantic Analysis. CSE 307 Principles of Programming Languages Stony Brook University

Semantic Analysis. CSE 307 Principles of Programming Languages Stony Brook University Semantic Analysis CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Role of Semantic Analysis Syntax vs. Semantics: syntax concerns the form of a

More information

Institutionen för datavetenskap Department of Computer and Information Science

Institutionen för datavetenskap Department of Computer and Information Science Institutionen för datavetenskap Department of Computer and Information Science Final thesis Design and Implementation of the ModelicaML Code Generator Using Acceleo 3.X by Ibrahim Bumin Kara LIU-IDA/LITH-EX-A--15/012

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

https://asd-pa.perfplusk12.com/admin/admin_curric_maps_display.aspx?m=5507&c=618&mo=18917&t=191&sy=2012&bl...

https://asd-pa.perfplusk12.com/admin/admin_curric_maps_display.aspx?m=5507&c=618&mo=18917&t=191&sy=2012&bl... Page 1 of 13 Units: - All - Teacher: ProgIIIJavaI, CORE Course: ProgIIIJavaI Year: 2012-13 Intro to Java How is data stored by a computer system? What does a compiler do? What are the advantages of using

More information

Programming Exercise 7: Static Methods

Programming Exercise 7: Static Methods Programming Exercise 7: Static Methods Due date for section 001: Monday, February 29 by 10 am Due date for section 002: Wednesday, March 2 by 10 am Purpose: Introduction to writing methods and code re-use.

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 04: Exception Handling MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Creating Classes 2 Introduction Exception Handling Common Exceptions Exceptions with Methods Assertions and

More information

Garrett Hall CSC 173 C Programming Weeks 3-4

Garrett Hall CSC 173 C Programming Weeks 3-4 Garrett Hall CSC 173 C Programming Weeks 3-4 1. Overview The program parses code from an input file and evaluates it. The evaluator can handle basic mathematical operations (+, -, *, /, ^) and trigonometric

More information

Types and Type Inference

Types and Type Inference CS 242 2012 Types and Type Inference Notes modified from John Mitchell and Kathleen Fisher Reading: Concepts in Programming Languages, Revised Chapter 6 - handout on Web!! Outline General discussion of

More information

Modeling and Simulation in Scilab/Scicos with ScicosLab 4.4

Modeling and Simulation in Scilab/Scicos with ScicosLab 4.4 Modeling and Simulation in Scilab/Scicos with ScicosLab 4.4 Stephen L. Campbell, Jean-Philippe Chancelier and Ramine Nikoukhah Modeling and Simulation in Scilab/Scicos with ScicosLab 4.4 Second Edition

More information

Chapter1 Overview of computers

Chapter1 Overview of computers 1 Chapter1 Overview of computers 1. What is a computer? 2. Which is the earliest computing machine? 3. Who invented the pascaline? 4. What is Charles babbage known as? 5. What is the machine proposed by

More information

Inheritance and Interfaces

Inheritance and Interfaces Inheritance and Interfaces Object Orientated Programming in Java Benjamin Kenwright Outline Review What is Inheritance? Why we need Inheritance? Syntax, Formatting,.. What is an Interface? Today s Practical

More information

MetaModelica A Unified Equation-Based Semantical and Mathematical Modeling Language

MetaModelica A Unified Equation-Based Semantical and Mathematical Modeling Language MetaModelica A Unified Equation-Based emantical and Mathematical Modeling Language Adrian Pop and Peter Fritzson Programming Environment Laboratory Department of Computer and Information cience Linköping

More information

An Eclipse-based Integrated Environment for Developing Executable Structural Operational Semantics Specifications

An Eclipse-based Integrated Environment for Developing Executable Structural Operational Semantics Specifications SOS 2006 Preliminary Version An Eclipse-based Integrated Environment for Developing Executable Structural Operational Semantics Specifications Adrian Pop 1,2 Peter Fritzson 3 Programming Environments Laboratory

More information

Integration of OpenModelica in Ptolemy II

Integration of OpenModelica in Ptolemy II Mana Mirzaei Lena Buffoni Peter Fritzson Department of Computer and Information Science (IDA), Linköping University, Division SE-581 83, Linköping, Sweden Abstract In this paper we present the work done

More information

Scheme Quick Reference

Scheme Quick Reference Scheme Quick Reference COSC 18 Winter 2003 February 10, 2003 1 Introduction This document is a quick reference guide to common features of the Scheme language. It is by no means intended to be a complete

More information

CA Compiler Construction

CA Compiler Construction CA4003 - Compiler Construction Semantic Analysis David Sinclair Semantic Actions A compiler has to do more than just recognise if a sequence of characters forms a valid sentence in the language. It must

More information

Mid-Term 2 Grades

Mid-Term 2 Grades Mid-Term 2 Grades 100 46 1 HW 9 Homework 9, in untyped class interpreter: Add instanceof Restrict field access to local class Implement overloading (based on argument count) Due date is the same as for

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

Writing Evaluators MIF08. Laure Gonnord

Writing Evaluators MIF08. Laure Gonnord Writing Evaluators MIF08 Laure Gonnord Laure.Gonnord@univ-lyon1.fr Evaluators, what for? Outline 1 Evaluators, what for? 2 Implementation Laure Gonnord (Lyon1/FST) Writing Evaluators 2 / 21 Evaluators,

More information

Syntax and Grammars 1 / 21

Syntax and Grammars 1 / 21 Syntax and Grammars 1 / 21 Outline What is a language? Abstract syntax and grammars Abstract syntax vs. concrete syntax Encoding grammars as Haskell data types What is a language? 2 / 21 What is a language?

More information