Compiler construction 编者考试说明

Compiler construction 编者考试说明,compiler-construction,invariants,induction,Compiler Construction,Invariants,Induction,我正在准备编译器考试,我在过去的论文中发现了以下两个我不知道如何回答的问题: 1. Array bounds checking requires code to check each array subscript to ensure it falls within the array's declared range. How could induction variable analysis be used to avoid repeated bounds checks in "for" l

我正在准备编译器考试,我在过去的论文中发现了以下两个我不知道如何回答的问题:

1. Array bounds checking requires code to check each array subscript to ensure it
falls within the array's declared range. How could induction variable analysis be
used to avoid repeated bounds checks in "for" loops.

2. Give a short example in Java in which one array address calculation is loop-
invariant and another array address is an induction variable.
我知道不变量和归纳变量是什么意思,但我不知道在解释这两种解决方案时,对我的期望是什么

如果有人帮我解释一下,我将不胜感激


谢谢

第一个非常简单-由于归纳变量在每次迭代中都会以固定的数量递增,因此可以预先计算用作数组下标的任何归纳变量的最大值,并检查其是否超过数组边界。在执行循环之前,您应该这样做一次,而不是在每次迭代中检查下标

至于第二个,有很多循环不变量和归纳变量循环的例子(在各种语言中,包括Java),只有Google提供了这些术语