Simple Pure ObjectOriented Language - PowerPoint PPT Presentation

1 / 39
About This Presentation
Title:

Simple Pure ObjectOriented Language

Description:

alphabetic ::= Any of the 52 uppercase or lowercase letters of the alphabet, ... character ::= Any printable character. Notes about the translator ... – PowerPoint PPT presentation

Number of Views:372
Avg rating:3.0/5.0
Slides: 40
Provided by: patrickj6
Category:

less

Transcript and Presenter's Notes

Title: Simple Pure ObjectOriented Language


1
Simple Pure Object-Oriented Language
  • The Design

By Patrick J. Sparrow
2
Outline
  • Overview of the project
  • A simple SPOOL program
  • The translator
  • The library of Java classes

3
Overview
  • The Simple Part
  • The Pure Part
  • The Advantages of such a language

4
The Simple Part
  • Simple LISP-like Syntax
  • Allow definition of classes and methods
  • The Java Standard Library
  • Translate source code to Java

5
Simple Syntax
  • No punctuation other than parentheses
  • Sequences of expressions nested in lists
  • Case sensitive due to Java

6
Classes and Methods
  • CLASS and METHOD reserved words
  • (CLASS Clock Object (
  • .))
  • (METHOD getTime String ( ) (
  • .))

7
The Java Standard Library
  • (CONSTRUCT String S Hello)
  • (SET S value Goodbye)
  • (CALL S toLowercase ( ))

8
Translate to Java
  • Translator written in Java
  • Whole project under one language
  • Java provides good parsing support
  • Further discussion later on

9
The Pure Part
  • Create a library of new abstract classes
  • Treat everything as an object

10
Abstract Library
  • Extend Javas Wrapper classes
  • Keyboard and Monitor classes
  • Program and Process classes
  • Array and Bit classes

11
Treat everything as an object
  • Disallow Javas intrinsic types
  • Only literals allowed are strings
  • Handle logic functions through the objects
    methods

12
Advantages
  • Completely object-oriented
  • Uniformity
  • Portability

13
Questions?
  • Basic description of the project
  • Simple syntax
  • Pure object-orientation

14
A simple SPOOL program
  • (CLASS MyProgram Object (
  • (METHOD STATIC main void ( ) (
  • (CONSTRUCT WholeNumber a)
  • (NEW WholeNumber a (CALL Keyboard input( )))
  • (CONSTRUCT WholeNumber b)
  • (NEW WholeNumber b (CALL Keyboard input( )))
  • (CONSTRUCT WholeNumber c (CALL WholeNumber
    add (a b)))
  • (CALL Monitor output (c))
  • ))
  • ))

15
The Translator
  • Recurse through each expression and convert it to
    correct Java code
  • Write each expression to a .java file
  • Each step of the recursive process is based on
    the grammatical rules of the language

16
Grammatical Rules
  • ltprogramgt ltexpressiongt ltprogramgt
    ltexpressiongt
  • ltexpressiongt ltatomgt ltlistgt lts_importgt
    lts_constructgt lts_newgt lts_callgt lts_setgt
    lts_classgt lts_methodgt lts_whilegt lts_ifgt
    lts_notgt lts_orgt lts_andgt lts_returngt

17
If / While
  • lts_whilegt WHILE ( ltconditiongt ) ltlistgt
  • lts_ifgt IF lts_ifstatementgt
  • lts_ifstatementgt ( ltconditiongt ltlistgt)
  • ( ltconditiongt ltlistgt) lts_ifstatementgt

18
And, Or, Not
  • lts_notgt NOT ( ltconditiongt )
  • lts_orgt OR ( ltconditiongt ) ( ltconditiongt )
  • lts_andgt AND ( ltconditiongt ) ( ltconditiongt )
  • ltconditiongt ltexpressiongt

19
Java Class Support
  • lts_importgt IMPORT ltstringgt
  • lts_constructgt CONSTRUCT ltobjecttypegt ltnamegt
    ltargumentsgt CONSTRUCT ltobjecttypegt ltnamegt
  • lts_newgt NEW ltobjecttypegt ltnamegt ltargumentsgt
  • lts_callgt CALL ltnamegt ltmethodgt ltargumentsgt
  • CALL ltobjecttypegt
    ltmethodgt ltargumentsgt
  • lts_setgt SET ltnamegt ltinstancevariablegt ltvaluegt

20
Java Class Support
  • ltnamegt ltidentifiergt
  • ltobjecttypegt ltidentifiergt
  • ltargumentsgt ltlistgt ltstringgt
  • ltmethodgt ltidentifiergt
  • ltinstancevariablegt ltidentifiergt
  • ltvaluegt ltstringgt ltlistgt

21
Class and Method support
  • lts_classgt CLASS ltnamegt ltparentclassgt ltlistgt
  • lts_methodgt METHOD ltmodifiergt ltnamegt
    ltreturntypegt ltargumentsgt ltlistgt METHOD
    ltnamegt ltreturntypegt ltargumentsgt ltlistgt
  • lts_returngt RETURN ltnamegt RETURN ltlistgt
  • ltparentclassgt ltidentifiergt
  • ltmodifiergt STATIC
  • ltreturntypegt ltidentifiergt

22
Lower Level Rules
  • ltlistgt ( ) ( ltsequencegt )
  • ltsequencegt ltexpressiongt ltsequencegt
    ltexpressiongt
  • ltatomgt ltidentifiergt ltstringgt
  • ltidentifiergt ltalphabeticgt ltrestgt
    ltalphabeticgt
  • ltrestgt ltnextgt ltrestgt ltnextgt
  • ltnextgt ltalphabeticgt ltdigitgt
  • ltalphabeticgt Any of the 52 uppercase or
    lowercase letters of the alphabet, , _
  • ltdigitgt 0 1 2 3 4 5 6 7 8 9
  • ltstringgt ltcharsequencegt
  • ltcharsequencegt ltcharactergt ltcharsequencegt
    ltcharactergt
  • ltcharactergt Any printable character

23
Notes about the translator
  • Everything will be public in this version
  • Main method will be checked for and handled
    correctly
  • Main method code will be put in a try statement
    for exception handling

24
Questions?
  • Grammatical Rules
  • How certain Java features can be used

25
Simple SPOOL Program
  • (CLASS MyProgram Object (
  • (METHOD STATIC main void ( ) (
  • (CONSTRUCT WholeNumber a)
  • (NEW WholeNumber a (CALL Keyboard input( )))
  • (CONSTRUCT WholeNumber b)
  • (NEW WholeNumber b (CALL Keyboard input( )))
  • (CONSTRUCT WholeNumber c (CALL WholeNumber
    add (a b)))
  • (CALL Monitor output (c))
  • ))
  • ))

26
The Translated Code
  • public class MyProgram extends Object
  • public static void main (String args)
  • try
  • WholeNumber a
  • a new WholeNumber(Keyboard.input())
  • WholeNumber b
  • b new WholeNumber(Keyboard.input())
  • WholeNumber c new WholeNumber(WholeNumber.
    add(a,b))
  • Monitor.output(c)
  • catch (Exception e)
  • Monitor.output(e.getMessage())

27
A More Involved Program
  • (CLASS Fibonacci Object (
  • (METHOD STATIC main void ( ) (
  • (CONSTRUCT WholeNumber x (CALL Keyboard
    input( ))
  • (CALL Monitor output (CALL Fibonacci f
    (x))))
  • )
  • (METHOD STATIC f WholeNumber (WholeNumber n) (
  • (CONSTRUCT WholeNumber result)
  • (IF ((CALL n lessThan (CALL WholeNumber
    fromString 2)) (
  • (NEW WholeNumber result 1)
  • (RETURN result)))
  • (T (
  • (NEW WholeNumber result (CALL
    WholeNumber add(
  • (CALL Fibonacci f (CALL
    WholeNumber subtract (n (CALL WholeNumber
    fromString 1))))
  • (CALL Fibonacci f (CALL
    WholeNumber subtract (n (CALL WholeNumber
    fromString 2)))))))
  • (RETURN result)))
  • )
  • ))

28
The Java Version
  • public class Fibonacci extends Object
  • public static void main (String args)
  • try
  • WholeNumber x new WholeNumber(
    Keyboard.input())
  • Monitor.output(Fibonacci.f(x))
  • catch (Exception e)
  • Monitor.output(e.getMessage())
  • public static WholeNumber f (WholeNumber n)
    throws Exception
  • WholeNumber result
  • if (n.lessThan(WholeNumber.fromString(2)))
  • result new WholeNumber(1)
  • return result
  • else
  • result new WholeNumber(WholeNumber.add(

  • Fibonacci.f(WholeNumber.subtract(n,
    WholeNumber.fromString(1),

  • Fibonacci.f(WholeNumber subtract(n,
    WholeNumber.fromString(2))

29
Questions?
  • Program examples
  • Translation issues

30
The Library
  • Extend Javas Wrapper classes
  • Keyboard and Monitor classes
  • Program and Process classes
  • Array and Bit classes

31
All Wrapper Classes
  • Constructed from String or intrinsic value
  • fromString method to parse a String for the
    corresponding intrinsic type
  • getValue method to uniformly get the intrinsic
    value
  • getType method to easily obtain a String
    containing what type of object it is

32
The Constructor
  • (CONSTRUCT WholeNumber X 77)
  • WholeNumber X new WholeNumber(77)
  • (CONSTRUCT WholeNumber X)
  • WholeNumber X
  • (CONSTRUCT WholeNumber X ( ))
  • ERROR no such constructor method
  • (NEW WholeNumber X 77)
  • X new WholeNumber(77)

33
Integers and Doubles
  • Integer ? WholeNumber
  • Double ? RealNumber
  • Add, Subtract, Multiply, Divide, Mod
  • LT, GT, EQ, LE, GE
  • Must be used to replace Wrappers if any
    arithmetic of logical methods are to be called

34
Strings
  • String ? ExtString
  • Rebuild charAt method to return a String
    containing the character

35
Booleans
  • Boolean ? Bool
  • No changes besides the ones included in all
    Wrapper classes

36
The Keyboard and Monitor Classes
  • Keyboard uses a BufferedReader for the keyboard
    to read and return Strings
  • Monitor uses Javas System.out methods to
    uniformly output lines of text to the computer
    screen

37
Program and Process classes
  • Program allows an actual program to be treated as
    an object, storing the author and date, along
    with the source code for the program.
  • Process extends Program to treat a running
    program as an object, storing a timestamp and
    allowing the hibernation of a running program.

38
Bit Class and Array Class
  • Bit extends WholeNumber to perform all the
    bitwise math and logic functions
  • Array will allow abstract arrays of Objects to be
    created. It will handle all of the operations
    performed on regular Java arrays, only in a more
    uniform way.

39
Questions???
Write a Comment
User Comments (0)
About PowerShow.com