Skip to content

Commit

Permalink
python fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PandaWhoCodes committed Nov 17, 2018
1 parent bc38604 commit 57f77cd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
7 changes: 4 additions & 3 deletions modiscript/MODI
Expand Up @@ -32,19 +32,20 @@ def execute(filename):
def main():
if len(sys.argv) < 2 or '-h' in sys.argv or '--help' in sys.argv:
usage()

filename = sys.argv[-1]
#filename = "modi.chai"
# filename = "modi.chai"
if '-d' in sys.argv or '--debug' in sys.argv:
global DEBUG
DEBUG = True

# check existence
if not os.path.isfile(filename):
raise ErrorHandler(FNF, filename)
# execute
execute(filename)


if __name__ == '__main__':
try:
main()
Expand Down
Binary file added modiscript/__pycache__/utils.cpython-36.pyc
Binary file not shown.
20 changes: 5 additions & 15 deletions modiscript/lexer.py
@@ -1,4 +1,4 @@
from utils import *
from utils import LEX, ErrorHandler, ERROR, CONGRESS_RULE, STARTING_TROUBLE, MISQUOTE, WORDS
import re
import sys

Expand All @@ -23,18 +23,8 @@ def lexeme(lex, value=None, line=0, offset=0):

@staticmethod
def normalize(word):
if word == 'nahin':
word = 'nahi'
elif word == 'tho':
word = 'toh'
elif word == 'bhayyo':
word = 'bhaiyo'
elif word == 'beheno':
word = 'behno'
elif word == 'thak':
word = 'tak'
elif word == 'jyada':
word = 'zyada'
if word in WORDS:
word = WORDS[word]
elif mitrooon.search(word):
word = 'mitrooon'
elif acche.search(word):
Expand Down Expand Up @@ -193,6 +183,6 @@ def _analyze_lexemes(self):
yield Lexer.lexeme(*lex)
self.stack = []
self.clear = False
if sys.version_info >= (3,7):
return
if sys.version_info >= (3, 7):
return
raise StopIteration()
10 changes: 6 additions & 4 deletions modiscript/parser.py
@@ -1,5 +1,5 @@
from ast import *
from utils import *
from utils import LEX, ErrorHandler, ERROR, CONGRESS_RULE


class Parser:
Expand Down Expand Up @@ -122,7 +122,7 @@ def _analyze_print(self, num):
new_num, node = self._analyze_expr(num + 1)
if node is not None:
return new_num, Expr(value=Call(func=Name(id='print', ctx=Load()),
args=[node], keywords=[]), **self._debug_details(num))
args=[node], keywords=[]), **self._debug_details(num))
return num + 1, None

def _analyze_until(self, num):
Expand Down Expand Up @@ -267,7 +267,8 @@ def _analyze_b(self, num):
elif lexeme['lex'] == LEX['<']:
op = Gt(**self._debug_details(num))
op = Compare(left=prev, ops=[op], comparators=[node], **self._debug_details(num))
if new_num + 1 < self.length and self.lex[new_num + 1]['lex'] == LEX['var'] and self.lex[new_num + 1]['value'] == 'nahi':
if new_num + 1 < self.length and self.lex[new_num + 1]['lex'] == LEX['var'] and self.lex[new_num + 1][
'value'] == 'nahi':
new_num += 1
op = UnaryOp(op=Not(), operand=op, **self._debug_details(new_num))
if new_num < self.length and self.lex[new_num]['lex'] == LEX['hai']:
Expand All @@ -293,7 +294,8 @@ def _analyze_b(self, num):
elif lexeme['lex'] == LEX['!=']:
op = NotEq(**self._debug_details(new_num))
op = Compare(left=prev, ops=[op], comparators=[node], **self._debug_details(num))
if new_num + 1 < self.length and self.lex[new_num + 1]['lex'] == LEX['var'] and self.lex[new_num + 1]['value'] == 'nahi':
if new_num + 1 < self.length and self.lex[new_num + 1]['lex'] == LEX['var'] and self.lex[new_num + 1][
'value'] == 'nahi':
new_num += 1
op = UnaryOp(op=Not(), operand=op, **self._debug_details(new_num))
if new_num + 1 < self.length and self.lex[new_num + 1]['lex'] == LEX['hai']:
Expand Down
9 changes: 9 additions & 0 deletions modiscript/utils.py
Expand Up @@ -40,6 +40,15 @@
'false': 105
}

WORDS = {
"nahin": "nahi",
"tho": "toh",
"bhayyo": "bhaiyo",
"beheno": "behno",
"thak": "tak",
"jyada": "zyada"
}


def usage():
print("Usage:", PROGRAM, "[options]", "filename")
Expand Down

0 comments on commit 57f77cd

Please sign in to comment.