Contents 0 Introduction 4



Download 383.54 Kb.
Page8/9
Date05.08.2017
Size383.54 Kb.
#26674
1   2   3   4   5   6   7   8   9

Loading a Program


A Progranimate file should end in the .prg extension. When a file is loaded the settings of Progranimate may change. This is because a file retains all of Progranimate’s settings when saved and re-instates them when loaded.

The load feature uses the file selection method native to the operating system used.


    1. Auto Loading


When Progranimate is launched via Java Web Start of Applet deployments the launching JNLP file or HTML page can specify a program file stored locally or on a web server. This program file will then be loaded automatically as Progranimate starts up. This is ideal for demonstrating concepts to users via an online tutorial. It can also be used for providing partially completed problems to solve. This makes Progranimate an ideal accompaniment to an online tutorial involving the basic imperatives of programming.

If Progranimate is launched via the Java Web Start or Applet deployments, the parameters specified in the JNLP file or Applet calling code will override the settings of any file being launched automatically at start up. Section 1.0, entitled ‘Deploying Progranimate’, will provide more information on pre-specifying a file to load in at start-up. It also explains how to externally configure almost all of Progranimate’s settings externally via parameters.


6.0Language Selection Code Generation and Translation


So that the user is not bogged down with the complexities of syntax, lines of code are not directly entered into Progranimate. Programming components and structures are defined individually and added to a program by interacting with either the flowchart or code views. The flowchart and code views update synchronously and tidily. When a component or structure is added to the flowchart view, corresponding components or structures will appear in the code view, and vice versa. The code generation features of Progranimate automatically generate code as components are added to a program.
    1. The Languages Available

Progranimate has the ability to generate code in a variety of languages. The current range of implemented languages is as follows:


Java,

VisualBasic.Net

VisualBasic6.0.
When a language is selected in Progranimate, any entered expression must conform to the rules governing the selected language. For information on selecting the language, see section 6.3.1, which discusses the code generation menu options.

    1. Language Translation

Progranimate provides the unique ability to translate a program between languages. This is because Progranimate utilises a subset of the primary programming components and structures that are common to most third generation languages. This makes it possible to analyse and translate a program and its data between languages.

To translate from the current language to another, a different language must be selected from the code generation menu. This can be done at any time other than during animation. Once the selection has been made, the current program is automatically analysed and translated to the new language. The flowchart, code and variable inspectors are then immediately updated to reflect the syntax of the new language.

Occasionally, there may be an inconsistency between the current language and the selected language. For this reason, the translated program is checked for syntax errors immediately after translation. For example, VisualBasic6.0 does not have an implementation of the character data type, but Java and VisualBasic.Net do. Therefore, it is not possible to translate programs containing characters to VisualBasic6.0; this causes an error. However, a simple way to overcome this limitation is to manually convert all character data types to string data types.


    1. The Code Generation Menu


Progranimate has a dedicated menu for customising the code generation features of Progranimate. The code generation menu is shown below in figure 22. Its options are discussed further in the following three sections.



Figure 22. The code generation menu.
      1. Language Selection


The Code Generation menu allows the user to select from a range of different languages. Progranimate can generate computer code in a range of languages. Currently, this includes:

Java,


VisualBasic.Net

Visual Basic6.

Selecting a language will cause the current program to be translated to the newly selected language. See section 6.2 for more details on language translation.

      1. Code Commenting Level


The program code can also contain commenting in the form of grey coloured text. The commenting is automatically generated and signifies the purpose ofclosing brackets in Java or End statements in Visual Basic. For example, in Java the commenting can signify: end of class, end of method, end While or end If, e.tc. The commenting features are also used by other languages such as VisualBasic.Net and Visual Basic 6.0 to comment the end statements belonging to While, If and If_Else structures, as well as the end statements belonging to sub procedures and modules. The table below shows how commenting is used in the Java and VisualBasic.Net languages.

Java

Visual Basic.Net

public class Untitled

{

public static void main(String[] args)

{

int x = 1;

String name = "";
while (x < 10)

{

x = x + 1;

}//End While (x < 10)

if (x > 2)

{

System.out.println("Hello");

}//End If (x > 2)
}//End Main

}//End Class

Module Untitled

Sub Main

Dim x as Integer = 1

Dim name as String = ""
While x < 10

x = x + 1

End While'(x < 10)

If x > 2

Console.WriteLine ("Hello")

End If'(x > 2)
End Sub'End of Main sub

End Module'End of Modlule Untitled
Table 14. Examples of Commenting

Three levels of commenting are available. These are: none, basic and advanced.


Selecting none will mean no commenting is generated at all.
Selecting basic means that basic commenting will be generated, for example:


Java

Visual Basic.Net


If ( x > 1)

{

System.out.println(msg1);

}//end If


Module Untitled

Sub Main

Dim x as Integer = 1
If x > 1

Console.WriteLine ("hello")

End If
End Sub'Main

End Module'Untitled


Table 15. Examples of basic commenting
The syntax of VisualBasic.Net and VisualBasic6.0 has a tendency to be more intuitive in respect to its structure ending syntax. Therefore, when basic commenting is selected for these languages, much of the commenting is redundant. For this reason, in VisualBasic.Net and VisualBasic6.0 basic, commenting only appears on End Sub and End Module statements.

A third advanced commenting option is also available; this provides a more detailed level of commenting. By adding arguments to the commenting of structure ends, it becomes easier to spot which structure the end bracket or end statement belongs to. The need for this becomes apparent with more complex programs, when multiple Ifs or Wiles are nested within each other. Table 13 below demonstrates this:




Java

VisualBasic.Net

public class Untitled

{

public static void main(String[] args)

{

int x = 1;
if (x > 1)

{

System.out.println("hello");

if (x > 2)

{

while (x < 1)

{

x = x + 1;

}//End While (x < 1 )

}//End If (x > 2 )

else

{

if (x > 3)

{

System.out.println(x);

}//End If (x > 3 )

}//End Else (x > 2 )

}//End If (x > 1)
}//End Main

}//End Class

Module Untitled

Sub Main

Dim x as Integer = 1
If x > 1

Console.WriteLine ("hello")

If x > 2

While x < 1

x = x + 1

End While'(x < 1)

End If '(x > 2 )

Else

If x > 3

Console.WriteLine (x)

End If '(x > 3)

End Else'(x > 2 )

End I f'(x > 1)
End Sub'End of Main sub

End Module'End of Modlule Untitled

Table 16. Complex nesting and advanced commenting.
      1. Font Size


It is possible to change the size of the font used in the generated code. There are five options available in the code generation menu. These are:
Largest

Large


Medium

Small


Smallest

      1. Font Style


The font style options of the code generation menu make it possible to change the font type of the generated code. There are three options available. These are:
Sans_Serif,

Serif ,


Monospaced.



Download 383.54 Kb.

Share with your friends:
1   2   3   4   5   6   7   8   9




The database is protected by copyright ©ininet.org 2024
send message

    Main page