UP | HOME

The SimpleC Language
Lecture 7

Table of Contents

SimpleC language

Live code the grammar for SimpleC

Share grammar screenshot once done

Testing

Start writing test cases to check that the grammar gives the parse tree you expect.

(For homework, start giving example inputs and expected outputs as well).

Building a correct compiler

Reflections on trusting trust

Homework

Write five test programs with input and output files and submit them to the shared example repository. Pick a variety of grammar constructs to exercise. Pick several combinations of them. Make a .in file that has the number for each input() function on each line and a .out file that has the number for each output() function on each line. For example:

test.simplec

f(a, b, c) {
  int x;
  int y;
  int z;
  x = 2;
  output x;
  y = x + 1;
  z = 0;
  while (x > 0) {
    x = x - 1;
  }
  return y;
}

main() {
  int n;
  int sum;
  int next;
  input n;
  sum = 0;
  while (n > 0) {
    input next;
    sum = sum + next;
    output sum;
    n = n - 1;
  }
  return 0;
}

test.in

3
5
3
2

test.out

5
8
10

Author: Paul Gazzillo

Created: 2022-02-14 Mon 11:49