-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcradle.py
More file actions
80 lines (65 loc) · 1.17 KB
/
cradle.py
File metadata and controls
80 lines (65 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import sys
# Variable declarations
look = '' # Lookahead character
# Read New Character From Input Stream
def GetChar():
global look
look = sys.stdin.read(1)
# Report an Error
def Error(s):
print ''
print 'Error: ' + s + '.'
# Report Error and Halt
def Abort(s):
Error(s)
sys.exit()
# Report What Was Expected
def Expected(s):
Abort(s + ' Expected')
# Match a Specific Input Character
def Match(x):
global look
if look == x:
GetChar()
else:
Expected(''' + x + ''')
# Recognize an Alpha Character
def IsAlpha(c):
return c.isalpha()
# Recognize a Decimal Digit
def IsDigit(c):
return c.isdigit()
# Get an Identifier
def GetName():
val = 0
global look
if not IsAlpha(look):
Expected('Name')
else:
val = look.upper()
GetChar()
return val #? maybe not intented?
# Get a Number
def GetNum():
val = 0
global look
if not IsDigit(look):
Expected('Integer')
else:
val = look.upper()
GetChar()
return val #? maybe not intented?
# Output a String with Tab
def Emit(s):
print '\t' , s
# Output a String with Tab and CRLF
def EmitLn(s):
Emit(s)
print '\n'
# Initialize
def Init():
GetChar()
#def main():
# Init()
#if __name__ == '__main__':
# main()