nand2tetris

Is there a way regex will match all the combinations of the tokens in `|` operator

拥有回忆 提交于 2021-02-10 19:21:32
问题 I am doing a parser for nand2tetris project. I want to check if the destination field is either M|D|MD|A|AM|AD|AMD and their different ways of combinations like MA not only AM . ^(M|D|MD|A|AM|AD|AMD)\s*=$ This regex correctly matches AM= , but not MA= . I don't want to list out all the possible combinations of those tokens, is there a way to do it simply? 回答1: This should do it: ^(?=[MDA]+$)(?!.?(.).?\1).{1,3}$ Demo The negative lookahead attempts to match two "M" 's, two "D" 's or two "A" 's

Is there a way regex will match all the combinations of the tokens in `|` operator

為{幸葍}努か 提交于 2021-02-10 19:17:28
问题 I am doing a parser for nand2tetris project. I want to check if the destination field is either M|D|MD|A|AM|AD|AMD and their different ways of combinations like MA not only AM . ^(M|D|MD|A|AM|AD|AMD)\s*=$ This regex correctly matches AM= , but not MA= . I don't want to list out all the possible combinations of those tokens, is there a way to do it simply? 回答1: This should do it: ^(?=[MDA]+$)(?!.?(.).?\1).{1,3}$ Demo The negative lookahead attempts to match two "M" 's, two "D" 's or two "A" 's

Is there a way regex will match all the combinations of the tokens in `|` operator

落爺英雄遲暮 提交于 2021-02-10 19:12:31
问题 I am doing a parser for nand2tetris project. I want to check if the destination field is either M|D|MD|A|AM|AD|AMD and their different ways of combinations like MA not only AM . ^(M|D|MD|A|AM|AD|AMD)\s*=$ This regex correctly matches AM= , but not MA= . I don't want to list out all the possible combinations of those tokens, is there a way to do it simply? 回答1: This should do it: ^(?=[MDA]+$)(?!.?(.).?\1).{1,3}$ Demo The negative lookahead attempts to match two "M" 's, two "D" 's or two "A" 's

Is there a way regex will match all the combinations of the tokens in `|` operator

核能气质少年 提交于 2021-02-10 19:12:15
问题 I am doing a parser for nand2tetris project. I want to check if the destination field is either M|D|MD|A|AM|AD|AMD and their different ways of combinations like MA not only AM . ^(M|D|MD|A|AM|AD|AMD)\s*=$ This regex correctly matches AM= , but not MA= . I don't want to list out all the possible combinations of those tokens, is there a way to do it simply? 回答1: This should do it: ^(?=[MDA]+$)(?!.?(.).?\1).{1,3}$ Demo The negative lookahead attempts to match two "M" 's, two "D" 's or two "A" 's

Is there a way regex will match all the combinations of the tokens in `|` operator

时光怂恿深爱的人放手 提交于 2021-02-10 19:11:16
问题 I am doing a parser for nand2tetris project. I want to check if the destination field is either M|D|MD|A|AM|AD|AMD and their different ways of combinations like MA not only AM . ^(M|D|MD|A|AM|AD|AMD)\s*=$ This regex correctly matches AM= , but not MA= . I don't want to list out all the possible combinations of those tokens, is there a way to do it simply? 回答1: This should do it: ^(?=[MDA]+$)(?!.?(.).?\1).{1,3}$ Demo The negative lookahead attempts to match two "M" 's, two "D" 's or two "A" 's

Is there a way regex will match all the combinations of the tokens in `|` operator

风流意气都作罢 提交于 2021-02-10 19:10:14
问题 I am doing a parser for nand2tetris project. I want to check if the destination field is either M|D|MD|A|AM|AD|AMD and their different ways of combinations like MA not only AM . ^(M|D|MD|A|AM|AD|AMD)\s*=$ This regex correctly matches AM= , but not MA= . I don't want to list out all the possible combinations of those tokens, is there a way to do it simply? 回答1: This should do it: ^(?=[MDA]+$)(?!.?(.).?\1).{1,3}$ Demo The negative lookahead attempts to match two "M" 's, two "D" 's or two "A" 's

Is there a way regex will match all the combinations of the tokens in `|` operator

℡╲_俬逩灬. 提交于 2021-02-10 19:08:12
问题 I am doing a parser for nand2tetris project. I want to check if the destination field is either M|D|MD|A|AM|AD|AMD and their different ways of combinations like MA not only AM . ^(M|D|MD|A|AM|AD|AMD)\s*=$ This regex correctly matches AM= , but not MA= . I don't want to list out all the possible combinations of those tokens, is there a way to do it simply? 回答1: This should do it: ^(?=[MDA]+$)(?!.?(.).?\1).{1,3}$ Demo The negative lookahead attempts to match two "M" 's, two "D" 's or two "A" 's

Implementing a logical shift right

喜欢而已 提交于 2019-12-25 01:37:14
问题 So I'm working on the nand2tetris project, and I want to implement shift right logical on a software level since the hardware doesn't support it. I know shift right logical is a division by two. So my first shot at implementing it would count the number of times I was able to subtract 2 from the initial value before the value became 0 or negative. Similar for if the number was negative. But, I've found a scenario where it's not working. I want to shift right -27139. Well the binary value

“Expression Expected” error on line 1. How to fix it?

怎甘沉沦 提交于 2019-12-25 01:24:26
问题 I am getting the "In line 1, expression expected" error and I am not sure why. I am using the CPU Emulator from nand2tetris. I tried changing line 1 to 5, but it did not solve the problem. I just do not get what is the problem in the first place. @j D=5; @i; M=1; @5 @i D=M D=D-A; @END D;JGT @j @1 M=M-A @i @1 M=M+A @LOOP 0;JMP What I am trying to recreate is this loop: J=5 for(i=1; i<5; i++) { j-- } 回答1: There are several issues that pop out at first glance. First, D=5 is not a valid Hack

Nand To Tetris (Jack): Simple if conditional with equality testing giving this error - “Expected - or ~ or ( in term”

纵饮孤独 提交于 2019-12-12 04:25:02
问题 class Main { function void main() { var String foo; let foo = "bar"; if (foo == "bar") { do Output.printString("true"); } else { do Output.printString("false"); } return; } } I get the error: Expected - or ~ or ( in term . Full output: code/nand2tetris » tools/JackCompiler.sh projects/09/Test Compiling /Users/adamzerner/code/nand2tetris/projects/09/Test In Main.jack (line 6): In subroutine main: Expected - or ~ or ( in term code/nand2tetris » What does the error mean? 回答1: The issue is that I