mirror of
https://github.com/hazemKrimi/hack-assembler.git
synced 2026-05-01 18:20:28 +00:00
Symbol-less assembler
This commit is contained in:
+20
-15
@@ -11,13 +11,13 @@ pub fn parse(instruction: &String) -> Instruction {
|
||||
decimal: cloned.trim().to_string(),
|
||||
});
|
||||
} else {
|
||||
let re_dest_and_comp = Regex::new(r"=").unwrap();
|
||||
let re_comp_and_jump = Regex::new(r";").unwrap();
|
||||
let re_dest = Regex::new(r"=").unwrap();
|
||||
let re_jump = Regex::new(r";").unwrap();
|
||||
|
||||
let dest_and_comp_exist = re_dest_and_comp.is_match(&cloned);
|
||||
let comp_and_jump_exist = re_comp_and_jump.is_match(&cloned);
|
||||
let dest_exists = re_dest.is_match(&cloned);
|
||||
let jump_exists = re_jump.is_match(&cloned);
|
||||
|
||||
let dest = match dest_and_comp_exist {
|
||||
let dest = match dest_exists {
|
||||
true => {
|
||||
let slice: Vec<&str> = cloned.split("=").collect();
|
||||
|
||||
@@ -26,22 +26,27 @@ pub fn parse(instruction: &String) -> Instruction {
|
||||
false => None,
|
||||
};
|
||||
|
||||
let comp = match comp_and_jump_exist {
|
||||
true => {
|
||||
let comp = match (dest_exists, jump_exists) {
|
||||
(true, false) => {
|
||||
let slice: Vec<&str> = cloned.split("=").collect();
|
||||
|
||||
// if jump_exist {
|
||||
// let another_slice: Vec<&str> = slice.as_slice()[1].split(";").collect();
|
||||
|
||||
// Some(another_slice.as_slice()[0].to_string());
|
||||
// }
|
||||
|
||||
Some(slice.as_slice()[1].to_string())
|
||||
}
|
||||
false => None,
|
||||
(false, true) => {
|
||||
let slice: Vec<&str> = cloned.split(";").collect();
|
||||
|
||||
Some(slice.as_slice()[0].to_string())
|
||||
}
|
||||
(true, true) => {
|
||||
let slice: Vec<&str> = cloned.split("=").collect();
|
||||
let another_slice: Vec<&str> = slice.as_slice()[1].split(";").collect();
|
||||
|
||||
Some(another_slice.as_slice()[0].to_string())
|
||||
}
|
||||
(false, false) => None,
|
||||
};
|
||||
|
||||
let jump = match comp_and_jump_exist {
|
||||
let jump = match jump_exists {
|
||||
true => {
|
||||
let slice: Vec<&str> = cloned.split(";").collect();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user