|
|
(13 intermediate revisions by the same user not shown) |
Line 3: |
Line 3: |
| <div align="center"> | | <div align="center"> |
| Chapter: | | Chapter: |
− | [[The SCI Programming Language/Introduction|1]] | | + | [[SCI Programming Language/Introduction|1]] | |
− | [[The SCI Programming Language/Primitive Procedures|2]] | | + | [[SCI Programming Language/Primitive Procedures|2]] | |
− | [[The SCI Programming Language/Arithmetic Primitives|3]] | | + | [[SCI Programming Language/Primitive_Procedures#Arithmetic_Primitives|3]] | |
− | [[The SCI Programming Language/Boolean Primitives|4]] | | + | [[SCI Programming Language/Primitive_Procedures#Boolean_Primitives|4]] | |
− | [[The SCI Programming Language/Assignment Primitives |5]] | | + | [[SCI Programming Language/Primitive_Procedures#Assignment_Primitives |5]] | |
− | [[The SCI Programming Language/Data Types and Variables|6]] | | + | [[SCI Programming Language/Data Types and Variables|6]] | |
− | [[The SCI Programming Language/Definitions|7]] | | + | [[SCI Programming Language/Definitions|7]] | |
− | [[The SCI Programming Language/Control Flow|8]] | | + | [[SCI Programming Language/Control Flow|8]] | |
− | [[The SCI Programming Language/Conditionals|9]] | | + | [[SCI Programming Language/Control Flow#Conditionals|9]] | |
− | [[The SCI Programming Language/Iteration|10]] | | + | [[SCI Programming Language/Control Flow#Iteration|10]] | |
− | [[The SCI Programming Language/Primitive Procedures|11]] | | + | [[SCI Programming Language/Procedures|11]] | |
− | [[The SCI Programming Language/Files|12]] | | + | [[SCI Programming Language/Files|12]] | |
− | [[The SCI Programming Language/Compiling SCI|13]] | | + | [[SCI Programming Language/Compiling SCI|13]] | |
− | [[The SCI Programming Language/Index|Index]] | + | [[SCI Programming Language/Index|Index]] |
| </div><br /> | | </div><br /> |
| | | |
− | <div align="center"><span style="font-size: 22pt">Introduction to the SCI Language</span><br /> | + | <div align="center"><span style="font-size: 22pt">Introduction to the SCI Programming Language</span><br /> |
| ''Author: [[Jeff Stephenson]]''</div> | | ''Author: [[Jeff Stephenson]]''</div> |
| | | |
Line 34: |
Line 34: |
| which would be written in infix notation as: | | which would be written in infix notation as: |
| | | |
− | (y -2) + (x / 3) | + | <blockquote>(y -2) + (x / 3)</blockquote> |
| | | |
| All expressions are guaranteed to be evaluated from left to right. Thus, | | All expressions are guaranteed to be evaluated from left to right. Thus, |
| | | |
| <blockquote> | | <blockquote> |
− | <code>(= x 4) | + | <code>(= x 4)</code><br /> |
− | (= y (/ (+= x 4) ( / = x 2)))</code> | + | <code>(= y (/ (+= x 4) ( / = x 2)))</code> |
| </blockquote> | | </blockquote> |
| | | |
Line 46: |
Line 46: |
| | | |
| Comments in SCI begin with a semicolon and continue to the end of the line. | | Comments in SCI begin with a semicolon and continue to the end of the line. |
− |
| |
− | ==<br /> Primitive Procedures ==
| |
− |
| |
− | ===<br /> Arithmetic primitives ===
| |
− |
| |
− | In the following examples, e1, e2, etc. are arbitrary expressions. Brackets [...] indicate optional entries. Procedures evaluate their parameters from left to right.
| |
− |
| |
− | ====<br /> Addition ====
| |
− |
| |
− | <blockquote><code>(+ e1 e2 [e3...])</code></blockquote>
| |
− |
| |
− | evaluates to: e1 + e2 [+ e3...]
| |
− |
| |
− | example: (+ 7 12 4) evaluates to 23.
| |
− |
| |
− | ====<br /> Multiplication ====
| |
− |
| |
− | <blockquote><code>(* e1 e2 [e3...])</code></blockquote>
| |
− |
| |
− | evaluates to: e1 (*e2[*e3...]
| |
− |
| |
− | example: (* 2 10 3) evaluates to 60.
| |
− |
| |
− | ====<br /> Subtraction ====
| |
− |
| |
− | <blockquote><code>(- e1 e2)</code></blockquote>
| |
− |
| |
− | evaluates to : e1 - e2
| |
− |
| |
− | example: (- 20 11) evaluates to 9.
| |
− |
| |
− | ====<br /> Division ====
| |
− |
| |
− | <blockquote><code>(/ e1 e2)</code></blockquote>
| |
− |
| |
− | evaluates to: e1 / e2
| |
− |
| |
− | example: (/ 24 6) evaluates to 4. <---- Note: does this round when necessary (up, down)?
| |
− |
| |
− | ====<br /> Remainder ====
| |
− |
| |
− | <blockquote><code>(mod e1 e2)</code></blockquote>
| |
− |
| |
− | evaluates to: the remainder of e1 when divided by e2.
| |
− |
| |
− | example: (mod 17 5) evaluates to 2.
| |
− |
| |
− | ====<br /> Operation Shift Left ====
| |
− |
| |
− | <blockquote><code>(<< e1 e2)</code></blockquote>
| |
− |
| |
− | evaluates to : e1<< e2 where the << operation shifts its left hand side left by the number of bits specified by its right hand side.
| |
− |
| |
− | example: (<< 7 2 ) evaluates to 28.
| |
− |
| |
− | In binary: 111 << 2 = 11100
| |
− |
| |
− | ====<br /> Operation Shift Right ====
| |
− |
| |
− | <blockquote><code>(>> e1 e2)</code></blockquote>
| |
− |
| |
− | evaluates to: e1 >> e2 (as in << except with a right shift)
| |
− |
| |
− | example: (>> 7 2) evaluates to 1.
| |
− |
| |
− | In binary: 111 >> 2 = 001
| |
− |
| |
− | ====<br /> Bitwise Exclusive OR Operator ====
| |
− |
| |
− | <blockquote><code>(^ e1 e2 [e3...])</code></blockquote>
| |
− |
| |
− | evaluates to: e1^ e2 [^ e3...]
| |
− |
| |
− | example: (^ 11 26) evaluates to 17.
| |
− |
| |
− | In binary: 01011" 11010 = 10001
| |
− |
| |
− | ====<br /> Bitwise AND Operator ====
| |
− |
| |
− | <blockquote>
| |
− | {|
| |
− | |<code>(& e1 e2 [e3...])</code>
| |
− | |-
| |
− | |evaluates to: ||e1 &e2 [& e3...]
| |
− | |-
| |
− | |''example:'' ||<code>(& 11 26)</code> evaluates to 10.
| |
− | |-
| |
− | | ||In binary: 01011 & 11010 = 01010
| |
− | |}
| |
− | </blockquote>
| |
− |
| |
− | ====<br /> Bitwise OR Operator ====
| |
− |
| |
− | <blockquote>
| |
− | {|
| |
− | | <code><nowiki>(| e1 e2 [e3...])</nowiki></code>
| |
− | |-
| |
− | |evaluates to: ||e1 | e2 [| e3...]
| |
− | |-
| |
− | |''example:'' ||<code><nowiki>(| 11 26)</nowiki></code> evaluates to 27.
| |
− | |-
| |
− | | ||In binary: 01011 111010 = 11011
| |
− | |}
| |
− | </blockquote>
| |
− |
| |
− | ====<br /> Bitwise NOT ====
| |
− |
| |
− | <blockquote>
| |
− | {|
| |
− | |<code>(~ e1)</code>
| |
− | |-
| |
− | |evaluates to: ||the bitwise not of e1 (all 1 bits are changed to 0 and all 0 bits are changed to 1).
| |
− | |-
| |
− | |''example:'' ||<code>(~ 11)</code> evaluates to -12.
| |
− | |-
| |
− | | ||In binary: ~01011 = 1111111111110100 (all the leading 0s in the 16 bit number change to 1s).
| |
− | |}
| |
− | </blockquote>
| |
− |
| |
− | ===<br /> Boolean primitives ===
| |
− |
| |
− | These procedures evaluate their parameters from left to right and terminate the moment the
| |
− | truth value of the expression is determined. If the truth value of the Boolean expression is
| |
− | determined before an expression is reached, that expression is never evaluated. Brackets [...]
| |
− | indicate optional entries. The compiler predefines FALSE to be 0 and TRUE to be 1.
| |
− |
| |
− | ====<br /> Greater Than ====
| |
− |
| |
− | {|
| |
− | |(> e1 e2 [e3...])
| |
− | |-
| |
− | |evaluates to: ||TRUE if e1 > e2 [> e3...], else FALSE.
| |
− | |-
| |
− | |''example:'' ||(> 7 4 6) evaluates to FALSE.
| |
− | |}
| |
− |
| |
− | ====<br /> Greater Than or Equals ====
| |
− |
| |
− | {|
| |
− | |(>= e1 e2 [e3...])
| |
− | |-
| |
− | |evaluates to: ||TRUE if e1 >= e2 [>= e3...], else FALSE.
| |
− | |-
| |
− | |''example:'' ||(>= 7 4 4) evaluates to TRUE.
| |
− |
| |
− | ====<br /> Less Than ====
| |
− |
| |
− | (< e1 e2 [e3...])
| |
− | |-
| |
− | |evaluates to: ||TRUE if e1 < e2 [< e3...], else FALSE.
| |
− | |-
| |
− | |''example:'' ||(< 2 4 5) evaluates to TRUE.
| |
− | |}
| |
− |
| |
− | ====<br /> Less Than or Equals ====
| |
− |
| |
− | {|
| |
− | |(<= e1 e2 [e3...])
| |
− | |-
| |
− | |evaluates to: ||TRUE if e1 <= e2 [<= e3...], else FALSE.
| |
− | |-
| |
− | |''example:'' ||(<= 7 8 7) evaluates to FALSE.
| |
− | |}
| |
− |
| |
− | ====<br /> Is Equal To
| |
− |
| |
− | {|
| |
− | |(== e1 e2 [e3...])
| |
− | |-
| |
− | |evaluates to: ||TRUE if e1 == e2 [== e3...], else FALSE.
| |
− | |-
| |
− | |''example:'' ||(== 1 TRUE 1) evaluates to TRUE.
| |
− | |}
| |
− |
| |
− | '''Page 7'''
| |
− |
| |
− | ====<br /> Is Not Equal To ====
| |
− |
| |
− | {|
| |
− | |(!= e1 e2 [e3...])|-
| |
− | |evaluates to: ||TRUE if e1 != e2 [!= e3...], else FALSE.|-
| |
− | |''example:'' ||( ! = 7 4 6) evaluates to TRUE.
| |
− | |}
| |
− |
| |
− | ====<br /> AND ====
| |
− |
| |
− | {|
| |
− | |(and e1 e2 [e3...])
| |
− | |-
| |
− | |evaluates to: ||TRUE if all the expressions are non-zero, else FALSE.|-
| |
− | |''example:'' ||(and 7 4 6) evaluates to TRUE.
| |
− | |}
| |
− |
| |
− | ====<br /> OR ====
| |
− |
| |
− | {|
| |
− | |(or e1 e2 [e3...])
| |
− | |-
| |
− | |evaluates to: ||TRUE if any of the expressions are non-zero, else FALSE.|-
| |
− | |''example:'' ||(or 3 0 2) evaluates to TRUE.
| |
− | |}
| |
− |
| |
− | ====<br /> NOT ====
| |
− |
| |
− | (not el)|-
| |
− | |evaluates to: ||TRUE if the expression is zero, else FALSE.|-
| |
− | |''example:'' ||(not 6) evaluates to FALSE.
| |
− | |}
| |
− |
| |
− | '''Page 8'''
| |
− | ===<br /> Assignment primitives ===
| |
− |
| |
− | All assignment procedures store a value in a variable and return that value as the result of the assignment. In the following, v is a variable and e is an expression.
| |
− |
| |
− | (= v e) evaluates to v = e
| |
− |
| |
− | (+= v e) evaluates to v = v + e
| |
− |
| |
− | (-= v e) evaluates to v = v - e
| |
− |
| |
− | (*= v e) evaluates to v = v * e
| |
− |
| |
− | (/= v e) evaluates to v = v / e
| |
− |
| |
− | (|= v e) evaluates to v = v | e
| |
− |
| |
− | (&= v e) evaluates to v = v & e
| |
− |
| |
− | (^= v e) evaluates to v = v ^ e
| |
− |
| |
− | (>>= v e) evaluates to v = v >> e
| |
− |
| |
− | (<<= v e) evaluates to v = v << e
| |
− |
| |
− | (++ v) evaluates to v = v + 1
| |
− |
| |
− | (--v) evaluates to v = v - 1
| |
− |
| |
− |
| |
− |
| |
− |
| |
− |
| |
− |
| |
− |
| |
− |
| |
− |
| |
− |
| |
− |
| |
− |
| |
− |
| |
− | ;Notes
| |
− | <references />
| |
− |
| |
− |
| |
| | | |
| [[The SCI Programming Language | Table of Contents]] | | [[The SCI Programming Language | Table of Contents]] |
| | | |
− |
| + | <span style="float: left">[[SCI Programming Language|< Previous: Table of Contents]]</span> |
− | | + | <span style="float: right">[[SCI Programming Language/Primitive Procedures|Next: Primitive Procedures >]]</span> |
− | <span style="float: left">[[The SCI Programming Language |< Previous: Table of Contents]]</span><span style="float: right">[[The SCI Programming Language/Files|Next: Files >]]</span> | |
| | | |
| | | |
| | | |
| [[Category:SCI Documentation]] | | [[Category:SCI Documentation]] |
| + | [[Category:SCI32]] |
| [[Category:Scripting]] | | [[Category:Scripting]] |