compiler construction - Is it possible to determine if the memory array is accessed out of bounds in a Brainf**k program? -


i have written own bf interpreter in assembly, , i'm writing bf compiler in java compiles assembly code.

i wanted implement little nice feature detected if array of memory cells out of bounds. traditional limitation array let index in [0, 30000), otherwise [0, inf) commonly used. option memory wrapped around, in first case mean accessing index 30000 means accessing index 0.

in compiler detection done @ semantic analysis phase of traditional compiler, have obtained our ast (abstract syntax tree) syntax analysis phase.

after trying come construct while have found detecting infinite loop in brainfuck program, bf's wikipedia page have found out bf program memory array [0, inf) resembles turing machine.

so question is, both [0, max) , [0, inf) cases, possible detect if memory pointer goes below zero, , in former case below max? without ending in infinite loop while checking it, , i'd rather avoid setting maximum execution time well.

bonus question: possible detect amount of times loop construct [...] loops?

bf turing capable. if use compute index, cannot determine in general if index has specific value (e.g., 30001) because of halting problem. in general, cannot detect out of bound access. however, may able detect many individual programs; why static analyzers built , used in spite of being theoretically useless.

regarding loop trip count: loop construct operates based on whether variable happens 0 or not. bf being turing capable means in general can't know if variable 0 or not @ particular point. implications can't know number of times loop construct works. again, may able figure out many individual programs.

for programs simple cases, might able implement checks easily. in general, doing these kind of static analyses take rather lot of machinery.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -