[Skip Navigation] [CSUSB] / [CNS] / [Comp Sci & Eng Dept] / [R J Botting] /[CS320 Course Materials] /SOOP1.html [SOOP1.txt(Text)] [Search ]
Tue Apr 7 10:56:39 PDT 2009
[Schedule] [Syllabi] [Text] [Labs] [Projects] [Resources] [Grading] [Contact]
Notes: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]


    SOOP -- Simple Object-Oriented Programming

      Author -- R J Botting Wed Dec 20 11:54:08 PST 2006

      Status -- Preliminary Draft Proposal

      There are many deliberate omissions, stupid ideas, and even typographical errors to fix.

      Goal -- The Simplest Possible Object Oriented Language

      SOOP is more object-based than object-oriented because classes take a back seat to objects.

      Example program:

       	{"Hello, World!"!;end}

      More examples below: [ Extended Examples ]

      Syntax and Informal Semantics


        The following strings are important parts of the language that are used in more complicated syntactic structures.
      1. identifier::= letter #(letter|digit|"_"). Letter and digit are defined in XBNF as the normal ASCII letters A-Z and a-z, and the decimal digits 0-9.
      2. operator::= symbol #(symbol).
      3. symbol::="!" | "@" | "#" | ... .
      4. vertical_bar::="|".
      5. semicolon::=";".
      6. backslash::="\\".


      8. constant::= number | string | Boolean | null. Constants represent objects that are members of predefined classes:
        (Predefined Classes): following
        • Number: Integer values, understands arithmetic operations like addition and subtraction.
        • String: Finite sequences of characters, understands how to be concatenated, etc.
        • Boolean: True or false, understands conjunction, disjunction, negation, etc.
        • Compound: has many parts with "@" and "#" to access them.
        • Null: has no knowledge or know how except how to accept data and methods.
        Note: all objects know how to add data and methods to derive new objects with new behaviors. They also know how to output themselves. Predefined methods are listed later.

      9. number::=O(sign) N(digit).
      10. string::=quotes #(char ~ quotes) quotes.
         		"hello world"
      11. Boolean::= "true" | "false".
      12. null::= "new".

      13. symbolic_id::=N(symbolic_character) | symbol.
      14. symbolic_character::="+" | "-" | "*" | "/" | "=" |"<" | ">" | "!" | "%" | "^" | backslash | "&" | "?".

      15. string::= quotes #(char~quotes) quotes.

        Classes and Programs

      16. class_definition::= class_id "=" "{" #(method | data_field) "}".
        	Widgets={type=""; setType{type=$@1;}};
      17. class_id::=identifier.

        A class is a list of new data and methods that can be added to an existing object. Al objects know how to extend themselves with new methods and data. So

         	new Widget
        creates a null object and adds an item of data (type) and a method to change it.

        A class is a collection of such methods and data fields. Here is a single an example with one data field and one method:

        	{type=""; setType {type=$@1; end} };

      18. method::= message program.
         	count{ n=n+1;end}
      19. message::=identifier.

      20. data_field::= variable "=" initial_value semicolon.
      21. initial_value::=expression.


      22. program::= "{" scenario # extension "}".

        Here is a simple one scenario program describing a simple calculation

         	{delta = b*b - 4 * a * c; end}
        Here is another
         	{tmp=a; a=b; b=tmp; end}
        A scenario is, in general, a sequence of commands and methods. A program has many scenarios that are tried in turn. The later scenarios are called extensions -- see below.

        Here is a three scenario program which is part of solving a quadratic equation. It has a main scenario and two extensions.

        	{delta==0; equalRoots; end | delta>0; realRoots; end | delta<0; complexRoots; end };

      23. extension::= vertical_bar scenario.

        A program executes a series of scenarios until one of them completes. A scenario can fail if an expression produces "false" as a final result or if all sub-scenarios fail.

        If a scenario fails then the following "extension" is tried in turn.

      24. scenario::= #(command | method) O(value | repeat | end).
      25. value::=expression.
      26. repeat::="repeat".
      27. end::="end".
      28. command::=O(labeled) expression semicolon.
      29. labeled::= variable "=".

        Control Structures

        SOOP does not need special control structures like if-then-else and while. A programer can use the above "program" structure to express them.

        (while_loop): { condition; body; repeat | end}
        (if_then_else_selection): { condition; ifTrue; end | ifFalse; end }
        (for_loop): { index=first; {condition; body; index=next; repeat | end}; end}


      30. expression::=O(object) #(message O(parameter) | program).
         	n odd
         	aStudent drops( aClass )

        If the first object is omitted then the object 'this' is assumed as the default. This has the effect of (1) allowing subprogram calls inside a class, (2) treating data items in an object as variables.


      31. object::=variable | constant | this | formal_parameter | compound.
      32. this::= "this".
      33. formal_parameter::="$" .

        Methods and Messages

        Methods in SOOP have a single formal parameter that is symbolized by a dollar sign. However, the actual parameter is nearly always a compound object. Often they are lists and so strings like "$@1" refer to the first object in the parameter.
      34. compound::= list | program. Compound objects have an at and an number method.
      35. at::= "@". This method selects parts of the compound.
         	(2,3,4)@1 == 2
         	{a=1; b=2;}@a == 1

        i>0i'th part of c
        i==0the whole of c
        i<0all parts of c without the i'th part

        (Close Table)
         	(2,3,4)@1 == 2
         	(2,3,4)@0 == (2,3,4)
         	(2,3,4)@(-1) == (2,3)

      36. number::= "#".
         	(2,3,4)# == 3

      37. parameter::=object.

      38. list::="(" L(command)")".

      39. message::=identifier|operator.

        Extended Examples

        Here is an object that knows how to count things:
         	theCount= new { value=0; counts{value=value+1;}; get{value}; }
        and here is how it might be used
        	theCount counts;
         	theCount counts;
         	theCount get;
        The last action returns the number 2.

        The following creates a new object with two data items and two methods:

        	widget= new {knobs=0; name=""; addKnob{knobs=knobs+1;}; setID{name=$@1;}};

        The following applies the methods to the object.

        	widget addKnob; widget setID ("ax123c");

        	wodget= widget{type=""; setType{type=$@1;}};
        Extends the widget object by adding a type attribute and an operation to operate on it.

        Conditions and loops

         	Hailstone={n==1; end | n even; n=n/2; repeat| n=n*3+1; repeat}

         	sum={s=0; n=1; { n>$@#; s | s=s+$@n; repeat }; s}

         	{d>0; d=d-a;  end| d=d+b; end}

         	{n<=0;  end| n=n-1; oneStep; repeat}

         	Bresenham={a=?;b=?; d=?; n=?;
         		{n<=0;  end
         		| n=n-1;
         			{d>0; d=d-a; diagonal; end
         			| d=d+b; axis; end

        An incomplete class for handling fractions like 1/2 and 37/48:

         Fraction={numerator=0; denominator=1;
         	*{new Fraction set (numerator * $@numerator, denominator * $@denominator)};
         	. . .

      . . . . . . . . . ( end of section Syntax) <<Contents | End>>

      Predefined Messages

        SymbolMeaningClass ParameterProduces
        !output Number, String, Boolean,
        <less thanAllsameBoolean
        >less thanAllsameBoolean
        #number parts inCompound-Number
        . . .

        (Close Table)


      XBNF Syntax Meta-Language

    1. O::=Optional.
    2. N::=one or more.
    3. char::=ASCII code character.
    4. #::=any number of including none.