You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
a{n,m} : Match n-m (inclusive) repetitions of a.
a{n,} : Match n or more (inclusive) repetitions of a.
a{,m} : Match m or less (inclusive) repetitions of a.
This can be done (I think) by adding just one new VM instruction, "jlt" or "Jump if Less Than".
This instruction takes two parameters; the index of an instruction in the VM program (jump location), and a count value. For example:
jlt 5 6
The first parameter "5" is the jump location. The second parameter "6" is the count value. The VM must keep count of how many times this instruction is executed within the containing program; if that count is less than the jlt instruction's count value, then execution will jump to the specified location, and if both values are equal then the VM will stop keeping count and execution will carry on to the next instruction as normal. The effect, in this example, is that for the first 6 times this instruction is executed it will cause execution to jump to the instruction at "5", and every time after that it will have no effect and execution will proceed normally.
These can be used with branch instructions to build the desired functionality. Some examples:
abc{n,m}
0 char a 1 char b 2 jlt 4 n 3 branch 4 6 4 char c 5 jlt 2 m+1 6 match
abc{n,}
0 char a 1 char b 2 char c 3 jlt 2 n+1 4 branch 2 5 5 match
abc{,m}
0 char a 1 char b 2 branch 3 5 3 char c 4 jlt 2 m+1 5 match
abc{n}
0 char a 1 char b 2 char c 3 jlt 2 n+1 4 match
The text was updated successfully, but these errors were encountered:
eriknyquist
changed the title
TODO: add support for numbered repetitions i.e. {n,m}, {n,}, {,m}
TODO: Add support for numbered repetitions i.e. {n,m}, {n,}, {,m}
May 16, 2016
Should look like this:
a{n,m} : Match n-m (inclusive) repetitions of a.
a{n,} : Match n or more (inclusive) repetitions of a.
a{,m} : Match m or less (inclusive) repetitions of a.
This can be done (I think) by adding just one new VM instruction, "jlt" or "Jump if Less Than".
This instruction takes two parameters; the index of an instruction in the VM program (jump location), and a count value. For example:
jlt 5 6
The first parameter "5" is the jump location. The second parameter "6" is the count value. The VM must keep count of how many times this instruction is executed within the containing program; if that count is less than the jlt instruction's count value, then execution will jump to the specified location, and if both values are equal then the VM will stop keeping count and execution will carry on to the next instruction as normal. The effect, in this example, is that for the first 6 times this instruction is executed it will cause execution to jump to the instruction at "5", and every time after that it will have no effect and execution will proceed normally.
These can be used with
branch
instructions to build the desired functionality. Some examples:abc{n,m}
0 char a
1 char b
2 jlt 4 n
3 branch 4 6
4 char c
5 jlt 2 m+1
6 match
abc{n,}
0 char a
1 char b
2 char c
3 jlt 2 n+1
4 branch 2 5
5 match
abc{,m}
0 char a
1 char b
2 branch 3 5
3 char c
4 jlt 2 m+1
5 match
abc{n}
0 char a
1 char b
2 char c
3 jlt 2 n+1
4 match
The text was updated successfully, but these errors were encountered: