diff --git a/lab1/main.cc b/lab1/main.cc index 66bbd5c8f15ba0243edd0d72c24224e755c62b9a..eb7c18e9a7bea33b934184f120cd6e15a40d016d 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 0000000000000000000000000000000000000000..d2e0107ca746e65c6b4d7274de79abf4e60b8d56 --- /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 dfbe98afe36bc8871c1295f742bb41ca169705a5..c88aa5f80a965f8974f34c4d7a7abb1884bbf195 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 ca7d04db1fc851e8f0e777eb0f9fa224a66d47e6..77e11fcdd1f8297240d85c68737e3ac4bd14a3a2 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 57020795a4d41fe7e2b8e7191ee033fd4c43b1f6..c763b4be3e04d51589079000a180c4fa9f737c6e 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 da1d48b997cc0bd674af3b49e42df336f86d8b9e..49a4e43e1bd28ec5f925e1860f347f3428497fc6 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; }