Skip to content
Snippets Groups Projects
Commit 8bc1e0b8 authored by johti17's avatar johti17
Browse files

Removed tab from Lab-1/Lab-2 Also added a test that tasks the students to deal with tabs

parent 720c00cd
No related branches found
No related tags found
1 merge request!4Updates cpp 2023
...@@ -75,7 +75,7 @@ int main(int argc, char **argv) ...@@ -75,7 +75,7 @@ int main(int argc, char **argv)
int token; int token;
extern FILE *yyin; extern FILE *yyin;
extern int yylex(); extern int yylex();
/* /*
* Open the input file, if any * Open the input file, if any
*/ */
...@@ -92,7 +92,7 @@ int main(int argc, char **argv) ...@@ -92,7 +92,7 @@ int main(int argc, char **argv)
perror(argv[1]); perror(argv[1]);
exit(1); exit(1);
} }
break; break;
default: default:
cerr << "Usage: " << argv[0] << " [ filename ]\n"; cerr << "Usage: " << argv[0] << " [ filename ]\n";
exit(1); exit(1);
......
/*
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;
...@@ -25,7 +25,7 @@ double Parser::Parse(void) ...@@ -25,7 +25,7 @@ double Parser::Parse(void)
* Parse the input using recursive descent parsing. You'll need * Parse the input using recursive descent parsing. You'll need
* an object of type Scanner to get tokens from the input. Call * 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 * the Scan method of this object to get the next token in the
* input stream. * input stream.
*/ */
/* --- End your code --- */ /* --- End your code --- */
...@@ -37,17 +37,17 @@ void Parser::Recover(void) ...@@ -37,17 +37,17 @@ void Parser::Recover(void)
{ {
cerr << "Error recovery.\n" << flush; cerr << "Error recovery.\n" << flush;
/* --- Your code here --- /* --- Your code here ---
* *
* Error recovery routine * Error recovery routine
* *
* Unless you come up with something better, this function should * Unless you come up with something better, this function should
* scan tokens until it sees the end of line or end of file. * 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 * 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 * of line token caused the error, this routine doesn't need to do
* anything. * anything.
* *
* Be sure not to scan more tokens than necessary, or it won't be * Be sure not to scan more tokens than necessary, or it won't be
* possible to resume parsing. * possible to resume parsing.
*/ */
......
...@@ -17,6 +17,7 @@ using namespace std; ...@@ -17,6 +17,7 @@ using namespace std;
class Parser class Parser
{ {
public: public:
Scanner scanner;
void Recover(void); // Error recovery routine void Recover(void); // Error recovery routine
double Parse(void); // Main entry point double Parse(void); // Main entry point
}; };
......
...@@ -81,12 +81,12 @@ void Scanner::PutbackChar(unsigned char c) ...@@ -81,12 +81,12 @@ void Scanner::PutbackChar(unsigned char c)
Token Scanner::Scan(void) Token Scanner::Scan(void)
{ {
int c; int c;
Reset(); Reset();
while (1) while (1)
{ {
c = GetChar(); c = GetChar();
switch (state) switch (state)
{ {
case 0: // Initial state case 0: // Initial state
...@@ -311,7 +311,6 @@ ostream& operator<<(ostream& s, ScannerError& e) ...@@ -311,7 +311,6 @@ ostream& operator<<(ostream& s, ScannerError& e)
// Lookup just returns the textual representation of a token type. The // Lookup just returns the textual representation of a token type. The
// no argument version returns the type of the token. // no argument version returns the type of the token.
// //
const char *Token::Lookup(void) const char *Token::Lookup(void)
{ {
return kTokenTypeNames[type]; return kTokenTypeNames[type];
......
...@@ -14,7 +14,7 @@ int main(void) ...@@ -14,7 +14,7 @@ int main(void)
try try
{ {
cout << "Expression: " << flush; cout << "Expression: " << flush;
/* Implement the parser.Parse method */ /* Implement the parser.Parse method */
val = parser.Parse(); val = parser.Parse();
cout << "Result: " << val << '\n' << flush; cout << "Result: " << val << '\n' << flush;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment