\Large{\texttt{fail-FS.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}
 
END {
  FS = "  "; # Fail: reassigning FS
}

CONFIG {
  FS = " ";
}
\end{lstlisting}

\Large{\texttt{fail-RS.bawk}}\begin{lstlisting}
BEGIN {}
 
LOOP {}
 
END {
  RS = "\n\n"; # Fail: reassigning RS
}
 
CONFIG {
  RS = "\n";
}
\end{lstlisting}

\Large{\texttt{fail-array1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  void[] a; # Fail: Creating an array of voids
  a = [];
}
\end{lstlisting}

\Large{\texttt{fail-array2.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int[] a;
  bool b;
  a = [1,2,3];
  b = contains(a, true); # Fail: Checking for bool inside int array
}
\end{lstlisting}

\Large{\texttt{fail-array3.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int[] a;
  int b;
  a = [1,2,3];
  b = index_of(a, true); # Fail: Finding index of bool in an int array
}
\end{lstlisting}

\Large{\texttt{fail-arrayassign1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int[] a;
  a = [[1,2], [3,4]]; # Fail: assigning a 2D array to a 1D array 
}
\end{lstlisting}

\Large{\texttt{fail-arrayassign2.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int[] a;
  a = [1, "hi"]; # Fail: assigning a string as an element in an int array
}
\end{lstlisting}

\Large{\texttt{fail-arrayassign3.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int[][] a;
  a = [[1,2], ["hi", "bye"]]; # Fail: Assigning 2D array of int type and string type to 2D array of int type
}
\end{lstlisting}

\Large{\texttt{fail-assign1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int i;
  bool b;

  i = 42;
  i = 10;
  b = true;
  b = false;
  i = false; # Fail: assigning a bool to an integer
}
\end{lstlisting}

\Large{\texttt{fail-assign2.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int i;
  bool b;

  b = 48; # Fail: assigning an integer to a bool
}
\end{lstlisting}

\Large{\texttt{fail-assign3.bawk}}\begin{lstlisting}
BEGIN {
  function void myvoid()
  {
    return;
  }
}

LOOP {}

END {
  int i;

  i = myvoid(); # Fail: assigning a void to an integer
}
\end{lstlisting}

\Large{\texttt{fail-assign4.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  void x; # Fail: Declaring a variable with void type
}
\end{lstlisting}

\Large{\texttt{fail-assign5.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  string s;
  s = '[0]*'; # Fail: assigning regex to string
}
\end{lstlisting}

\Large{\texttt{fail-assign6.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  NF = 3; # Fail: assigning a value to NF
}
\end{lstlisting}

\Large{\texttt{fail-assign7.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  rgx r;
  r = "hello"; # Fail: assigning string to regex
}
\end{lstlisting}

\Large{\texttt{fail-blocks1.bawk}}\begin{lstlisting}
BEGIN {}

BEGIN {} # Fail: two BEGIN blocks

LOOP {}

END {}
\end{lstlisting}

\Large{\texttt{fail-conversion1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {
  print(int_to_string(string_to_int(8))); # Fail: Passing an int instead of string to string_to_int
}

END {}
\end{lstlisting}

\Large{\texttt{fail-conversion2.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
	print(int_to_string("hi")); # Fail: Passing a string instead of int
}
\end{lstlisting}

\Large{\texttt{fail-conversion3.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
	print(rgx_to_string(2)); # Fail: Passing a int instead of rgx
}
\end{lstlisting}

\Large{\texttt{fail-conversion4.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
	print(bool_to_string('[0-9]*')); # Fail: Passing a rgx instead of bool
}
\end{lstlisting}

\Large{\texttt{fail-conversion5.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
	print(bool_to_string('[0-9]*')); # Fail: Passing a rgx instead of bool
}
\end{lstlisting}

\Large{\texttt{fail-dead1.bawk}}\begin{lstlisting}
BEGIN {
  function int foo(){
    int i;  

    i = 15;
    return i;
    i = 32; # Error: code after a return
  }
}

LOOP {}

END {}
\end{lstlisting}

\Large{\texttt{fail-decl1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int NF; # Fail: declaring a variable called NF
}
\end{lstlisting}

\Large{\texttt{fail-decl2.bawk}}\begin{lstlisting}
BEGIN {}
 
LOOP {}
 
END {
  int RS; # Fail: declaring RS
}
\end{lstlisting}

\Large{\texttt{fail-decl3.bawk}}\begin{lstlisting}
BEGIN {}
 
LOOP {}
 
END {
  int FS; # Fail: declaring FS
}
\end{lstlisting}

\Large{\texttt{fail-dollarbegin.bawk}}\begin{lstlisting}
BEGIN {
  string hello;
  hello = $0;
}

LOOP {}

END {}
\end{lstlisting}

\Large{\texttt{fail-dynamicarr1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int[] a;
  a = [1,2,3];
  insert(a, 1, true); # Fail: Inserting bool into int array
}
\end{lstlisting}

\Large{\texttt{fail-expr1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int i;
  bool b;

  i = 42;
  i = 10;
  b = true;
  b = false;
  i = false; # Fail: assigning a bool to an integer
}
\end{lstlisting}

\Large{\texttt{fail-expr2.bawk}}\begin{lstlisting}
BEGIN {
  int a;
  bool b;

  function void foo(int c, bool d)    
  {
    int dd;
    bool e;
    a + c;
    c - a;
    a * 3;
    c / 2;
    d + a; # Error: bool + int
  }
}

LOOP {}

END {}
\end{lstlisting}

\Large{\texttt{fail-expr3.bawk}}\begin{lstlisting}
BEGIN {
  int a;
  bool b;

  function void foo(int c, bool d)    
  {
    int d;
    bool e;
    b + a; # Error: bool + int
  }
}

LOOP {}

END {}
\end{lstlisting}

\Large{\texttt{fail-expr4.bawk}}\begin{lstlisting}
BEGIN {
  int a;
  string b;

  function void foo(int c, string d)    
  {
    int d;
    string e;
    b + a; # Error: string + int 
  }
}

LOOP {}

END {}
\end{lstlisting}

\Large{\texttt{fail-expr5.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
	'[0]*' ~ true; # Fail: Comparing rgx and bool
}
\end{lstlisting}

\Large{\texttt{fail-for1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int i;

  for (i = 0 ; i < 10 ; i = i + 1) {
    if (i == 3) {
      print(int_to_string(42));
    }
  }

  for (j = 0; i < 10 ; i = i + 1) {} # j undefined 
}
\end{lstlisting}

\Large{\texttt{fail-for2.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int i;

  for (i = 0; j < 10 ; i = i + 1) {} # j undefined
}
\end{lstlisting}

\Large{\texttt{fail-for3.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int i;

  for (i = 0; i ; i = i + 1) {} # i is an integer, not Boolean 
}
\end{lstlisting}

\Large{\texttt{fail-for4.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int i;

  for (i = 0; i < 10 ; i = j + 1) {} # j undefined 
}
\end{lstlisting}

\Large{\texttt{fail-for5.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int i;

  for (i = 0; i < 10 ; i = i + 1) {
    foo(); # Error: no function foo 
  }
}
\end{lstlisting}

\Large{\texttt{fail-for6.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int i;
  int x;

  x = 10;
  for (i in x) {} # Fail: enhanced for loop on an integer
}
\end{lstlisting}

\Large{\texttt{fail-for7.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int x;
  string[] a;
  for(x in a) {} # Fail: Enhanced for loop on a string array using an int
}
\end{lstlisting}

\Large{\texttt{fail-func1.bawk}}\begin{lstlisting}
BEGIN {
  function int foo() {}

  function int bar() {}

  function int baz() {}

  function void bar() {} # Error: duplicate function bar 
}

LOOP {}

END {}
\end{lstlisting}

\Large{\texttt{fail-func2.bawk}}\begin{lstlisting}
BEGIN {
  function int foo(int a, bool b, int c) { }

  function void bar(int a, bool b, int a) {} # Error: duplicate formal a in bar 
}

LOOP {}

END {}
\end{lstlisting}

\Large{\texttt{fail-func3.bawk}}\begin{lstlisting}
BEGIN {
  function int foo(int a, bool b, int c) { }

  function void bar(int a, void b, int c) {} # Error: illegal void formal b 
}

LOOP {}

END {}
\end{lstlisting}

\Large{\texttt{fail-func4.bawk}}\begin{lstlisting}
BEGIN {
  function int foo() {}

  function void bar() {}

  function int print() {} # Should not be able to define print 

  function void baz() {}
}

LOOP {}

END {}
\end{lstlisting}

\Large{\texttt{fail-func5.bawk}}\begin{lstlisting}
BEGIN {
  function int foo() {}

  function int bar() {
    int a;
    void b; # Error: illegal void local b 
    bool c;

    return 0;
  }
}

LOOP {}

END {}
\end{lstlisting}

\Large{\texttt{fail-func6.bawk}}\begin{lstlisting}
BEGIN {
  function void foo(int a, bool b)
  {
  }
}

LOOP {}

END {
  foo(42, true);
  foo(42); # Wrong number of arguments 
}
\end{lstlisting}

\Large{\texttt{fail-func7.bawk}}\begin{lstlisting}
BEGIN {
  function void foo(int a, bool b)
  {
  }
}

LOOP {}

END {
  foo(42, true);
  foo(42, true, false); # Wrong number of arguments 
}
\end{lstlisting}

\Large{\texttt{fail-func8.bawk}}\begin{lstlisting}
BEGIN {
  function void foo(int a, bool b)
  {
  }

  function void bar()
  {
  }
}

LOOP {}

END {
  foo(42, true);
  foo(42, bar()); # int and void, not int and bool 
}
\end{lstlisting}

\Large{\texttt{fail-func9.bawk}}\begin{lstlisting}
BEGIN {
  function void foo(int a, bool b)
  {
  }
}

LOOP {}

END {
  foo(42, true);
  foo(42, 42); # Fail: int, not bool 
}
\end{lstlisting}

\Large{\texttt{fail-global1.bawk}}\begin{lstlisting}
BEGIN {
  int c;
  bool b;
  void a; # global variables should not be void 
}

LOOP {}

END {}
\end{lstlisting}

\Large{\texttt{fail-global2.bawk}}\begin{lstlisting}
BEGIN {
  int b;
  bool c;
  int a;
  int b; # Duplicate global variable 
}

LOOP {}

END {}
\end{lstlisting}

\Large{\texttt{fail-helloworldbegin.bawk}}\begin{lstlisting}
BEGIN {
  print("Hello World!");
}

LOOP {}

END {
}

CONFIG {}
\end{lstlisting}

\Large{\texttt{fail-if1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  if (true) {}
  if (false) {} else {}
  if (42) {} # Error: non-bool predicate 
}
\end{lstlisting}

\Large{\texttt{fail-if2.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  if (true) {
    foo; # Error: undeclared variable 
  }
}
\end{lstlisting}

\Large{\texttt{fail-if3.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  if (true) {
    42;
  } else {
    bar; # Error: undeclared variable
  }
}
\end{lstlisting}

\Large{\texttt{fail-length.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
	int x;
	x = 0;
	length(x); # Fail: Finding length of int
}
\end{lstlisting}

\Large{\texttt{fail-print1.bawk}}\begin{lstlisting}
BEGIN {
  # Should be illegal to redefine 
  function void print() {}
}

LOOP {}

END {}
\end{lstlisting}

\Large{\texttt{fail-print2.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
	print(5); # Fail: Printing an int instead of a string
}
\end{lstlisting}

\Large{\texttt{fail-return1.bawk}}\begin{lstlisting}
BEGIN {
  function void foo()
  {
    if (true) {
      return 42; # Should return void
    }
    else {
      return;
    }
  }
}

LOOP {}

END {}
\end{lstlisting}

\Large{\texttt{fail-scope1.bawk}}\begin{lstlisting}
BEGIN{}
LOOP{
  int i;  

  {
    i = 15;
  }

  i = 32; 
}
END{}
\end{lstlisting}

\Large{\texttt{fail-structure1.bawk}}\begin{lstlisting}
BEGIN {
  function void loop() {}
}

LOOP {}

END {}
\end{lstlisting}

\Large{\texttt{fail-structure2.bawk}}\begin{lstlisting}
BEGIN {
  function void end() {}
}

LOOP {}

END {}
\end{lstlisting}

\Large{\texttt{fail-while1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int i;

  while (true) {
    i = i + 1;
  }

  while (42) { # Should be boolean 
    i = i + 1;
  }
}
\end{lstlisting}

\Large{\texttt{fail-while2.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int i;

  while (true) {
    i = i + 1;
  }

  while (true) {
    foo(); # foo undefined 
  }
}
\end{lstlisting}

\Large{\texttt{pass-add1.bawk}}\begin{lstlisting}
BEGIN {
  function int add(int x, int y) {
    return x + y;
  }
}

LOOP {}

END {
  print(int_to_string(add(1, 2)));
}

CONFIG {}
\end{lstlisting}

\Large{\texttt{pass-add2.bawk}}\begin{lstlisting}
BEGIN {
  function void add(int x, int y) {
    print(int_to_string(x + y));
  }
}

LOOP {}

END {
  add(1, 2);
}
\end{lstlisting}

\Large{\texttt{pass-arith1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int x;
  x = 0;
  x = x + 2;
  print(int_to_string(x));
}
\end{lstlisting}

\Large{\texttt{pass-arith2.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  print(int_to_string(1 + 2 * 3 + 4));
}
\end{lstlisting}

\Large{\texttt{pass-arith3.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  print(int_to_string(1 - 2 / 3 - 4));
}
\end{lstlisting}

\Large{\texttt{pass-arith4.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int x;
  x = 2;
  x += 2;
  print(int_to_string(x));
}
\end{lstlisting}

\Large{\texttt{pass-arith5.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int x;
  x = 2;
  x -= 2;
  print(int_to_string(x));
}
\end{lstlisting}

\Large{\texttt{pass-arrayliterals.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
	int[] a;
  a = [1+1, 2+2, 3+2];
  print(int_to_string(a[0]));
}
\end{lstlisting}

\Large{\texttt{pass-bool1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  bool b;
  b = true;
  if (b) {
    print(int_to_string(10));
  }
}
\end{lstlisting}

\Large{\texttt{pass-bool2.bawk}}\begin{lstlisting}
BEGIN {
  function bool cond() {
    bool b;
    b = true;
    return b;
  }
}

LOOP {}

END {
  if (cond()) {
    print(int_to_string(10));
  }
}
\end{lstlisting}

\Large{\texttt{pass-boolarr1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  bool[] a; 
  a = [];
  print(int_to_string(length(a)));
}
\end{lstlisting}

\Large{\texttt{pass-boolarr2.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  bool[] a; 
  a = [true, false, false];
  print(int_to_string(length(a)));
}
\end{lstlisting}

\Large{\texttt{pass-boolarr3.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  bool[] a; 
  a = [true, false, false];
  print(bool_to_string(a[0]));
}
\end{lstlisting}

\Large{\texttt{pass-boolarr4.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  bool[] a; 
  a = [true, false, false];
  a[0] = false;
  print(bool_to_string(a[0]));
}
\end{lstlisting}

\Large{\texttt{pass-boolarr5.bawk}}\begin{lstlisting}
BEGIN {
  function bool[] foo() {
    bool[] a; 
    a = [true, false, false];
    return a;
  }
}

LOOP {}

END {
  bool[] a;
  a = foo();
  print(bool_to_string(a[0]));
}
\end{lstlisting}

\Large{\texttt{pass-boolarr6.bawk}}\begin{lstlisting}
BEGIN {
  function bool[] foo (bool[] a) {
    return a;
  }
}

LOOP {}

END {
  bool[] a;
  a = [true, false, false];
  a = foo(a);
  print(bool_to_string(a[0]));
}
\end{lstlisting}

\Large{\texttt{pass-boolarr7.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  bool[][] m;
  bool[][][] a;
  bool[][][][] b;

  m = [[false, false], [false, false]];
  m[0][0] = true;
  print(bool_to_string(m[0][0]));

  a = 
  [
    [ [true, false], [false, false] ], [ [false, false], [false, false] ]
  ];
  print(bool_to_string(a[0][0][0]));

  b = 
  [
    [ [ [true, false], [false, false] ], [ [false, false], [false, false] ] ], 
    [ [ [false, false], [false, false] ], [ [false, false], [false, false] ] ]
  ];
  print(bool_to_string(b[0][0][0][0]));
}
\end{lstlisting}

\Large{\texttt{pass-boolarr8.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  bool[] a; 
  a = [false, false, false];
  print(bool_to_string(contains(a, false)));
  print(bool_to_string(contains(a, true)));
}
\end{lstlisting}

\Large{\texttt{pass-boolarr9.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  bool[] a; 
  a = [true, false, false];
  print(int_to_string(index_of(a, true)));
}
\end{lstlisting}

\Large{\texttt{pass-comment.bawk}}\begin{lstlisting}
BEGIN {
  function int add(int x, int y) {
    return x + y;
  }
}

LOOP {}

END {
  # this should not print
  # print(int_to_string(add(1, 2)));
  print(int_to_string(add(1, 2)));
}

CONFIG {}
\end{lstlisting}

\Large{\texttt{pass-config1.bawk}}\begin{lstlisting}
BEGIN {}
 
LOOP {
	print($1);
}
 
END {}
 
CONFIG {
  RS = "\n";
}
\end{lstlisting}

\Large{\texttt{pass-config2.bawk}}\begin{lstlisting}
BEGIN {}
 
LOOP {
  print($1);
}
 
END {}
 
CONFIG {
  FS = " ";
}
\end{lstlisting}

\Large{\texttt{pass-config3.bawk}}\begin{lstlisting}
BEGIN {}
 
LOOP {
  print($1);
}
 
END {}
 
CONFIG {
  RS = "\n";
  FS = "  ";
}
\end{lstlisting}

\Large{\texttt{pass-dollar1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {
  print($0);
}

END {}
\end{lstlisting}

\Large{\texttt{pass-dollar2.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {
	string hello;
	hello = $0;
	print(hello);
}

END {}
\end{lstlisting}

\Large{\texttt{pass-dynamicarr1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  bool[] a; 
  a = [true, false, false];
  insert(a, 3, true);
  print(int_to_string(length(a)));
}
\end{lstlisting}

\Large{\texttt{pass-dynamicarr2.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  bool[] a; 
  a = [true, false, false];
  delete(a, 2);
  print(int_to_string(length(a)));
}
\end{lstlisting}

\Large{\texttt{pass-dynamicarr3.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int[] a;
  int b;
  a = [1,2,3];
  b = a[3]; # Fail: Accessing past size of array
}
\end{lstlisting}

\Large{\texttt{pass-dynamicarr4.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int[] a;
  a = [1,2,3];
  insert(a, 6, 4); # Fail: Inserting past (size of array + 1)
}
\end{lstlisting}

\Large{\texttt{pass-dynamicarr5.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int[] a;
  a = [1,2,3];
  insert(a, -1, 4); # Fail: Inserting at illegal index
}
\end{lstlisting}

\Large{\texttt{pass-dynamicarr6.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int[] a;
  a = [1,2,3];
  delete(a, 4); # Fail: Deleting element from invalid index
}
\end{lstlisting}

\Large{\texttt{pass-dynamicarr7.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int[] a;
  a = [1,2,3];
  delete(a, -1); # Fail: Deleting from an invalid index
}
\end{lstlisting}

\Large{\texttt{pass-fib.bawk}}\begin{lstlisting}
BEGIN {
  function int fib(int x)
  {
    if (x < 2) {
      return 1;
    }
    return fib(x-1) + fib(x-2);
  }
}

LOOP {}

END {
  print(int_to_string(fib(0)));
  print(int_to_string(fib(1)));
  print(int_to_string(fib(2)));
  print(int_to_string(fib(3)));
  print(int_to_string(fib(4)));
  print(int_to_string(fib(5)));
}
\end{lstlisting}

\Large{\texttt{pass-for1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int i;
  for (i = 0 ; i < 5 ; i = i + 1) {
    print(int_to_string(i));
  }
  print(int_to_string(42));
}
\end{lstlisting}

\Large{\texttt{pass-for2.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int i;
  int[] arr;
  arr = [1, 2, 3];

  for (i = 0; i < length(arr); i++) {
    print(int_to_string(arr[i]));
  }
  print(int_to_string(42));
}
\end{lstlisting}

\Large{\texttt{pass-func1.bawk}}\begin{lstlisting}
BEGIN {
  function int fun(int x, int y)
  {
    return 0;
  }
}

LOOP {}

END {
  int i;
  i = 1;

  fun(i = 2, i = i+1);

  print(int_to_string(i));
}
\end{lstlisting}

\Large{\texttt{pass-func2.bawk}}\begin{lstlisting}
BEGIN {
  function void printem(int a, int b, int c, int d)
  {
    print(int_to_string(a));
    print(int_to_string(b));
    print(int_to_string(c));
    print(int_to_string(d));
  }
}

LOOP {}

END {
  printem(42,17,192,8);
}
\end{lstlisting}

\Large{\texttt{pass-func3.bawk}}\begin{lstlisting}
BEGIN {
  function int add(int a, int b)
  {
    int c;
    c = a + b;
    return c;
  }
}

LOOP {}

END {
  int d;
  d = add(52, 10);
  print(int_to_string(d));
}
\end{lstlisting}

\Large{\texttt{pass-func4.bawk}}\begin{lstlisting}
BEGIN {
  function int foo(int a)
  {
    return a;
  }
}

LOOP {}

END {
	print( int_to_string(foo(2)) );
}
\end{lstlisting}

\Large{\texttt{pass-func5.bawk}}\begin{lstlisting}
BEGIN {
  function void foo() {}

  function int bar(int a, bool b, int c) { return a + c; }
}

LOOP {}

END {
  print(int_to_string(bar(17, false, 25)));
}
\end{lstlisting}

\Large{\texttt{pass-func6.bawk}}\begin{lstlisting}
BEGIN {
  int a;

  function void foo(int c)
  {
    a = c + 42;
  }
}

LOOP {}

END {
  foo(73);
  print(int_to_string(a));
}
\end{lstlisting}

\Large{\texttt{pass-func7.bawk}}\begin{lstlisting}
BEGIN {
  function void foo(int a)
  {
    print(int_to_string(a + 3));
  }
}

LOOP {}

END {
  foo(40);
}
\end{lstlisting}

\Large{\texttt{pass-func8.bawk}}\begin{lstlisting}
BEGIN {
  function void foo(int a)
  {
    print(int_to_string(a + 3));
    return;
  }
}

LOOP {}

END {
  foo(40);
}
\end{lstlisting}

\Large{\texttt{pass-func9.bawk}}\begin{lstlisting}
BEGIN {
  function int x() {
    return 2;
  }

  function int y() {
    return x();
  }
}

LOOP {}

END {
	print( int_to_string(y()) );
}
\end{lstlisting}

\Large{\texttt{pass-gcd.bawk}}\begin{lstlisting}
BEGIN {
  function int gcd(int a, int b) {
    while (a != b) {
      if (a > b) {
        a = a - b;
      }
      else {
        b = b - a;
      }
    }
    return a;
  }
}

LOOP {}

END {
  print(int_to_string(gcd(2,14)));
  print(int_to_string(gcd(3,15)));
  print(int_to_string(gcd(99,121)));
}
\end{lstlisting}

\Large{\texttt{pass-global1.bawk}}\begin{lstlisting}
BEGIN {
  int a;
  int b;

  function int add(int x, int y) {
    return x + y;
  }
}

LOOP {}

END {
  a = 1;
  b = 2;
  print(int_to_string(add(a, b)));
}

\end{lstlisting}

\Large{\texttt{pass-global2.bawk}}\begin{lstlisting}
BEGIN {
  int a;
  int b;

  function void printa()
  {
    print(int_to_string(a));
  }

  function void printbb()
  {
    print(int_to_string(b));
  }

  function void incab()
  {
    a = a + 1;
    b = b + 1;
  }
}

LOOP {}

END {
  a = 42;
  b = 21;
  printa();
  printbb();
  incab();
  printa();
  printbb();
}
\end{lstlisting}

\Large{\texttt{pass-global3.bawk}}\begin{lstlisting}
BEGIN {
  bool i;
}

LOOP {}

END {
  int i; # Should hide the global i

  i = 42;
  print(int_to_string(i + i));
}
\end{lstlisting}

\Large{\texttt{pass-helloworld.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  print("Hello World!");
}

CONFIG {}
\end{lstlisting}

\Large{\texttt{pass-helloworldloop.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {
  print("Hello World");
}

END {}

CONFIG {}
\end{lstlisting}

\Large{\texttt{pass-helloworldloopend.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {
  print("Hello loop!");  
}

END {
  print("Hello end!");  
}
\end{lstlisting}

\Large{\texttt{pass-if1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  if (true) {
    print(int_to_string(10));
  }
  print(int_to_string(2));
}
\end{lstlisting}

\Large{\texttt{pass-if2.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  if(true) {
    print(int_to_string(10));
  } 
  else {
    print(int_to_string(5));
  }
  print(int_to_string(2));
}
\end{lstlisting}

\Large{\texttt{pass-if3.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  if(false) {
    print(int_to_string(10));
  } 
  print(int_to_string(2));
}
\end{lstlisting}

\Large{\texttt{pass-if4.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  if(false) {
    print(int_to_string(10));
  } 
  else {
    print(int_to_string(5));
  }
  print(int_to_string(2));
}
\end{lstlisting}

\Large{\texttt{pass-if5.bawk}}\begin{lstlisting}
BEGIN {
  function int cond(bool b) {
    int x;
    if (b) {
      x = 10;
    }
    else {
      x = 5;
    }
    return x;
  }
}

LOOP {}

END {
  print(int_to_string(cond(true)));
  print(int_to_string(cond(false)));
}
\end{lstlisting}

\Large{\texttt{pass-if6.bawk}}\begin{lstlisting}
BEGIN {
  function int cond(bool b) {
    int x;
    if (!b) {
      x = 10;
    }
    else {
      x = 5;
    }
    return x;
  }
}

LOOP {}

END {
  print(int_to_string(cond(true)));
  print(int_to_string(cond(false)));
}
\end{lstlisting}

\Large{\texttt{pass-if7.bawk}}\begin{lstlisting}
BEGIN {
  function int cond(bool b) {
    int x;
    x = 10;
    if (b) {
      if (x == 10) {
        x = 10;
      }
    }
    else {
      x = 5;
    }
    return x;
  }
}

LOOP {}

END {
  print(int_to_string(cond(true)));
  print(int_to_string(cond(false)));
}
\end{lstlisting}

\Large{\texttt{pass-intarr1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int[] a; 
  a = [];
  print(int_to_string(length(a)));
}
\end{lstlisting}

\Large{\texttt{pass-intarr2.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int[] a; 
  a = [1, 2, 3];
  print(int_to_string(length(a)));
}
\end{lstlisting}

\Large{\texttt{pass-intarr3.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int[] a; 
  a = [1, 2, 3];
  print(int_to_string(a[0]));
}
\end{lstlisting}

\Large{\texttt{pass-intarr4.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int[] a; 
  a = [1, 2, 3];
  a[0] = 0;
  print(int_to_string(a[0]));
}
\end{lstlisting}

\Large{\texttt{pass-intarr5.bawk}}\begin{lstlisting}
BEGIN {
  function int[] foo() {
    int[] a; 
    a = [1, 2, 3];
    return a;
  }
}

LOOP {}

END {
  int[] a;
  a = foo();
  print(int_to_string(a[0]));
}
\end{lstlisting}

\Large{\texttt{pass-intarr6.bawk}}\begin{lstlisting}
BEGIN {
  function int[] foo (int[] a) {
    return a;
  }
}

LOOP {}

END {
  int[] a;
  a = [1, 2, 3];
  a = foo(a);
  print(int_to_string(a[0]));
}
\end{lstlisting}

\Large{\texttt{pass-intarr7.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int[][] m;
  int[][][] a;
  int[][][][] b;

  m = [[1, 2], [3, 4]];
  m[0][0] = 20;
  print(int_to_string(m[0][0]));

  a = 
  [
    [ [1, 2], [3, 4] ], [ [5, 6], [7, 8] ]
  ];
  print(int_to_string(a[0][0][0]));

  b = 
  [
    [ [ [1, 2], [3, 4] ], [ [5, 6], [7, 8] ] ], 
    [ [ [9, 10], [11, 12] ], [ [13, 14], [15, 16] ] ]
  ];
  print(int_to_string(b[0][0][0][0]));
}
\end{lstlisting}

\Large{\texttt{pass-intarr8.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int[] a; 
  a = [1, 2, 3];
  print(bool_to_string(contains(a, 1)));
  print(bool_to_string(contains(a, 4)));
}
\end{lstlisting}

\Large{\texttt{pass-intarr9.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int[] a; 
  a = [1, 2, 3];
  print(int_to_string(index_of(a, 1)));
}
\end{lstlisting}

\Large{\texttt{pass-local1.bawk}}\begin{lstlisting}
BEGIN {
  function void foo(bool i)
  {
    int i; # Should hide the formal i 

    i = 42;
    print(int_to_string(i + i));
  }
}

LOOP {}

END {
  foo(true);
}
\end{lstlisting}

\Large{\texttt{pass-local2.bawk}}\begin{lstlisting}
BEGIN {
  function int foo(int a, bool b)
  {
    int c;
    bool d;

    c = a;

    return c + 10;
  }
}

LOOP {}

END {
  print(int_to_string(foo(37, false)));
}
\end{lstlisting}

\Large{\texttt{pass-nf1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {
  print(int_to_string(NF));
}

END {}
\end{lstlisting}

\Large{\texttt{pass-ops1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  print(int_to_string(1 + 2));
  print(int_to_string(1 - 2));
  print(int_to_string(-1 + 2));
  print(int_to_string(1 * 2));
  print(int_to_string(100 / 2));
  print(int_to_string(99));
  print(bool_to_string(1 == 2));
  print(bool_to_string(1 == 1));
  print(int_to_string(99));
  print(bool_to_string(1 != 2));
  print(bool_to_string(1 != 1));
  print(int_to_string(99));
  print(bool_to_string(1 < 2));
  print(bool_to_string(2 < 1));
  print(int_to_string(99));
  print(bool_to_string(1 <= 2));
  print(bool_to_string(1 <= 1));
  print(bool_to_string(2 <= 1));
  print(int_to_string(99));
  print(bool_to_string(1 > 2));
  print(bool_to_string(2 > 1));
  print(int_to_string(99));
  print(bool_to_string(1 >= 2));
  print(bool_to_string(1 >= 1));
  print(bool_to_string(2 >= 1));
}
\end{lstlisting}

\Large{\texttt{pass-ops2.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int x;
  x = 42;
  print(bool_to_string(true));
  print(bool_to_string(false));
  print(bool_to_string(true && true));
  print(bool_to_string(true && false));
  print(bool_to_string(false && true));
  print(bool_to_string(false && false));
  print(bool_to_string(true || true));
  print(bool_to_string(true || false));
  print(bool_to_string(false || true));
  print(bool_to_string(false || false));
  print(bool_to_string(!false));
  print(bool_to_string(!true));
  print(int_to_string(-10));
  print(int_to_string(x--));
  print(int_to_string(x++));
}
\end{lstlisting}

\Large{\texttt{pass-ops3.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  print("hello " & "world");
  print(int_to_string(99));
  print(bool_to_string("hello" == "world"));
  print(bool_to_string("hello" == "hello"));
  print(int_to_string(99));
  print(bool_to_string("hello" != "world"));
  print(bool_to_string("hello" != "hello"));
  print(int_to_string(99));
  print(bool_to_string("hello" < "world"));
  print(bool_to_string("world" < "hello"));
  print(int_to_string(99));
  print(bool_to_string("hello" <= "world"));
  print(bool_to_string("hello" <= "hello"));
  print(bool_to_string("world" <= "hello"));
  print(int_to_string(99));
  print(bool_to_string("hello" > "world"));
  print(bool_to_string("world" > "hello"));
  print(int_to_string(99));
  print(bool_to_string("hello" >= "world"));
  print(bool_to_string("hello" >= "hello"));
  print(bool_to_string("world" >= "hello"));
}
\end{lstlisting}

\Large{\texttt{pass-ops4.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  print(bool_to_string('[0-9]*' % '[0]*'));
  print(bool_to_string('[0-9]*' % '[0-9]*'));
  print(int_to_string(99));
  print(bool_to_string('[0-9]*' !% '[0]*'));
  print(bool_to_string('[0-9]*' !% '[0-9]*'));
  print(int_to_string(99));
  print(bool_to_string("1234" ~ '[0]'));
  print(bool_to_string("1234" ~ '[0-9]*'));
  print(int_to_string(99));
  print(bool_to_string("1234" !~ '[0]'));
  print(bool_to_string("1234" !~ '[0-9]*'));
}
\end{lstlisting}

\Large{\texttt{pass-print.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {
  print(int_to_string(string_to_int("8")));
}

END {}
\end{lstlisting}

\Large{\texttt{pass-printbegin.bawk}}\begin{lstlisting}
BEGIN {
  function void print_begin () {
    print("Hello world");
  }
}
LOOP {}
END {
  print_begin();  
}
\end{lstlisting}

\Large{\texttt{pass-rgx1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  rgx r; 
  r = '[0-9]*';
  print(rgx_to_string(r));
}
\end{lstlisting}

\Large{\texttt{pass-rgx2.bawk}}\begin{lstlisting}
BEGIN {
  function rgx foo() {
    return '[0-9]*';
  }
}

LOOP {}

END {
  print(rgx_to_string(foo()));
}

CONFIG {}
\end{lstlisting}

\Large{\texttt{pass-rgx3.bawk}}\begin{lstlisting}
BEGIN {
  function bool foo(rgx a, rgx b) {
    return a % b;
  }
}

LOOP {}

END {
  print(bool_to_string(foo('[0-9]*', '[0-9]*')));
}

CONFIG {}
\end{lstlisting}

\Large{\texttt{pass-rgx4.bawk}}\begin{lstlisting}
BEGIN {
  function bool foo(rgx a, rgx b) {
    return a !% b;
  }
}

LOOP {}

END {
  print(bool_to_string(foo('[0-9]*', '[0-9]*')));
}

CONFIG {}
\end{lstlisting}

\Large{\texttt{pass-rgx5.bawk}}\begin{lstlisting}
BEGIN {
  function bool foo(string a, rgx b) {
    return a ~ b;
  }
}

LOOP {}

END {
  print(bool_to_string(foo("1234", '[0-9]*')));
}

CONFIG {}
\end{lstlisting}

\Large{\texttt{pass-rgx6.bawk}}\begin{lstlisting}
BEGIN {
  function bool foo(string a, rgx b) {
    return a !~ b;
  }
}

LOOP {}

END {
  print(bool_to_string(foo("1234", '[0]')));
}

CONFIG {}
\end{lstlisting}

\Large{\texttt{pass-rgxarr1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  rgx[] a; 
  a = [];
  print(int_to_string(length(a)));
}
\end{lstlisting}

\Large{\texttt{pass-rgxarr2.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  rgx[] a; 
  a = ['[0]*', '[1]*', '[1]*'];
  print(int_to_string(length(a)));
}
\end{lstlisting}

\Large{\texttt{pass-rgxarr3.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  rgx[] a; 
  a = ['[0]*', '[1]*', '[1]*'];
  print(rgx_to_string(a[0]));
}
\end{lstlisting}

\Large{\texttt{pass-rgxarr4.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  rgx[] a; 
  a = ['[0]*', '[1]*', '[1]*'];
  a[0] = '[2]*';
  print(rgx_to_string(a[0]));
}
\end{lstlisting}

\Large{\texttt{pass-rgxarr5.bawk}}\begin{lstlisting}
BEGIN {
  function rgx[] foo() {
    rgx[] a; 
    a = ['[0]*', '[1]*', '[1]*'];
    return a;
  }
}

LOOP {}

END {
  rgx[] a;
  a = foo();
  print(rgx_to_string(a[0]));
}
\end{lstlisting}

\Large{\texttt{pass-rgxarr6.bawk}}\begin{lstlisting}
BEGIN {
  function rgx[] foo (rgx[] a) {
    return a;
  }
}

LOOP {}

END {
  rgx[] a;
  a = ['[0]*', '[1]*', '[1]*'];
  a = foo(a);
  print(rgx_to_string(a[0]));
}
\end{lstlisting}

\Large{\texttt{pass-rgxarr7.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  rgx[][] m;
  rgx[][][] a;
  rgx[][][][] b;

  m = [['[0*]', '[1*]'], ['[1*]', '[1*]']];
  m[0][0] = '[6*]';
  print(rgx_to_string(m[0][0]));

  a = 
  [
    [ ['[0*]', '[1*]'], ['[1*]', '[1*]'] ], [ ['[1*]', '[1*]'], ['[1*]', '[1*]'] ]
  ];
  print(rgx_to_string(a[0][0][0]));

  b = 
  [
    [ [ ['[0*]', '[1*]'], ['[1*]', '[1*]'] ], [ ['[1*]', '[1*]'], ['[1*]', '[1*]'] ] ], 
    [ [ ['[1*]', '[1*]'], ['[1*]', '[1*]'] ], [ ['[1*]', '[1*]'], ['[1*]', '[1*]'] ] ]
  ];
  print(rgx_to_string(b[0][0][0][0]));
}
\end{lstlisting}

\Large{\texttt{pass-rgxarr8.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  rgx[] a; 
  a = ['[0]*', '[1]*', '[1]*'];
  print(bool_to_string(contains(a, '[0]*')));
  print(bool_to_string(contains(a, '[2]*')));
}
\end{lstlisting}

\Large{\texttt{pass-rgxarr9.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  rgx[] a; 
  a = ['[0]*', '[1]*', '[1]*'];
  print(int_to_string(index_of(a, '[0]*')));
}
\end{lstlisting}

\Large{\texttt{pass-strarr1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  string[] a; 
  a = [];
  print(int_to_string(length(a)));
}
\end{lstlisting}

\Large{\texttt{pass-strarr2.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  string[] a; 
  a = ["a", "b", "c"];
  print(int_to_string(length(a)));
}
\end{lstlisting}

\Large{\texttt{pass-strarr3.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  string[] a; 
  a = ["a", "b", "c"];
  print(a[0]);
}
\end{lstlisting}

\Large{\texttt{pass-strarr4.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  string[] a; 
  a = ["a", "b", "c"];
  a[0] = "p";
  print(a[0]);
}
\end{lstlisting}

\Large{\texttt{pass-strarr5.bawk}}\begin{lstlisting}
BEGIN {
  function string[] foo() {
    string[] a; 
    a = ["a", "b", "c"];
    return a;
  }
}

LOOP {}

END {
  string[] a;
  a = foo();
  print(a[0]);
}
\end{lstlisting}

\Large{\texttt{pass-strarr6.bawk}}\begin{lstlisting}
BEGIN {
  function string[] foo (string[] a) {
    return a;
  }
}

LOOP {}

END {
  string[] a;
  a = ["a", "b", "c"];
  a = foo(a);
  print(a[0]);
}
\end{lstlisting}

\Large{\texttt{pass-strarr7.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  string[][] m;
  string[][][] a;
  string[][][][] b;

  m = [["a", "b"], ["c", "d"]];
  m[0][0] = "hi";
  print(m[0][0]);

  a = 
  [
    [ ["a", "b"], ["c", "d"] ], [ ["e", "f"], ["g", "h"] ]
  ];
  print(a[0][0][0]);

  b = 
  [
    [ [ ["a", "b"], ["c", "d"] ], [ ["e", "f"], ["g", "h"] ] ], 
    [ [ ["i", "j"], ["k", "l"] ], [ ["m", "n"], ["o", "p"] ] ]
  ];
  print(b[0][0][0][0]);
}
\end{lstlisting}

\Large{\texttt{pass-strarr8.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  string[] a; 
  a = ["a", "b", "c"];
  print(bool_to_string(contains(a, "a")));
  print(bool_to_string(contains(a, "e")));
}
\end{lstlisting}

\Large{\texttt{pass-strarr9.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  string[] a; 
  a = ["a", "b", "c"];
  print(int_to_string(index_of(a, "a")));
}
\end{lstlisting}

\Large{\texttt{pass-string1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  string s;
  s = "hello";
  print(s);
}
\end{lstlisting}

\Large{\texttt{pass-string2.bawk}}\begin{lstlisting}
BEGIN {
  function string foo() {
    return "hello";
  }
}

LOOP {}

END {
  print(foo());
}

CONFIG {}
\end{lstlisting}

\Large{\texttt{pass-string3.bawk}}\begin{lstlisting}
BEGIN {
  function string concat(string a, string b) {
    return a & b;
  }
}

LOOP {}

END {
  print(concat("hello ", "world"));
}

CONFIG {}
\end{lstlisting}

\Large{\texttt{pass-string4.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int x;
  string s;
  
  s = "3";
  x = string_to_int(s);
  print(int_to_string(x));
}
\end{lstlisting}

\Large{\texttt{pass-while1.bawk}}\begin{lstlisting}
BEGIN {}

LOOP {}

END {
  int i;
  i = 5;
  while (i > 0) {
    print(int_to_string(i));
    i = i - 1;
  }
  print(int_to_string(42));
}
\end{lstlisting}

\Large{\texttt{pass-while2.bawk}}\begin{lstlisting}
BEGIN {
  function int foo(int a)
  {
    int j;
    j = 0;
    while (a > 0) {
      j = j + 2;
      a = a - 1;
    }
    return j;
  }
}

LOOP {}

END {
  print(int_to_string(foo(7)));
}
\end{lstlisting}

