Difference between revisions of "SCI Programming Language/Introduction"

From SCI Wiki
Jump to navigationJump to search
Line 24: Line 24:
 
 
 
 
  
 +
The SCI language is an object-oriented language with a Lisp-like syntax. It is compiled by the sc compiler into p-machine code which is used by the interpreter, sci.exe. We will begin our discussion of the language with its basic Lisp-like characteristics, then go on to the object-oriented parts of the language. Like Lisp, SCI is based on parenthesized expressions which return values. An expression is of the form:
  
 +
<blockquote><code>(procedure [parameter parameter...])</code></blockquote>
  
 +
The parameters to a procedure may themselves be expressions to be evaluated, and may be nested until you lose track of the parentheses. Unlike Lisp, a procedure itself may not be the result of an evaluation. An example of an expression is:
  
 +
<blockquote><code>(+ (-y 2) (/ x 3))</code></blockquote>
  
 +
which would be written in infix notation as:
 +
 +
(y -2) + (x / 3)
 +
 +
All expressions are guaranteed to be evaluated from left to right. Thus,
 +
 +
<blockquote>
 +
<code>(= x 4)
 +
(= y (/ (+= x 4) ( / = x 2)))</code>
 +
</blockquote>
 +
 +
will result in y = 2 and x = 4.
 +
 +
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>
 +
<blockquote><code>(& e1 e2 [e3...])</code></blockquote>
 +
 +
evaluates to: e1 &e2 [& e3...]
 +
 +
{|
 +
|-
 +
|example: ||<code>(& 11 26)</code> evaluates to 10.
 +
|&nbsp;
 +
|&nbsp;    ||In binary: 01011 & 11010 = 01010
 +
|}
 +
</blockquote>
 +
 +
====<br /> Bitwise OR Operator ====
 +
 +
<blockquote>
 +
<blockquote><code>(| e1 e2 [e3...])</code></blockquote>
 +
 +
evaluates to: e1 | e2 [| e3...]
 +
 +
example: (| 11 26) evaluates to 27.
 +
 +
<blockquote>In binary: 01011 111010 = 11011</blockquote>
 +
</blockquote>
 +
 +
====<br /> Bitwise NOT ====
 +
 +
<blockquote>
 +
<blockquote><code>(~ e1)</code></blockquote>
 +
evaluates to: the bitwise not of e1 (all 1 bits are changed to 0 and all 0 bits are changed to 1).
 +
 +
example: (~ 11) evaluates to -12.
 +
 +
<blockquote>In binary: ~01011 = 1111111111110100 (all the leading 0s in the 16 bit number change to 1s).</blockquote>
 +
</blockquote>
  
  

Revision as of 16:06, 20 May 2016

Official SCI Documentation

Chapter: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | Index


Introduction to the SCI Language
Author: Jeff Stephenson

 

The SCI language is an object-oriented language with a Lisp-like syntax. It is compiled by the sc compiler into p-machine code which is used by the interpreter, sci.exe. We will begin our discussion of the language with its basic Lisp-like characteristics, then go on to the object-oriented parts of the language. Like Lisp, SCI is based on parenthesized expressions which return values. An expression is of the form:

(procedure [parameter parameter...])

The parameters to a procedure may themselves be expressions to be evaluated, and may be nested until you lose track of the parentheses. Unlike Lisp, a procedure itself may not be the result of an evaluation. An example of an expression is:

(+ (-y 2) (/ x 3))

which would be written in infix notation as:

(y -2) + (x / 3)

All expressions are guaranteed to be evaluated from left to right. Thus,

(= x 4) (= y (/ (+= x 4) ( / = x 2)))

will result in y = 2 and x = 4.

Comments in SCI begin with a semicolon and continue to the end of the line.


Primitive Procedures


Arithmetic primitives

In the following examples, e1, e2, etc. are arbitrary expressions. Brackets [...] indicate optional entries. Procedures evaluate their parameters from left to right.


Addition

(+ e1 e2 [e3...])

evaluates to: e1 + e2 [+ e3...]

example: (+ 7 12 4) evaluates to 23.


Multiplication

(* e1 e2 [e3...])

evaluates to: e1 (*e2[*e3...]

example: (* 2 10 3) evaluates to 60.


Subtraction

(- e1 e2)

evaluates to : e1 - e2

example: (- 20 11) evaluates to 9.


Division

(/ e1 e2)

evaluates to: e1 / e2

example: (/ 24 6) evaluates to 4. <---- Note: does this round when necessary (up, down)?


Remainder

(mod e1 e2)

evaluates to: the remainder of e1 when divided by e2.

example: (mod 17 5) evaluates to 2.


Operation Shift Left

(<< e1 e2)

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


Operation Shift Right

(>> e1 e2)

evaluates to: e1 >> e2 (as in << except with a right shift)

example: (>> 7 2) evaluates to 1.

In binary: 111 >> 2 = 001


Bitwise Exclusive OR Operator

(^ e1 e2 [e3...])

evaluates to: e1^ e2 [^ e3...]

example: (^ 11 26) evaluates to 17.

In binary: 01011" 11010 = 10001


Bitwise AND Operator

(& e1 e2 [e3...])

evaluates to: e1 &e2 [& e3...]

example: (& 11 26) evaluates to 10.     In binary: 01011 & 11010 = 01010


Bitwise OR Operator

(| e1 e2 [e3...])

evaluates to: e1 | e2 [| e3...]

example: (| 11 26) evaluates to 27.

In binary: 01011 111010 = 11011


Bitwise NOT

(~ e1)

evaluates to: the bitwise not of e1 (all 1 bits are changed to 0 and all 0 bits are changed to 1).

example: (~ 11) evaluates to -12.

In binary: ~01011 = 1111111111110100 (all the leading 0s in the 16 bit number change to 1s).





 

Notes


 

Table of Contents

 

< Previous: Table of ContentsNext: Files >