-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython
More file actions
73 lines (67 loc) · 1.77 KB
/
Copy pathpython
File metadata and controls
73 lines (67 loc) · 1.77 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
output "Hello World!"
output "This is a Pseudo program!"
set variable foo to 5 plus 6
output "The value of foo is:"
output variable foo
make function foobar taking void as parameters
output "Inside foobar!"
make function foobar2 taking foo as parameters
output "Inside foobar2!"
output "The value of foo is:"
output variable foo
output call foobar with void now
call foobar2 with foo now
output 5 greater than 6
output 4 greater than or equal to 4
output 4 not equals 2
output 5 equals 4
output 12 remainder 5
output 4 equals 5 and 6 equals 6
output 4 equals 5 or 6 equals 6
if 5 equals 3
output "This is true!"
else if 5 equals 5
output "This is true!"
else
output "None are true"
set variable i to 0
while variable i less than 5
output variable i
set variable i to variable i plus 1
for each i from 0 to 10 counting by 2
output variable i
if variable i greater than 3
output variable i plus 100
else
output variable i minus 100
#!/usr/bin/python
import token_string
import translate
import sys
import re
def main():
if len(sys.argv) > 2:
print "pseudo: " + " ".join(sys.argv) + ". Too many arguments. Usage: pseudo file"
exit()
#elif len(sys.argv) < 2:
#print "pseudo: Too few arguments. Usage: pseudo file"
#exit()
#filename = sys.argv[1]
#if re.match(r'(.*)\.psu$', filename) == None:
#print "pseudo: Not a '.psu' file. Usage: pseudo file"
#exit()
#f = open(filename, 'r')
str = ""
for line in sys.stdin:
str = str + line
print str
tokens = token_string.tokenize(str)
translation = translate.parse(tokens)
#f.close()
code = open(filename[:-4] + '.py', 'w+')
code.write(translation)
code.close()
exec(translation)
print "Code has been run and has been translated into " + filename[:-4] + ".py"
if __name__ == "__main__":
main()