Skip to content

Support for object-oriented design features in Chiron Framework#14

Open
luthanhar wants to merge 50 commits into
PRAISE-group:cs335_oops_221223from
manandraj20:master
Open

Support for object-oriented design features in Chiron Framework#14
luthanhar wants to merge 50 commits into
PRAISE-group:cs335_oops_221223from
manandraj20:master

Conversation

@luthanhar

Copy link
Copy Markdown

Pull Request Template for Feature Additions.

Brief description feature

Provide the details of the feature, explain it's functionality.

Added following features:  
1)  Array and List 
2)  Nested assignments and expression support in conditions
3)  Functions (Overloading, Recursion)
4) Classes (Inheritence, Static Polymorphism, encapsulation(private, public),nested object access)

Example

Give a test case and related commands that show the utility of the feature.

def sqroot(:n)
{
    if (:n == 0) [ 
        return 0 
        ]
    if (:n == 1) [ 
        return 1 
        ]
    
    :low = 0
    :high = :n
    :ans = 0
    :epsilon = 0.0001  
    repeat 50 [ 
        :mid = (:low + :high) / 2
        :square = :mid * :mid
        
        if (:square == :n) [
            return :mid
        ]
        
        if (:square < :n) [
            :low = :mid
            :ans = :mid 
        ]
        else [
            :high = :mid
        ]
        
        if ((:high - :low) < :epsilon) [
            return :ans
        ]
    ]
    return :ans
}

def drawRangoli(:size)
{
    pendown
    forward :size
    left 90
    forward :size
    left 90
    forward :size
    left 90
    forward :size
    penup

    left 90
    forward :size/2
    left 45
    :size = sqroot((:size * :size ) / 2)
    if :size > 10
     [ drawRangoli(:size) ]
    return 100
}

class :Point {
    :x = -300
    :y = -300
}
penup
:point = new :Point()
goto (:point.:x, :point.:y)
:size=200
drawRangoli(:size)
Running Command: python3 ./chiron.py -r ./filename.tl

Please add a atleast 3 test cases to the repository which shows how the feature works and what are the outcomes.

Test-1 : Class inheritence

class :Shape {
    :length = 250
}

class :Triangle(:Shape) {
    :sides = 3
}

:tri = new :Triangle()
:count = 0
repeat :tri.:sides [
    forward :tri.:length
    right 120
    :count = :count + 1
]

Output: Triangle drawn

Test-2 Expressions in If else and nested assignments

if  :x=0 == :y=:z=3 [
    print(2)
]
else [
    print(:x)
]

Output: 0 is printed

Test-3 Class: Encapsulation

class :Shape {
    :length = 250
    def moveForward(:self) 
    {
        forward :self.:length
        return 0
    }
}

class :Hexagon(:Shape) {
    :sides = 6
    def drawHex(:self) {
        repeat :self.:sides [
            :self.moveForward()
            right 60
        ]
        return 0
    }
    def __moveForward(:self, :distance) {
        forward :distance
        return 0
    }
}

:hex = new :Hexagon()
:hex.drawHex()
# This does not work #
:hex.__moveForward(100) 

Output: Hexagon will be drawn but on accessing the private function moveForward leads to error

Why is the feature interesting?

Give use cases for the feature.

1) Complex shapes can be drawn by writing simple and readable code by the use of functions and classes
2) Grammar is more robust and generalised, for example :x=3 is an expression and returns a value which can be used in if conditions

Screenshots

Please add screenshots whenever possible.

Other Details

Please add additional details that you want the developers to be aware of about the feature. Eg. good use cases (if any).

@lahiri-phdworks
lahiri-phdworks self-requested a review April 17, 2025 09:53
@lahiri-phdworks lahiri-phdworks added the enhancement New feature or request label Apr 17, 2025
@lahiri-phdworks lahiri-phdworks linked an issue Apr 17, 2025 that may be closed by this pull request
@lahiri-phdworks lahiri-phdworks changed the title OOPS support in Kachua Support for object-oriented design features in Chiron Framework Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dumping error for .tl file.

4 participants