Laid initial nim project structure and fixed a bug with inheritance

This commit is contained in:
nocturn9x 2020-08-02 11:04:01 +02:00
parent cd1b8e937f
commit 93ae32f54c
15 changed files with 14 additions and 6 deletions

View File

@ -401,7 +401,10 @@ class Parser(object):
while True:
if len(parameters) >= 255:
raise self.throw(self.peek(), "Cannot have more than 255 arguments")
parameters.append(self.consume(TokenType.ID, "Expecting parameter name"))
parameter = self.consume(TokenType.ID, "Expecting parameter name")
if parameter in parameters:
raise self.throw(self.peek(), "Multiple parameters with the same name in function declaration are not allowed")
parameters.append(parameter)
if not self.match(TokenType.COMMA):
break
self.consume(TokenType.RP, "Unexpected error while parsing function declaration")

View File

@ -17,8 +17,11 @@ class JAPLClass(Callable):
def get_method(self, name: str):
if name in self.methods:
return self.methods[name]
elif self.superclass and name in self.superclass.methods:
return self.superclass.methods[name]
superclass = self.superclass
while superclass:
if name in superclass.methods:
return superclass.methods[name]
superclass = superclass.superclass
def __repr__(self):
return f"<class '{self.name}'>"

View File

@ -5,6 +5,8 @@ fun fib(n) {
return fib(n - 2) + fib(n - 1);
}
for (var i = 0; i < 20; i = i + 1) {
print fib(i);
}
var start = clock();
fib(30);
var end = clock() - start;
print(end);

0
nimjapl/interpreter.nim Normal file
View File

0
nimjapl/lexer.nim Normal file
View File

View File

View File

View File

View File

View File

0
nimjapl/parser.nim Normal file
View File

View File

0
nimjapl/types/class.nim Normal file
View File

View File

View File