Skip to content

Commit

Permalink
added statements , functions,run
Browse files Browse the repository at this point in the history
  • Loading branch information
sudip-mondal-2002 committed Jun 27, 2021
1 parent f15465a commit 64563ee
Show file tree
Hide file tree
Showing 16 changed files with 1,994 additions and 253 deletions.
38 changes: 35 additions & 3 deletions Classes/Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,46 @@

TT_INT = 'INT'
TT_FLOAT = 'FLOAT'
TT_STRING = 'STRING'
TT_IDENTIFIER = 'IDENTIFIER'
TT_KEYWORD = 'KEYWORD'
TT_PLUS = 'PLUS'
TT_MINUS = 'MINUS'
TT_MUL = 'MUL'
TT_DIV = 'DIV'
TT_POW = 'POW'
TT_KEYWORD = 'KEYWORD'
TT_IDENTIFIER = 'IDENTIFIER'
TT_EQ = 'EQ'
TT_LPAREN = 'LPAREN'
TT_RPAREN = 'RPAREN'
TT_EOF = 'EOF'
TT_LSQUARE = 'LSQUARE'
TT_RSQUARE = 'RSQUARE'
TT_EE = 'EE'
TT_NE = 'NE'
TT_LT = 'LT'
TT_GT = 'GT'
TT_LTE = 'LTE'
TT_GTE = 'GTE'
TT_COMMA = 'COMMA'
TT_ARROW = 'ARROW'
TT_NEWLINE = 'NEWLINE'
TT_EOF = 'EOF'

KEYWORDS = [
'VAR',
'AND',
'OR',
'NOT',
'IF',
'ELIF',
'ELSE',
'FOR',
'TO',
'STEP',
'WHILE',
'FUN',
'THEN',
'END',
'RETURN',
'CONTINUE',
'BREAK',
]
35 changes: 16 additions & 19 deletions Classes/Error.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,48 @@
from error_line import *
from Classes.error_line import *


class Error:
def __init__(self, pos_start, pos_end, error_name, details):
self.pos_start = pos_start
self.pos_end = pos_end
self.error_name = error_name
self.details = details

def as_string(self):
result = f'{self.error_name}: {self.details}\n'
result = f'{self.error_name}: {self.details}\n'
result += f'File {self.pos_start.fn}, line {self.pos_start.ln + 1}'
result += '\n\n' + \
string_with_arrows(self.pos_start.ftxt,
self.pos_start, self.pos_end)
result += '\n\n' + string_with_arrows(self.pos_start.ftxt, self.pos_start, self.pos_end)
return result


class IllegalCharError(Error):
def __init__(self, pos_start, pos_end, details):
super().__init__(pos_start, pos_end, 'Illegal Character', details)

class ExpectedCharError(Error):
def __init__(self, pos_start, pos_end, details):
super().__init__(pos_start, pos_end, 'Expected Character', details)

class InvalidSyntaxError(Error):
def __init__(self, pos_start, pos_end, details=''):
super().__init__(pos_start, pos_end, 'Invalid Syntax', details)


class RunTimeError(Error):
class RTError(Error):
def __init__(self, pos_start, pos_end, details, context):
super().__init__(pos_start, pos_end, 'Run Time Error', details)
super().__init__(pos_start, pos_end, 'Runtime Error', details)
self.context = context

def as_string(self):
result = self.generate_traceback()
result += f'{self.error_name}: {self.details}\n'
result += \
string_with_arrows(self.pos_start.ftxt,
self.pos_start, self.pos_end)

result = self.generate_traceback()
result += f'{self.error_name}: {self.details}'
result += '\n\n' + string_with_arrows(self.pos_start.ftxt, self.pos_start, self.pos_end)
return result

def generate_traceback(self):
result = ""
result = ''
pos = self.pos_start
ctx = self.context
while ctx:
result = f'File {pos.fn}, line {pos.ln + 1}, {ctx.display_name}\n' + result
result = f' File {pos.fn}, line {str(pos.ln + 1)}, in {ctx.display_name}\n' + result
pos = ctx.parent_entry_pos
ctx = ctx.parent
return "Traceback recent calls: "+result

return 'Traceback (most recent call last):\n' + result
Loading

0 comments on commit 64563ee

Please sign in to comment.