From 8bc1e0b87fa318a50647f4776c31f4f3b7cf6a11 Mon Sep 17 00:00:00 2001
From: johti17 <johti17@tlvm-4-1-1.ad.liu.se>
Date: Tue, 31 Oct 2023 17:32:44 +0100
Subject: [PATCH] Removed tab from Lab-1/Lab-2 Also added a test that tasks the
 students to deal with tabs

---
 lab1/main.cc   |  4 ++--
 lab1/test/code | 33 +++++++++++++++++++++++++++++++++
 lab2/lab2.cc   |  8 ++++----
 lab2/lab2.hh   |  1 +
 lab2/lex.cc    |  5 ++---
 lab2/main.cc   |  2 +-
 6 files changed, 43 insertions(+), 10 deletions(-)
 create mode 100644 lab1/test/code

diff --git a/lab1/main.cc b/lab1/main.cc
index 66bbd5c..eb7c18e 100644
--- a/lab1/main.cc
+++ b/lab1/main.cc
@@ -75,7 +75,7 @@ int main(int argc, char **argv)
     int     token;
     extern  FILE *yyin;
     extern  int yylex();
-    
+
     /*
      * Open the input file, if any
      */
@@ -92,7 +92,7 @@ int main(int argc, char **argv)
             perror(argv[1]);
             exit(1);
         }
-        break;	
+        break;
     default:
         cerr << "Usage: " << argv[0] << " [ filename ]\n";
         exit(1);
diff --git a/lab1/test/code b/lab1/test/code
new file mode 100644
index 0000000..d2e0107
--- /dev/null
+++ b/lab1/test/code
@@ -0,0 +1,33 @@
+/*
+	This test checks the fibonacci function
+	Author: John Tinnerholm
+*/
+declare
+a : integer;
+function fib (x : integer) : integer
+begin
+  if x == 0 then
+    begin
+      return 0;
+    end
+  elseif x == 1 then
+    begin
+      return 1;
+    end
+  else
+    begin
+      return fib(x - 1) + fib(x-2);
+    end
+  if;
+end;
+
+begin
+  a := 0;
+  while a < 10 do
+    begin
+      putint(fib(a));
+      putline();
+      a := a + 1;
+    end
+  while;
+end;
diff --git a/lab2/lab2.cc b/lab2/lab2.cc
index dfbe98a..c88aa5f 100644
--- a/lab2/lab2.cc
+++ b/lab2/lab2.cc
@@ -25,7 +25,7 @@ double Parser::Parse(void)
      * Parse the input using recursive descent parsing. You'll need
      * an object of type Scanner to get tokens from the input. Call
      * the Scan method of this object to get the next token in the
-     * input stream. 
+     * input stream.
      */
 
     /* --- End your code --- */
@@ -37,17 +37,17 @@ void Parser::Recover(void)
 {
 
     cerr << "Error recovery.\n" << flush;
-    
+
     /* --- Your code here ---
      *
      * Error recovery routine
-     * 
+     *
      * Unless you come up with something better, this function should
      * scan tokens until it sees the end of line or end of file.
      * Parsing may be resumed at that point. This means that if an end
      * of line token caused the error, this routine doesn't need to do
      * anything.
-     * 
+     *
      * Be sure not to scan more tokens than necessary, or it won't be
      * possible to resume parsing.
      */
diff --git a/lab2/lab2.hh b/lab2/lab2.hh
index ca7d04d..77e11fc 100644
--- a/lab2/lab2.hh
+++ b/lab2/lab2.hh
@@ -17,6 +17,7 @@ using namespace std;
 class Parser
 {
 public:
+    Scanner scanner;
     void Recover(void);         // Error recovery routine
     double Parse(void);         // Main entry point
 };
diff --git a/lab2/lex.cc b/lab2/lex.cc
index 5702079..c763b4b 100644
--- a/lab2/lex.cc
+++ b/lab2/lex.cc
@@ -81,12 +81,12 @@ void Scanner::PutbackChar(unsigned char c)
 Token Scanner::Scan(void)
 {
     int c;
-    
+
     Reset();
     while (1)
     {
         c = GetChar();
-        
+
         switch (state)
         {
         case 0:                     // Initial state
@@ -311,7 +311,6 @@ ostream& operator<<(ostream& s, ScannerError& e)
 // Lookup just returns the textual representation of a token type. The
 // no argument version returns the type of the token.
 //
-
 const char *Token::Lookup(void)
 {
     return kTokenTypeNames[type];
diff --git a/lab2/main.cc b/lab2/main.cc
index da1d48b..49a4e43 100644
--- a/lab2/main.cc
+++ b/lab2/main.cc
@@ -14,7 +14,7 @@ int main(void)
         try
         {
             cout << "Expression: " << flush;
-	    /* Implement the parser.Parse method */
+            /* Implement the parser.Parse method */
             val = parser.Parse();
             cout << "Result:     " << val << '\n' << flush;
         }
-- 
GitLab