Skip to content

Commit

Permalink
Run autopep8 on example/
Browse files Browse the repository at this point in the history
  • Loading branch information
qyearsley authored and dabeaz committed Aug 30, 2016
1 parent 481413e commit 9e2b80e
Show file tree
Hide file tree
Showing 20 changed files with 1,448 additions and 983 deletions.
46 changes: 20 additions & 26 deletions example/BASIC/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#

import sys
sys.path.insert(0,"../..")
sys.path.insert(0, "../..")

if sys.version_info[0] >= 3:
raw_input = input
Expand All @@ -17,7 +17,8 @@
if len(sys.argv) == 2:
data = open(sys.argv[1]).read()
prog = basparse.parse(data)
if not prog: raise SystemExit
if not prog:
raise SystemExit
b = basinterp.BasicInterpreter(prog)
try:
b.run()
Expand All @@ -39,33 +40,26 @@
line = raw_input("[BASIC] ")
except EOFError:
raise SystemExit
if not line: continue
if not line:
continue
line += "\n"
prog = basparse.parse(line)
if not prog: continue
if not prog:
continue

keys = list(prog)
if keys[0] > 0:
b.add_statements(prog)
b.add_statements(prog)
else:
stat = prog[keys[0]]
if stat[0] == 'RUN':
try:
b.run()
except RuntimeError:
pass
elif stat[0] == 'LIST':
b.list()
elif stat[0] == 'BLANK':
b.del_line(stat[1])
elif stat[0] == 'NEW':
b.new()









stat = prog[keys[0]]
if stat[0] == 'RUN':
try:
b.run()
except RuntimeError:
pass
elif stat[0] == 'LIST':
b.list()
elif stat[0] == 'BLANK':
b.del_line(stat[1])
elif stat[0] == 'NEW':
b.new()
71 changes: 29 additions & 42 deletions example/BASIC/basiclex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,72 +3,59 @@
from ply import *

keywords = (
'LET','READ','DATA','PRINT','GOTO','IF','THEN','FOR','NEXT','TO','STEP',
'END','STOP','DEF','GOSUB','DIM','REM','RETURN','RUN','LIST','NEW',
'LET', 'READ', 'DATA', 'PRINT', 'GOTO', 'IF', 'THEN', 'FOR', 'NEXT', 'TO', 'STEP',
'END', 'STOP', 'DEF', 'GOSUB', 'DIM', 'REM', 'RETURN', 'RUN', 'LIST', 'NEW',
)

tokens = keywords + (
'EQUALS','PLUS','MINUS','TIMES','DIVIDE','POWER',
'LPAREN','RPAREN','LT','LE','GT','GE','NE',
'COMMA','SEMI', 'INTEGER','FLOAT', 'STRING',
'ID','NEWLINE'
'EQUALS', 'PLUS', 'MINUS', 'TIMES', 'DIVIDE', 'POWER',
'LPAREN', 'RPAREN', 'LT', 'LE', 'GT', 'GE', 'NE',
'COMMA', 'SEMI', 'INTEGER', 'FLOAT', 'STRING',
'ID', 'NEWLINE'
)

t_ignore = ' \t'


def t_REM(t):
r'REM .*'
return t


def t_ID(t):
r'[A-Z][A-Z0-9]*'
if t.value in keywords:
t.type = t.value
return t

t_EQUALS = r'='
t_PLUS = r'\+'
t_MINUS = r'-'
t_TIMES = r'\*'
t_POWER = r'\^'
t_DIVIDE = r'/'
t_LPAREN = r'\('
t_RPAREN = r'\)'
t_LT = r'<'
t_LE = r'<='
t_GT = r'>'
t_GE = r'>='
t_NE = r'<>'
t_COMMA = r'\,'
t_SEMI = r';'
t_INTEGER = r'\d+'
t_FLOAT = r'((\d*\.\d+)(E[\+-]?\d+)?|([1-9]\d*E[\+-]?\d+))'
t_STRING = r'\".*?\"'

t_EQUALS = r'='
t_PLUS = r'\+'
t_MINUS = r'-'
t_TIMES = r'\*'
t_POWER = r'\^'
t_DIVIDE = r'/'
t_LPAREN = r'\('
t_RPAREN = r'\)'
t_LT = r'<'
t_LE = r'<='
t_GT = r'>'
t_GE = r'>='
t_NE = r'<>'
t_COMMA = r'\,'
t_SEMI = r';'
t_INTEGER = r'\d+'
t_FLOAT = r'((\d*\.\d+)(E[\+-]?\d+)?|([1-9]\d*E[\+-]?\d+))'
t_STRING = r'\".*?\"'


def t_NEWLINE(t):
r'\n'
t.lexer.lineno += 1
return t


def t_error(t):
print("Illegal character %s" % t.value[0])
t.lexer.skip(1)

lex.lex(debug=0)

















56 changes: 25 additions & 31 deletions example/BASIC/basiclog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
#

import sys
sys.path.insert(0,"../..")
sys.path.insert(0, "../..")

if sys.version_info[0] >= 3:
raw_input = input

import logging
logging.basicConfig(
level = logging.INFO,
filename = "parselog.txt",
filemode = "w"
level=logging.INFO,
filename="parselog.txt",
filemode="w"
)
log = logging.getLogger()

Expand All @@ -24,8 +24,9 @@
# interactive mode below
if len(sys.argv) == 2:
data = open(sys.argv[1]).read()
prog = basparse.parse(data,debug=log)
if not prog: raise SystemExit
prog = basparse.parse(data, debug=log)
if not prog:
raise SystemExit
b = basinterp.BasicInterpreter(prog)
try:
b.run()
Expand All @@ -47,33 +48,26 @@
line = raw_input("[BASIC] ")
except EOFError:
raise SystemExit
if not line: continue
if not line:
continue
line += "\n"
prog = basparse.parse(line,debug=log)
if not prog: continue
prog = basparse.parse(line, debug=log)
if not prog:
continue

keys = list(prog)
if keys[0] > 0:
b.add_statements(prog)
b.add_statements(prog)
else:
stat = prog[keys[0]]
if stat[0] == 'RUN':
try:
b.run()
except RuntimeError:
pass
elif stat[0] == 'LIST':
b.list()
elif stat[0] == 'BLANK':
b.del_line(stat[1])
elif stat[0] == 'NEW':
b.new()









stat = prog[keys[0]]
if stat[0] == 'RUN':
try:
b.run()
except RuntimeError:
pass
elif stat[0] == 'LIST':
b.list()
elif stat[0] == 'BLANK':
b.del_line(stat[1])
elif stat[0] == 'NEW':
b.new()
Loading

0 comments on commit 9e2b80e

Please sign in to comment.