Skip to content
Snippets Groups Projects
Verified Commit 61df89a5 authored by Martin Sjölund's avatar Martin Sjölund
Browse files

Add the old instructions

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 131 additions and 0 deletions
File added
File added
File added
File added
File added
Source diff could not be displayed: it is too large. Options to address this: view the blob.
File added
This diff is collapsed.
File added
This diff is collapsed.
File added
This diff is collapsed.
File added
This diff is collapsed.
File added
This diff is collapsed.
CC = g++
CCFLAGS = -g
LDFLAGS =
lab1 : lex.o main.o lab1.o
$(CC) -o lab1 $(CCFLAGS) $(LDFLAGS) lex.o main.o lab1.o
lex.o: lex.hh lex.cc
$(CC) $(CFLAGS) -c lex.cc
lab1.o: lab1.hh lex.hh lab1.cc
$(CC) $(CFLAGS) -c lab1.cc
main.o: lab1.hh lex.hh main.cc
$(CC) $(CFLAGS) -c main.cc
clean:
rm *.o lab1
#include "lab1.hh"
//
// The trace class needs a class variable. This is it
//
int Trace::indent = 0;
//
// Parse should be the entry point to your parser class. It will be
// called by the main program, which you also have to write.
//
double Parser::Parse(void)
{
Trace x("Parse"); // Trace execution of Parse
double val; // Value of a statement
val = 0;
/* --- Your code here ---
*
* 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.
*/
/* --- End your code --- */
return val;
}
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.
*/
/* --- End your code --- */
}
//
// parser.hh
//
// Skeleton header file for your parser class. You will probably need more
// methods and instance variables in the parser class.
//
#ifndef KOMP_LABONE_H
#define KOMP_LABONE_H
#include <iostream>
#include "lex.hh"
using namespace std;
class Parser
{
public:
void Recover(void); // Error recovery routine
double Parse(void); // Main entry point
};
class Trace
{
static int indent;
char *name;
public:
Trace(char *s)
{
name = s;
cerr.width(indent);
cerr << " ";
cerr << "--> " << name << '\n' << flush;
indent += 4;
};
~Trace()
{
indent -= 4;
cerr.width(indent);
cerr << "";
cerr << "<-- " << name << '\n' << flush;
};
};
//
// Two error classes that you may find useful. You can thrown
// ParserError to signal an error in parsing and ParserEndOfFile to
// signal an end of file. There are other alternatives to error
// reporting that may be more convenient.
//
class ParserError {};
class ParserEndOfFile {};
#endif
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment