-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstripcomments.py
More file actions
38 lines (32 loc) · 1004 Bytes
/
stripcomments.py
File metadata and controls
38 lines (32 loc) · 1004 Bytes
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
# Comment Stripper
# Michael Leonhard
# stripcomments.py (Project 5 Comment Stripper)
# Michael Leonhard (mleonhar)
# CS366 Fall 2005, Professor Khokhar
# TA: Mani Radhakrishnan
# MythSim 3.1.1 on Windows XP SP2, Java SDK 1.5.0_04, Python 2.4
# 2005-11-30
#
# Usage: python assemble.py foo.asm >> foo.mem
import sys, string
def stripComment(Line):
Index = Line.find("//")
# no comment
if Index == -1: return Line
# return line without comment
return Line[:Index]
# print usage
if len(sys.argv) != 2:
print >> sys.stderr, "Comment Stripper by Michael Leonhard (http://tamale.net/)"
print >> sys.stderr, "Strip comments out of microcode files to avoid MythSim's parsing errors."
print >> sys.stderr, "Usage: python stripcomments.py foo.ucode >> foo.ucode2"
sys.exit(0)
# open file
F = file(sys.argv[1])
A = ""
for Line in F: A = A + string.expandtabs(stripComment(Line.strip())).strip() + " "
B = string.join(A.split())
Lines = B.split("; ")
print string.join(Lines, ";\n")
# done
F.close()