Contents 0 Introduction 4


Editing Component and Structures



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

Editing Component and Structures


Occasionally, it may be required to edit the expressions associated with a component or structure. This can be achieved in multiple ways. The simplest way is to double click the component. Other ways are to select edit from the palette and then the component or structure to be edited. This can also be achieved in reverse (advanced settings permitting), where the component or structure is first selected and then the edit option from the palette is selected. A final way to edit a component is to right click it. If the popup menu has been enabled in the advanced settings, the user should be able to select the option edit. Depending on the advanced settings, some of these editing methods may be inhibited. For information on adjusting the selection methods in the advanced settings, see section 8.3.

All of these methods cause a pre-filled definition window to appear. Via this window, the expression belonging to the selected component can be edited. If desired, the name of the program can be changed. This is achieved by editing the starter component of the flowchart or the program delectation in the code view. In Java, program declaration is also known as class declaration.


    1. Copying, Cutting and Pasting Components and Structures.


Progranimate provides features for copying, cutting and pasting components or structures. This is achieved via a right click popup menu or by using Progranimate’s edit menu.
      1. Copying and Cutting





Figure 11. The popup menu

To copy or cut a component or structure, right click it in the flowchart or code views. A popup menu will then appear where the user can select from the options Copy or Cut (see figure 11). Selecting the component and clicking copy from Progranimate’s edit menu will have the same result.

When the copy option is selected, a copy of the component or structure selected is stored in the computers memory, leaving the copied component remaining. When copying a structure such as an If, If_Else or While, all of its internal components and sub structures will also be copied.

When the cut option is selected, a copy of the component or structure selected is stored in the computer memory as with copy. However, this time the component selected is cut (removed) from the flowchart. When cutting a structure such as an If, If_Else, While or For all of its internal components and sub structures are also cut.


      1. Pasting


Pasting a component or structure that has been copied or cut is achieved very easily. This can be done in two different ways, depending on what settings have been enabled in the advanced settings. The first way is to right click the intended location of the component in the flowchart or code views. This will cause the popup menu to appear where the paste option is available. The other way is to select the intended location with a left click. This will highlight the component. The paste option can then be selected from the edit menu. If a component or a line of code is selected, the pasted component or structure will be inserted below it. If a valid vertical link is selected, the pasted component or structure will be inserted by replacing the link.

T




Figure 12. Cutting and pasting a structure.
here will be no need for the user to tidy up the flowchart or code once a component has been pasted; the code and flowchart will be adjusted and tidied automatically. Figure 12 below shows an example of a cut and paste operation in Progranimate.

    1. The Components and Structures in Detail


This section discusses each programming component or structure available to Progranimate. It provides information on the usage and possibilities of each component or structure. The syntax used within the components and structures of Progranimate depend on the language selected. In this section we will discuss the syntax in relation to Java and VisualBasic.Net. For more information on the language selection possibilities of Progranimate, see section 6.1.
      1. The Print Component.




At run time, the print component will evaluate an expression and display the result in the console as it is animated.



E

Figure 13. The Print definition window


ntering Data to be Printed

To define a print component, the user enters the expression they wish to be printed at run time. This could be a singular variable such as X. It could also be a mathematical expression involving more than one variable such as X + Y * Z. Complex expressions using brackets and array elements are also permitted. Where any variable may be used, an array element may also be referenced. Logical expressions such as x > = y are also allowed in the Print component. In this case, the true or false result is output to the console. It is not permitted to use the assignment operator in the expressions used by the print component. In the Java and VisualBasic programming languages, the assignment operator is an equals ‘=’ symbol.



Concatenating Strings

In Java, String items are concatenated together using the plus ‘+’ operator. (In VisualBasic.Net it is an ampersand ‘&’.) Therefore, the print definition window will allow us to enter the parameters: A + B + C when Progranimate is setup for the Java Language. Given that A, B and C are String variables, at run time the values of variables A,B and C will be concatenated together and printed in the console window as the print component is animated.



Entering Literal Strings and Characters Directly

Users may enter a literal string directly; in this case they would encase the string in double quotes i.e. “Please enter your name”. They may also combine litteral strings with other variables and array elements, i.e. “Your name is” + name or “Your name is “ + n[3].

Characters may also be entered directly, in this case they are encased in single, i.e ‘ stringValue + ‘s’.

Mixing Data Types.

If the expression to be printed contains a mixture Strings and other data types all data types will be handled as if they were strings inline with the semantics of the languages implimented. For example:

Variable X is an integer type containing the value 1,

Variable Y is a Double type containing the value 3.5,

Variable S is a String data type containing the value “ + ”.

In this example X + S + Y would point out 1 + 3.5.

As another example, one may enter the following expression with the intention of performing a calculation.

We could enter the following: X + S + Y + “ = ” + X + Y.

This would print out: 1 + 3.5 = 13.5.

However, the result of the calculation appears wrong. This is because no calculation is taking place; all the values are being concatenated as strings because they are of mixed data types.

To overcome this problem, encase the section to be calculated in parenthesise, i.e. X + S + Y + “ = “ + ( X + Y). This will ensure the correct calculation is displayed on screen i.e. X + Y = 4.1.

Another way to overcome this problem is to perform the calculation X + Y individually, assign the result to another variable, and then construct the expression to be printed. To do this you will need to use the assign component; see section 3.9.3 for more details.


      1. The Read Component




At run time, the read component is used to take input from the keyboard and place it in a variable or array element. As the read component is animated, the console window pops up, and there, the user enters a value to be stored. If valid, this value is then placed in the variable or array element referenced in the read component’s parameters. At this time, animation is halted until the information is entered into the console and either the enter key or the on screen enter button is pressed.



Entering A Variable or Array Element to Read In To

The read component can only take one variable or array element. Expressions are not permitted in a read component unless the expression is used to reference the index of an array element.

For example:

anArray[x+(2*y)]

Runtime Validation of User Input

At run time, the user input is validated against the data type of the variable. For example, an error would be generated if the user were to enter Hello when the read component was referencing an integer. The user would then have to re-enter the information where it would then be re-validated.


      1. The Assign Component


The assign component is used to assign a value to a variable or the value of one variable into another. It is also used to assign the result of an expression into a variable, providing the expression result matches the data type of the variable to be assigned to. When the assign component is animated at run time, the assignment expression is evaluated and calculated. The changes to program data are displayed in the variable or array inspector. In this section, we will refer to the variable being assigned to as the assignee.

Assigning a value to a Variable or Array Element

The most primary function of the assignment component is to directly assign a value to a variable. For example, we may want to assign the value 1 to an integer variable called X. In this case, we would enter:



X = 1.

The same can also be performed by an array’s element, for example:



anArray[4] = 1.

This would assign the value ‘one’ to the fifth element of an array (fifth because arrays are zero based).

The assignment of literal stings and characters is also possible. A few examples are shown below.

name = “Mike” sex = ‘M’ months[0] = “Jan”

When assigning a value to a variable or array, the assignee and value to be assigned must be compatible. This compatibility may vary depending on the language selected.



Assigning The Value of one Variable or Array Element to another.

Assigning one variable to another is simple. For example, to assign the value of integer Y to integer X, the following expression could be entered:



X = Y.

To assign the value of an array element to a variable, the following expression could be entered.



X = anArray[3].

To assign the value of a variable to an array element, an expression like the following example could be entered.



anArray[3] = X.

To assign the value of one array element to another, the following expression could be entered.



anArray[2] = anotherArray[4].

When assigning one variable or array to another. you must ensure that the data type of the assignee is compatible with that of the value to be assigned. This compatibility may vary depending on the language selected.



Assigning an Entire Array to Another Entire Array

In Progranimate it is not possible to assign one array directly to another. To achieve this you must assign each array element individually. This can be achieved by using an assignment statement within a looping structure.



Assigning the Result of an Expression to a Variable or Array.

It is possible to assign the result of an expression to an array, providing the evaluated result of the data type is compatible with that of the assignee.

An example of a simple expression is shown below. In this example, the expression is used to increment the integer variable x:

X = X + 1

Progranimate does not understand the Java short cuts for incrementing and decrementing such as X ++ or X --. These shortcuts were not included, as they hide the logical process behind such an assignment operation.

The assign component also allows for the results of Boolean expressions to be assigned to a Boolean type variable, for example:

bool1 = X >= Y

The logical operators used will be in line with the operators of the selected programming language being used by Progranimate.

More complex logical expressions can be used using the AND, OR and XOR operators native to the selected language. For example, when the Java language is selected, the following expression is permitted:

bool1 = X >= 1 && X <= 10

If VisualBasic.Net is selected the following expression would be permitted:



bool1 = X >= 1 AND X <=10

Progranimate allows for complex expressions to be entered, involving many parenthesise to multiple levels. The following is an example of a more complex calculation permissible by Progranimate:



X = X + ( na[5]* 2 ) * (X*2 +(na[3*Y]) /2) - 1

Once the expression has been entered into the assign definition window and the ok button (or enter key) is pressed, then the expression undergoes evaluation. Any errors are fed back to the user using plain English. For more on expression analysis and evaluation, see section 3.9.6.



      1. Control Structures.


The If, If_Else, While and For structures are the three control structures used by Progranimate. The If and If_Else form decisional structures. The While, and For structures form the looping structures implemented by Progranimate. Each of these structures utilises a Boolean expression. Boolean expressions are expressions that evaluate to a true or false result. These three structures are discussed in the following sections. This section also contains further reading on creating logical expressions. For more information on constructing logical expressions, see section 3.9.5 “Constructing Logical Expressions”.
        1. The If Structure




P


Figure 14. The If Structure
rogranimate’s If structure allows decisions to be made within a program. Like all of Progranimate’s control structures, it must contain a Boolean expression. This Boolean expression is entered during its definition.

At run time, the If component directs the flow of execution down one of two paths, based on the evaluated result of the expression it contains. If the argument evaluates to true, the flow of code is directed inside the If’s structure. If the argument evaluates to false, the flow of execution is directed to skip over the If’s structure. As the expression is evaluated, the If _Else’s diamond will highlight two of its edges, pointing either left or downward. This is to indicate the direction in which the flow of control will move.

Components and sub structures that reside within the If’s structure are placed on the true path between an If and its end component. When interacting with the flowchart, attempting to add component to the false path of a standard If will cause a placement error to be generated and displayed.

Table 3 below shows an example of the code generated for an If structure with one internal component. The blue arrows show how the flowchart component relates to the lines of code.



Flowchart

Java

Visual Basic



if ( x >= 5)

{
System.out.println (“Hello”);
}

If x >= 5

Console.Writeline(“Hello”);
End If



Table 3. How code relates to the flowchart.

For more information on constructing the logical conditions needed by the If structure, see section 3.9.5.


        1. The If_Else Structure


T

Figure 15. The If Else Structure


he If_Else structure differs from the standard If structure, as it has two possible paths of execution. As well as having a slightly different visual appearance, components can be placed on both the true or false paths of this structure, as shown in figure 15.b

Like the other control structures of Progranimate, the If_Else takes a Boolean expression during its definition. At run time, the flow of execution is determined by evaluating the expression it contains. If the result is true, control is passed down the true left side path of the If structure. If the result is false, control is passed down the left side of the If_Else’s structure. In code, the IF and the Else parts of the structure represent the true and false paths of the flowchart. As the Boolean expression is evaluated, it will highlight either the left or right edges of the If _Else structure’s diamond to indicate the direction in which the flow of control will move. Table 4 below demonstrates this. The blue and red lines and arrows demonstrate how the flowchart relates to the generated code.



Flowchart

Java

Visual Basic



if ( age >= 18)

{
System.out.println (“Adult”);
}

else

{
System.out.println (“Child”);
}

If Age >= 18
Console.Writeline(“Adult”)
Else
Console.Writeline (“Child”)
End Else


Table 4. How the code relates to the flowchart.

For information on constructing the logical conditions needed by the If structure, see section 3.9.5.



*NOTE*:Synchronised Highlighting With the IF_Else Structure.

The IF_Else structure has some minor enhancements to its visual components that make it easier to relate its flowchart representation to its code representation. Clicking on the left side of the If structure’s diamond in the flowchart view will cause the code associated with its If to highlight. Clicking on the right side of the If’s diamond will cause the code relative to the structure’s Else to highlight. When the left side of the End_If is clicked in the flowchart, the relevant closing bracket or End_If statement will be highlighted in the code view. When the right side of the End_If is clicked the relevant closing curly bracket or End Else statement will be highlighted in the code view. The same is true in reverse; clicking a line of code relating to the If_Else structure will cause the relevant side of the relevant component in the flowchart view to highlight.


        1. The While Loop Structure


The While control structure allows for looping within programs. Its role is to continually re-direct the flow of control though a set of components or sub structures, until the expression it contains evaluates to false. Figure 16 shows the flowchart representation of a While loop with and without internal components.

Like the If and If_Else structures, the While structure is associated with a Boolean expression during its definition. During animation, when the While is reached, its expression is evaluated. If its expression evaluates to true, then the flow of execution is directed downwards within the While’s structure. The components and sub structures inside the While loop are then executed in order until the End_While is reached. The f




Figure 16. The While Looping Structure
low of execution is then redirected to the top of the loop, where its expression is re-evaluated and the flow is directed appropriately. Looping continues until the expression evaluates to false. If and when the expression evaluates to false, the flow of execution is directed down the exit path, past the While loop, and on to the next component or structure below.

To add the first component within a While’s structure the user must click on its decisional diamond in the flowchart, or on the While line of text in the code. This will add a component inside its structure in-between the While and End_While in both the flowchart and code. Other components or structures can then be added inside a While’s structure by interacting with the code and flowchart in the standard way. Components cannot be added to the loop return or exit paths of a While loop. Doing so causes a placement error to be generated and displayed.


Table 5 demonstrates the relationship between the visual flowchart structure and the code generated for a While structure. For information on constructing the logical conditions needed by the While structure, see section 3.9.5



Flowchart

Java

Visual Basic




while (x < 10)

{

x = x + 1;
}//End While


While x < 10


x = x + 1
End While

Table 5. How the code relates to the flowchart
      1. The For Loop Structure

The For loop provides an additional looping structure. The for loop behaves like a while loop except it increments a variable without the need for an additional assignment statement. Depending on the language chosen the format and semantics of the For loop differs.


Visual Basic For Loop
Visual Basic (.Net and 6.0) utilizes a traditional style for loop with start , end and step values as follows.
For controlVariable = start TO end STEP stepValue
‘Code to be looped goes here.
Next ‘(the end of the loop)
The control variable can be a integer or double type variable or array element. Its value will change with each loop.
When the loop begins the control variable is assigned a starting value:
controlVariable = start
The loop will terminate when the controlVariable equals the end value.
With each loop the value of the control variable is incremented by the amount specified by the step value. If no step value is specified this value is assumed to be one.
Table 6 demonstrates the relationship between the visual flowchart structure and the code generated for a While structure The code shown below will loop 100 times during which the value of variable i will be printed. This will result in the values 1 to 100 being printed.


Flowchart

Visual Basic




For i = 0 TO 100
Console.WriteLine (i)
Next'End For


Table6. The For Loop in VB

Using the Step Value

If you modify the above to add a step the control variable will increment by a different amount with each loop. In the example below we supply a step value of 2. The program should loop 50 times printing 1,3,5,7,9 and so on until the control variable exceeds 100.


For i = 0 TO 100 STEP 2

Console.WriteLine(i)

Next
Negative Increments (Looping Backwards)

It is also possible to loop backwards in this case the start value needs to be higher than the end value and the step needs to be negative for example:


For I = 100 TO 1 STEP -1

Console.WriteLine(i)

Next
In this example the loop will loop 100 times from 100 down to 1 whilst printing the value of variable i. This will result in the numbers 100 down to 1 being printed to the screen.
Looping in Decimals

It is also possible to loop in decimal increments providing the control variable and step value are of the double data type. For this example imagine the variable d is a double.

For d = 1.0 to 5.5 STEP 0.1

Console.WriteLine(d)

Next
In this example 55 values will be printed out from 0 to 5.5 i.e. 1.0, 1.1, 1.2, 1.3, 1.5, 1.6……and so on until 5.5.
Complex For Loops

The for loops can handle the same level of complexity that VB allows. For example all of the following examples are value.


Example A.

For x = y+2 TO z -2


Next
Example B

For values[1] = anArray[0] TO anotherArray[x] STEP otherArray[0]


Next
Example C.

For values[i] = 1+ x TO y 2 STEP z/2 + (2 * z )


Next
The Definition Panel a Visual Basic For Loop

The definition panel For a Visual Basic for loop is the most complex of all the definition panels. However, it is still very simple and intuitive to use.





Figure 17 The Visual Basic For Loop Definition Panel
All fields of this panel are mandatory except step which is optional. When no specified the step will not show in the code but will cause a default increment of 1.
The control variable must be an integer or decimal variable or array element. In all other fields literal values, variables and expressions may be entered as long as they result in an integer or a double data type.
Any user errors will appear below the relevant field where the error has been detected.

Java Style For Loops
In the Java language the format of the For loop is significantly different than with Visual Basic. The for loop in this language relates more closely to a while loop where it relies in the use of a Boolean condition. Like the for loop it also manages the initialization and incrementation of a control variable. In Java the for loop takes the following form:
for ( initialization; boolean expression; increment )

{

//Code goes here



}
The initialisation section is used to initialize the control variable with an initial value as the loop begins.
The Boolean expression is evaluated with each loop and while true looping continues. When false looping stops and the flow of execution is diverted past the for loop and onto the next instruction. It is common practice to have a Boolean expression which tests the value of variable initialized in the initialization section, though any valid Boolean expression may go here.
With each loop the value of the expression contained in the increment is evaluated. It is common practice to include in here an expression to increment the a control variable specified in the initialization and Boolean expression of this component. However any valid assignment expression may go here.



Flowchart

Java




For ( i = 0; i <= 100 ; i = i + 1)

{

System.out.println (i)
}



Table7. The For Loop in Java
The expressions contained within the Java for loop may include anything that is permitted by the Java language. Some examples are shown below.
Basic Looping
Printing numbers 1 to 100 in increments of two
For ( i = 0 ; i <= 100; i= i + 2)

{

System.out.println (i);



}
Negative Increments (Looping Backwards)
Printing number from 100 down to 1.
For ( i = 10; i > 0; i= i – 1)

{

System.out.println(i);



}
Decimal Increments
Outputting 55 numbers between 1.0 to 5.5. in increments of 0.1
For ( d = 0.1; d <= 5.5; d = d + 0.1)

{

System.out.println(i);



}
Complex Examples:
Any valid expression permitted in the for loops of the Java language are also facilitated in Progranimate this means complex loops can be constructed if needed.
Example A:
For (x = y +2; x => y+(z*3); x = x * y)

{

//Code here



}
Example B:

For (anArray[i] = 0 ; anArray[1] <= anotherArray[5]; anArray[i] = anArray[i] + 1

{

//Code here



}

For loop Definition
The definition panel for a Java For loop consist of three parameters, the control variable, the condition and the increment. Inline with the rules of the Java language all these parameters are optional. Should the user entry any syntactically incorrect expressions, or non existent variables an error will be presented below the relevant field.


Figure 18 The JavaFor Loop Definition Panel

      1. Constructing Logical Boolean Expressions


All of the control structures of Progranimate rely on the use of a Boolean expression as a necessity. Boolean expressions are expressions that produce a true or false result when evaluated. Other components such as Print and Assign can also make use of Boolean expressions. This section aims to highlight the possibilities relating to the creation of Boolean expressions in Progranimate.

In Progranimate the syntax of any entered expression is native to the programming language selected. In this section, we will look at the creation of expressions in relation to the Java and VisualBasic.Net programming languages. However, this section will be of use to those wishing to use other languages, as there are many similarities between third generation programming languages.

The rules regarding the formation of Boolean expressions conform to that of the programming language selected. The main rule that tends to be uniform amongst most third generation programming languages is that the data being compared must be of the same data type. Some languages such as Java and VisualBasic allow for mixed data type comparison. For example, it is okay to compare an Integer with a Double, and visa versa. This ability has also been facilitated in Progranimate (when these languages have been selected). Java permits the comparison of an Integer with a character, via its ASCII code. This feature is not available in Progranimate; it was seen as an unessential feature that it introduced a level of complexity not needed by the novice.

        1. Comparison Operators


The comparison operators available to Progranimate are in line with the basic operators provided by the selected language. These are shown below in table 8.


Java

Visual Basic.Net

Meaning

>

>

Greater

<

<

Less

>=

>=

Greater or Equal

<=

<=

Less or Equal

==

=

Equal

!=

<>

Not Equal


Table 8. Comparison operators
        1. Entering Simple Boolean Expressions


Creating simple Boolean expressions in Progranimate is very easy. They are entered when defining or editing one of Progranimate’s control structures (see figure 19).



Figure 19. Condition definition

Below are some examples of simple logical expressions in the Java and VisualBasic.Net programming languages.




Java

Visual Basic.Net


X >= 5
X < 2.5
name != “Bob”
chr == ‘C’
answer == True
array[ 1 ] >= anotherArray[ 4 ]


X >= 5
X < 2.5
name <> “Bob”
chr = ‘C’
ansert = True
array( 1 ) >= anotherArray( 4 )



Table 9. Example Boolean expressions

For information relating to more complex Boolean expressions, see section 3.9.5.3 ‘Using AND, OR and XOR’ and 3.9.5.4 ‘Complex Boolean expressions.’


        1. Using AND, OR and XOR


Progranimate allows the use of three basic logical operators these are AND, OR and XOR. The form these operators take is dependant on the language selected. Below table 10 shows the logical operators in relation to the Java and VisualBasic.Net programming languages.


Java

Visual Basic.Net

Meaning

&&

AND

And

||

OR

Or

^

XOR

Exclusive or


Table 10. The logical operators

The logical operator NOT is not included in the logical operators used by Progranimate. It is felt more educationally beneficial to for the users to learn how to negate their logic statements, rather than using the NOT operator.



Using the thee logical operators the user can construct a very diverse range of Boolean expressions. The examples shown in table 11 below demonstrate some of the possibilities.


Java

Visual Basic.Net


x >= 1 && X <= 10
x < 2 . 5 || y < 2 . 5
name != “Bob” && age == 58
chr == ‘C’ || chr = ‘c’
answer == True ^ fail == False
x >= 1 && x <= 5 && check == true
chr == ‘C’ || chr = ‘c’ && x >= n[ 5 ]



x >= 1 AND X <= 10
x < 2 . 5 OR y < 2 . 5
name <> “Bob” AND age = 58
chr = ‘C’ OR chr = ‘c’
answer = True XOR fail = false
x >= 1 AND x <= 5 AND check = true
chr = ‘C’ OR chr = ‘c’ AND x >= n( 6 )


Table 11. Examples of Boolean expressions with logical operators
        1. Complex Boolean Expressions


It is possible to use complex Boolean expressions if required. It is permissible to use multiple levels of parenthesise and mathematical sub expressions to build up complex Boolean expressions. However, with novices, the use of complex expressions should be minimised or eliminated, if at all possible. Some examples of what is possible are shown in table 12 below.


Java


x + ( 3 *y) >= y * 3 + (x - -1)

x + nA[ 5 ] <= 2 | | y + (2*x) <= d
name = = “Bob Coomber” && duration <= (hours / 24) + days
nA[ 5 + (2*x) ] >= bA[ y ]


Visual Basic

x + ( 3 *y) >= y * 3 + (x - -1)
x + nA( 5 ) <= 2 OR y + (2*x) <= d
name = = “Bob Coomber” AND duration <= (hours / 24) + days
nA( 5+(2*x) ) >= bA( y )



Table 12. Examples of complex Boolean expressions
      1. Expression Analysis and Evaluation


Once an expression is entered into a component, it undergoes evaluation to check for errors. The aim of Progranimate is to inform the user of the error in plain English and to limit the use of technical jargon where possible.
        1. Syntax Analysis


Once entered, an expression is evaluated for syntactical errors. The following ten checks are carried out to validate the expression’s syntax.

  1. Ensure the count of opening parenthesise matches the count the closing parenthesise.

  2. Ensure the count of opening array index brackets matches the number of closing array index brackets.

  3. Ignoring brackets, ensure the syntax is in the form Value Operator Value Operator Value etc.

  4. Ensure all named variables or arrays exist in the inspector.

  5. Ensure the data types of all values to be calculated or compared are compatible with each other.

  6. Ensure all operators are valid.

  7. Ensure the operators used are compatible with the values and sub values of the expression.

  8. Ensure one assignment operator is used for all assign components and no assignment operator is used for all others.

  9. Ensure the assignment operator is the second item of an assignment expression.

  10. Where assignment takes place, ensure the result of the expression is compatible with the variable or array element being assigned to.

There is a very wide rage of syntax errors generated by Progranimate. With respect to syntax error handling, Progranimate aims to be more contextual than most standard development environments. Furthermore, all of the errors generated by Progranimate are in plain English; technical Jargon has been limited where at all possible. Four examples of Progranimate’s syntax errors are shown below.

Example 1:

A user may attempt to reference a non-existent variable or array when defining a component or structure. In this case, Progranimate should display the following syntax error:



The variable X does not exist.

Example 2:

An error will be generated when a user attempts to enter an unrecognised operator or symbol. For example, using Java’s not equal operator != when VisualBasic.net is selected causes the following error message to appear:



!= is invalid. Ensure you have typed the expression correctly.

Example 3:

Look at the following erroneous Java expression. Can you see what is wrong with it?



x = x + + 2

Example 4:

The user has entered two pluses. This is either because they entered a plus one to many times or because a value is missing between the two plus operators. In any case, the following error message is generated.



The symbol + is in an invalid location within the expression.
        1. Operator Precedence


Each expression entered into Progranimate is evaluated using the normal order of precedence pertaining to the selected Language. When it comes to the order of mathematical expressions, most languages conform to normal mathematical rules of precedence. However, when it comes to the precedence of logical and other operators, the order of precedence may differ very subtlety. Table 13 demonstrates the subtle differences in operator precedence between the Java and VisualBasic.Net languages.

During both entry and run time, Progranimate evaluates and calculates its expressions in accordance with the rules of precedence. During entry the expressions are evaluated for validation purposes. During run time, expressions are evaluated so that the variable and array inspectors can be appropriately updated.



Precedence

Java

Visual Basic

1

Array Brackets: [ ]

Array Brackets: ( )

2

Parenthesise: ( )

Parenthesise: ( )

3

Multiplicative: * and /

Multiplicative: * and /

4

Additive: + and –

String concatenation: +



Additive: + and -

5

Comparison:

>, < , >= and <=



String concatenation: &

6

Comparison:

!= and = =



Comparison:

>, <, >=, <=, = and <>



7

Logic AND: &&

Logic AND: And

8

Logic OR: | |

Logic OR: Or

9

Logic XOR: ^

Logic XOR: Xor

Table 13. Operator precedence

For precedence relating to the operators of other languages implemented by Progranimate, see the technical documentation relating to that language. It may be worthwhile to take a look on the Internet. For most popular programming languages, the Internet is a great resource for finding information about operator precedence.




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