File tree Expand file tree Collapse file tree 4 files changed +22
-11
lines changed Expand file tree Collapse file tree 4 files changed +22
-11
lines changed Original file line number Diff line number Diff line change 1
1
venv /
2
- __pycache__ /
2
+ __pycache__ /
Original file line number Diff line number Diff line change 1
1
# type: ignore
2
- from .parser import parse_and_translate_instruction
2
+ from .parser import Parser
3
3
4
4
5
5
def main ():
6
- user_input = input ("Enter the full instruction: " )
7
- binary_instruction = parse_and_translate_instruction (user_input )
6
+ # user_input = input("Enter the full instruction: ")
7
+ # binary_instruction = parse_and_translate_instruction(user_input)
8
8
9
- print (binary_instruction )
9
+ # print(binary_instruction)
10
+ parser = Parser ("/home/ash/code/python-hack-assembler/test.asm" )
11
+ parser .assemble ()
10
12
11
13
12
14
if __name__ == "__main__" :
Original file line number Diff line number Diff line change @@ -24,15 +24,16 @@ def assemble(self):
24
24
try :
25
25
with open (self .file , "r" ) as file :
26
26
for line in file :
27
- self .read_line (line )
27
+ translatedLine = parse_line (line )
28
+
29
+ if translatedLine is not None :
30
+ self .lineNum += 1
31
+ print (translatedLine )
28
32
29
33
except FileNotFoundError :
30
34
print (f"File { self .file } not found." )
31
35
return None
32
36
33
- def read_line (self , line ):
34
- print (line )
35
-
36
37
37
38
def parse_line (line : str ) -> None | str :
38
39
line = line .strip ()
@@ -41,8 +42,12 @@ def parse_line(line: str) -> None | str:
41
42
if line == "" :
42
43
return None
43
44
45
+ # Skip comment lines
46
+ if line .startswith ("//" ):
47
+ return None
48
+
44
49
# Handle inline comments
45
- if line .split ("//" )[ 1 ] :
50
+ if len ( line .split ("//" )) > 1 :
46
51
line = line [0 ].strip ()
47
52
48
53
if line .startswith ("(" ):
@@ -58,7 +63,7 @@ def parse_line(line: str) -> None | str:
58
63
maybe_variable = line .split ("@" )[1 ]
59
64
if not maybe_variable .isdigit ():
60
65
# Stubbed: Add to the symbol table here
61
- return
66
+ return None
62
67
63
68
return parse_and_translate_instruction (line )
64
69
Original file line number Diff line number Diff line change
1
+ D =1
2
+ D =D+1
3
+
4
+
You can’t perform that action at this time.
0 commit comments