0

I've started to write a brainfuck compiler in bash.
The 'compiler' translates the code in assambly to compile it using gcc.
The problem is, when I try to run it, it prints this error:

$ ./compiler test.bf
./compiler: Zeile 111: src: {0..45}: Syntax Fehler: Operator erwartet. (Fehlerverursachendes Zeichen ist \"{0..45}\").

(In english:

$ ./compiler test.bf
./compiler: Line 111: src: {0..45}: Syntax Error: Operator excepted. (Causal Error Char is \"{0..45}\").

)

As I might understand, It says that there is a fault in line 111:

...
for i in {0..${#src}}        # line 109
do                           # line 110
    case ${src:$i:1} in      # line 111
...

(Here is the full code)

But I don't see any.

If the error is cause of the for loop, can you tell me how to make a for loop like in python:

for i in range(15):
    ...

Thanks in advance

2 Answers2

1

Use the C-style for loop:

for ((i=0; i < ${#src}; i++)); do
chepner
  • 497,756
  • 71
  • 530
  • 681
0

You can't use variables inside the {m..n} construct ; use seq instead :

for i in $(seq 0 ${#src})# line 109
do                       # line 110
    case ${src:$i:1} in  # line 111
Aaron
  • 24,009
  • 2
  • 33
  • 57