User Tools

Site Tools


mpl

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
mpl [2016/07/11 16:20] – [WHILE] gryphonmpl [2016/07/11 16:51] gryphon
Line 206: Line 206:
       WriteLn ('More Blah')       WriteLn ('More Blah')
     End     End
 +
 +==== PROCEDURES ====
 +The syntax for defining a procedure is as follows:
 +
 +  Procedure <Proc Name> (<varname vartype>, <varname vartype>)
 +    <Code here>
 +
 +IE:
 +
 +  Procedure Hello_World
 +    WriteLn ('Hello World')
 +
 +OR:
 +
 +  Procedure SomeProc (Str String, A Byte)
 +    WriteLn ('Str = ' + Str)
 +    WriteLn ('  = ' + A)
 +  End
 +
 +OR:
 +
 +  Procedure SomeProc (Str String)
 +    Var
 +      Str2 : String,
 +      Str3 : String
 +    Begin             <--- The keyword "BEGIN" is ignored by the compiler
 +    WriteLn (Str)        just to maintain a "Pascal-like" feel.
 +  End
 +==== IF THEN/ELSE/END ====
 +The syntax of an if/else/end statement:
 +
 +  If <boolean statement> Then
 +    <True code here>
 +  Else If <boolean statement> Then     (optional)
 +    <True code here>
 +  Else                            (optional)
 +    <False code here>
 +
 +  If Not fEof(fptr) Then
 +    WriteLn ('We''re not at the end of the file.')
 +
 +The above example is the same as the following example, except we've added an else statement:
 +
 +  If fEof(fptr) = False Then
 +    WriteLn ('We''re not at the end of the file.')
 +  Else
 +    WriteLn ('This is the end of the file.')
 +
 +
 +  If A = 1 Then
 +    WriteLn ('A is 1')
 +  Else If A = 2 Then
 +    WriteLn ('A is 2')
 +  Else If A = 5 Then
 +    WriteLn ('A is 5')
 +  Else
 +    WriteLn ('A is not 1, 2, or 5...')
 +==== CASE Statements ====
 +
 +This has actually been expanded on from the Pascal standard but still follows the same syntax.  It has been expanded to allow CASE of more variable types, such as strings.  See the included MPLTEST.MPS for examples.
 +
 +  Var I : Integer = 10
 +  
 +  Case I Of
 +    1 : WriteLn('I = 1')
 +    2 : Begin
 +         I:=I+1
 +         WriteLn('I = 3')
 +        End
 +    3,4,5,6,7,8,9: 
 +      WriteLn('Not 1, 2, or 10')
 +  End
 +
 +  Var S : String = 'ABCDEFG'
 +    Case S[3] Of
 +      'A': WriteLn('S[3] = '+S[3])
 +      'B','C','D': WriteLn('S[3] = '+S[3])
 +    Else
 +       WriteLn('This is the default choice')
 +    End
 +
 +==== FUNCTIONS ====
 +The syntax for defining a function is as follows:
 +
 +  Function <Function Name> (<varname vartype>) : <result type>
 +
 +IE:
 +
 +  Function AddTen (Num Byte) : Byte
 +  Begin
 +    AddTen := Num + 10
 +  End
 +==== CONST VARIABLES ====
 +The syntax for a constant variable is as follows:
 +
 +String constants:
 +
 +  Const
 +    SomeStr = 'Hello World!'
 +
 +Numerical constants:
 +
 +  Const
 +    SomeNum = 69
 +
 +Constant variables, like regular variables, can be separated with a comma:
 +
 +  Const
 +    SomeNum = 69,
 +    SomeStr = 'Hello World!'
 +
 +At the moment, constant variables cannot be used in certain places within the MPE engine.  If you are assigning a value to a variable, constant values will not be recognized.
  
mpl.txt · Last modified: 2016/07/13 21:27 by g00r00

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki