Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
d62d37b
Nesting instruction support, assignment in expressions, handling synt…
luthanhar Feb 9, 2025
8f06dc9
Adding print command
luthanhar Feb 9, 2025
48b5d65
adding list support (nested)
luthanhar Feb 9, 2025
180f066
class addition (without nested internal declaration, no nested class …
luthanhar Feb 10, 2025
0020c21
provision for functional programming
manandraj20 Feb 19, 2025
ed51e6c
returning values from functions now supported
manandraj20 Feb 19, 2025
aeff813
rangoli code added
manandraj20 Feb 20, 2025
ebf8a68
real number issue fixed
manandraj20 Feb 20, 2025
06adbe4
function call with array assignment
manandraj20 Feb 20, 2025
6455bb2
recursive expression temporary registers used
manandraj20 Feb 20, 2025
9cf55e9
all working
manandraj20 Feb 20, 2025
f123b4b
object nesting
manandraj20 Mar 3, 2025
15ed551
inheritance on member variables and method call done!
manandraj20 Mar 4, 2025
cfe287a
inheritance now supported
manandraj20 Mar 17, 2025
f7a0f51
Add demo test cases for functions, class methods, and inheritance
its-me-yps Mar 19, 2025
8201822
[bug fix for method call]
manandraj20 Mar 19, 2025
d81aa5b
updated grammar
manandraj20 Mar 19, 2025
2886a5b
[bug fix] class with no attribute
manandraj20 Mar 20, 2025
36a50be
[bug fix] instance level attributes
manandraj20 Mar 21, 2025
48a3ac0
Encapsulation with MRO
manandraj20 Mar 21, 2025
a74cae5
example on encapuslation
manandraj20 Mar 21, 2025
39e4aa9
adding comments
manandraj20 Mar 21, 2025
cbd0c53
diamond problem example added
manandraj20 Apr 3, 2025
d939e44
instruction and declaration separated
manandraj20 Apr 4, 2025
bd709ba
function overloading now supported
manandraj20 Apr 5, 2025
44c9cbc
example on function overloading
manandraj20 Apr 5, 2025
0cdb146
code commenting supported and private method supported
manandraj20 Apr 5, 2025
a35157f
feature: add test script
its-me-yps Apr 7, 2025
cf30f03
fixed duplicate addition of intermediate instructions
manandraj20 Apr 7, 2025
e374d81
code commenting and refactoring
manandraj20 Apr 7, 2025
ce0176e
Grammar change, removing ambiguity, refactoring code, expression is n…
luthanhar Apr 16, 2025
8baf4a9
Merge remote-tracking branch 'upstream/master'
luthanhar Apr 17, 2025
ee2ea6d
[feature] visualize class hierarchy with -ch flag
its-me-yps Apr 20, 2025
ad07cd0
changed grammar
luthanhar Apr 20, 2025
f9c2654
changed grammar and examples
luthanhar Apr 20, 2025
efa22d4
grammar change
luthanhar Apr 20, 2025
6cc1a55
[feature] visualize class hierarchy with -ch flag
its-me-yps Apr 20, 2025
74ee23b
correcting object initialisation
luthanhar Apr 21, 2025
511ed40
object initialisation inside classes
luthanhar Apr 21, 2025
4828f9d
object initialisation inside class
luthanhar Apr 21, 2025
7f40035
demo example upload
luthanhar Apr 21, 2025
2da1868
class herirrarchy changes
luthanhar Apr 21, 2025
19c3444
object instantition inside classes and class heirarchy diagram
luthanhar Apr 21, 2025
8bf84d7
added new issues
manandraj20 Apr 21, 2025
e579edb
private attributes in ch diagram
luthanhar Apr 21, 2025
3f6fc81
small feature
luthanhar Apr 21, 2025
cb51f7c
feature enchancement
luthanhar Apr 21, 2025
039c989
minor enhancement and examples
luthanhar Apr 21, 2025
e825edc
minor improve
luthanhar Apr 22, 2025
13155f5
adding examples
luthanhar Apr 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 142 additions & 1 deletion ChironCore/ChironAST/ChironAST.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ class Instruction(AST):
pass


class PrintCommand(Instruction):
def __init__(self, expr):
self.expr = expr

def __str__(self):
return self.expr.__str__()


class AssignmentCommand(Instruction):
def __init__(self, leftvar, rexpr):
self.lvar = leftvar
Expand All @@ -21,6 +29,20 @@ def __str__(self):
return self.lvar.__str__() + " = " + self.rexpr.__str__()


class ClassDeclarationCommand(Instruction):

def __init__(self, className, baseClasses, attributes, objectAttributes):
self.className = className # Class name as a string
self.attributes = attributes # List of AssignmentCommand objects
self.objectAttributes = objectAttributes
self.baseClasses = baseClasses

def __str__(self):
attr_str = "\n ".join(str(attr) for attr in self.attributes)
obj_attr_str = "\n ".join(str(attr[0]) for attr in self.objectAttributes)
return f"class {self.className} {{\n {attr_str if attr_str else ' // No attributes'}\n\n {obj_attr_str if obj_attr_str else ' // No object attributes'}\n}}"


class ConditionCommand(Instruction):
def __init__(self, condition):
self.cond = condition
Expand All @@ -29,13 +51,16 @@ def __str__(self):
return self.cond.__str__()

# Not Implemented Yet.


class AssertCommand(Instruction):
def __init__(self, condition):
self.cond = condition

def __str__(self):
return self.cond.__str__()


class MoveCommand(Instruction):
def __init__(self, motion, expr):
self.direction = motion
Expand All @@ -52,6 +77,7 @@ def __init__(self, penstat):
def __str__(self):
return self.status


class GotoCommand(Instruction):
def __init__(self, x, y):
self.xcor = x
Expand All @@ -60,26 +86,76 @@ def __init__(self, x, y):
def __str__(self):
return "goto " + str(self.xcor) + " " + str(self.ycor)


class NoOpCommand(Instruction):
def __init__(self):
pass

def __str__(self):
return "NOP"


class PauseCommand(Instruction):
def __init__(self):
pass

def __str__(self):
return "pause"


class FunctionDeclarationCommand(Instruction):
def __init__(self, fname, params=None, body=None):
self.name = fname
self.params = params if params is not None else []
self.body = body if body is not None else []

def __str__(self):
params_str = ", ".join(self.params)
body_str = "\n ".join(str(stmt) for stmt in self.body)
return f"def {self.name}({params_str}):\n {body_str}"


class FunctionCallCommand(Instruction):
def __init__(self, fname, arguments=None, caller = None):
self.name = fname
self.args = arguments if arguments is not None else []
self.caller = caller

def __str__(self):
args_str = ", ".join(str(arg) for arg in self.args)
if self.caller:
return f"{self.caller}.{self.name}({args_str})"
else:
return f"{self.name}({args_str})"


class ReturnCommand(Instruction):
def __init__(self, returnValues):
self.returnValues = returnValues
def __str__(self):
return f"return {self.returnValues}"

class ReadReturnCommand(Instruction):
def __init__(self, returnValues):
self.returnValues = returnValues
def __str__(self):
return f"read {self.returnValues}"


class ParametersPassingCommand(Instruction):
def __init__(self, parameters):
self.params = parameters

def __str__(self):
return ", ".join(str(param) for param in self.params)


class Expression(AST):
pass


# --Arithmetic Expressions--------------------------------------------


class ArithExpr(Expression):
pass

Expand Down Expand Up @@ -122,6 +198,7 @@ class Mult(BinArithOp):
def __init__(self, lexpr, rexpr):
super().__init__(lexpr, rexpr, "*")


class Div(BinArithOp):
def __init__(self, lexpr, rexpr):
super().__init__(lexpr, rexpr, "/")
Expand All @@ -147,6 +224,7 @@ class AND(BinCondOp):
def __init__(self, expr1, expr2):
super().__init__(expr1, expr2, "and")


class OR(BinCondOp):
def __init__(self, expr1, expr2):
super().__init__(expr1, expr2, "or")
Expand Down Expand Up @@ -226,10 +304,73 @@ def __init__(self, v):
def __str__(self):
return str(self.val)

class Real(Value):
def __init__(self, v):
self.val = float(v)

def __str__(self):
return str(self.val)


class Var(Value):
def __init__(self, vname):
self.varname = vname

def __str__(self):
return self.varname


class Array(Value):
def __init__(self, vname):
self.arr = vname

def __str__(self):
return self.arr

# class ArrayAccess(Value):
# def __init__(self, var, index):
# self.var = var
# self.idx = index

# def __str__(self):
# indices_str = "".join(f"[{idx}]" for idx in self.idx) # Format multiple indices
# return f"{self.var}{indices_str}"
# # return self.var.__str__() + "[" + self.idx.__str__() + "]"


class DataLocationAccess(Value):
def __init__(self, var, access_chain):
self.var = var
self.access_chain = access_chain # List of attribute names or indices

def __str__(self):
result = str(self.var)
for access in self.access_chain:
if isinstance(access, list): # Array indexing
indices_str = "".join(f"[{idx}]" for idx in access)
result += indices_str
else: # Object attribute access
result += f".{access}"
return result

class MethodCaller:
def __init__(self, access_chain):
self.access_chain = access_chain

def __str__(self):
result = ""
for access in self.access_chain:
if isinstance(access, list): # Array indexing
indices_str = "".join(f"[{idx}]" for idx in access)
result += indices_str
else: # Object attribute access
result += f".{access}"
return result[1:]

class ObjectInstantiationCommand(Instruction):
def __init__(self, target, class_name):
self.target = target # Variable name or Object/Array Access
self.class_name = class_name # The class being instantiated

def __str__(self):
return f"{self.target} = new {self.class_name}()"
Loading