<section xml:id="code-lens">
<title>Code Lens</title>
<p>
CodeLens is an interactive tool for following program execution,
much like a debugger,
without the ability to influence flow control or variable values.
For use without a server, traces must be computed beforehand.
First, we have some trivial programs,
to provide minimal testing.
</p>
<listing xml:id="program-codelens-python">
<caption>A Python program, stepable with CodeLens</caption>
<program xml:id="python-hello-world-code-lens" interactive="codelens" language="python">
<code>
print('Hello, World!')
</code>
</program>
</listing>
<listing xml:id="program-codelens-c">
<caption>An C program, stepable with CodeLens</caption>
<program xml:id="c-hello-world-code-lens" interactive="codelens" language="c">
<code>
#include <stdio.h>
int main(void)
{
puts("Hello, World!");
}
</code>
</program>
</listing>
<listing xml:id="program-codelens-java">
<caption>A Java program, stepable with CodeLens</caption>
<program xml:id="java-hello-world-code-lens" interactive="codelens" language="java">
<code>
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
</code>
</program>
</listing>
<p>
Now some moderately more complicated programs to find teh prime numbers less than <m>20</m>.
We do not vouch for the quality of these,
or even their correctness!
</p>
<listing xml:id="sieve-python">
<caption><url href="https://www.tutorialspoint.com/python-program-for-sieve-of-eratosthenes" visual="www.tutorialspoint.com/python-program-for-sieve-of-eratosthenes">Sieve of Eratosthenes</url>, Java</caption>
<program xml:id="sieve-codelens-python" interactive="codelens" language="python">
<code>
def SieveOfEratosthenes(n):
# array of type boolean with True values in it
prime = [True for i in range(n + 1)]
p = 2
while (p * p <= n):
# If it remain unchanged it is prime
if (prime[p] == True):
# updating all the multiples
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 1
prime[0]= False
prime[1]= False
# Print
for p in range(n + 1):
if prime[p]:
print (p,end=" ")
# main
if __name__=='__main__':
n = 20
print ("The prime numbers smaller than or equal to", n,"is")
SieveOfEratosthenes(n)
</code>
</program>
</listing>
<listing xml:id="sieve-cpp">
<caption><url href="https://www.tutorialspoint.com/cplusplus-program-to-implement-sieve-of-eratosthenes-to-generate-prime-numbers-between-given-range" visual="www.tutorialspoint.com/cplusplus-program-to-implement-sieve-of-eratosthenes-to-generate-prime-numbers-between-given-range">Sieve of Eratosthenes</url>, C++</caption>
<program xml:id="sieve-codelens-cpp" interactive="codelens" language="cpp">
<code>
#include <stdio.h>
const int len = 20;
int main() {
int arr[20] = {0};
for (int i = 2; i < len; i++) {
for (int j = i * i; j < len; j+=i) {
arr[j - 1] = 1;
}
}
for (int i = 1; i < len; i++) {
if (arr[i - 1] == 0)
printf(" %d", i);
}
}
</code>
</program>
</listing>
<listing xml:id="sieve-java">
<caption><url href="https://www.tutorialspoint.com/Sieve-of-Eratosthenes-in-java" visual="www.tutorialspoint.com/Sieve-of-Eratosthenes-in-java">Sieve of Eratosthenes</url>, Java</caption>
<program xml:id="sieve-codelens-java" interactive="codelens" language="java">
<code>
public class SievePrimeFactors {
public static void main(String args[]) {
int num = 20;
boolean[] bool = new boolean[num];
for (int i = 0; i< bool.length; i++) {
bool[i] = true;
}
for (int i = 2; i < Math.sqrt(num); i++) {
if(bool[i] == true) {
for(int j = (i*i); j < num; j = j+i) {
bool[j] = false;
}
}
}
System.out.println("List of prime numbers: ");
for (int i = 2; i< bool.length; i++) {
if(bool[i]==true) {
System.out.println(i);
}
}
}
}
</code>
</program>
</listing>
</section>
CodeLens is an interactive tool for following program execution, much like a debugger, without the ability to influence flow control or variable values. For use without a server, traces must be computed beforehand. First, we have some trivial programs, to provide minimal testing.
Now some moderately more complicated programs to find teh prime numbers less than \(20\text{.}\) We do not vouch for the quality of these, or even their correctness!