diff --git a/lab1/main.cc b/lab1/main.cc index 216ced2f461bb53c77875b768c6a694c517016e3..eb7c18e9a7bea33b934184f120cd6e15a40d016d 100644 --- a/lab1/main.cc +++ b/lab1/main.cc @@ -10,7 +10,7 @@ using namespace std; typedef struct { int token; - char *name; + const char *name; } tTokenName; @@ -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/Makefile b/lab2/Makefile index fd270a32ae6a0d1d1e8ae15f479ab3983fe5356b..ad10420bc2c83f861329add376daea08fadfec5e 100644 --- a/lab2/Makefile +++ b/lab2/Makefile @@ -1,5 +1,6 @@ CC = g++ CCFLAGS = -g +CFLAGS = -g LDFLAGS = lab2 : lex.o main.o lab2.o 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 892c4d0060c6de5743689ab54aa26f5b9e5fc336..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 }; @@ -24,10 +25,10 @@ public: class Trace { static int indent; - char *name; + const char *name; public: - Trace(char *s) + Trace(const char *s) { name = s; cerr.width(indent); diff --git a/lab2/lex.cc b/lab2/lex.cc index 272efdf479cbcddc4ce9f41170962b4ffdf70ca2..c763b4be3e04d51589079000a180c4fa9f737c6e 100644 --- a/lab2/lex.cc +++ b/lab2/lex.cc @@ -8,7 +8,7 @@ // Human-readable representations of token types // -static char *kTokenTypeNames[] = +static const char *kTokenTypeNames[] = { "uninitialized", "number", @@ -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 @@ -238,7 +238,7 @@ Token Scanner::Scan(void) // multiple-character token. // -void Scanner::Accumulate(char c) +void Scanner::Accumulate(const char c) { if (position >= kMaxTokenLength) { @@ -311,13 +311,12 @@ 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. // - -char *Token::Lookup(void) +const char *Token::Lookup(void) { return kTokenTypeNames[type]; } -char *Token::Lookup(TokenType t) +const char *Token::Lookup(TokenType t) { return kTokenTypeNames[t]; } diff --git a/lab2/lex.hh b/lab2/lex.hh index ac3dc0301e5bc5b62a25dcfe790854627884ddb5..d24cf4dab8af0050d108d0b74329886bced60a0c 100644 --- a/lab2/lex.hh +++ b/lab2/lex.hh @@ -30,11 +30,11 @@ class ScannerError { public: char errorCharacter; - char *message; + const char *message; int state; ScannerError(char c, int s) : errorCharacter(c), state(s) {}; - ScannerError(char *s) : message(s) {}; + ScannerError(const char *s) : message(s) {}; ScannerError() : errorCharacter(0) {}; }; @@ -86,8 +86,8 @@ public: double numberValue; char *symbolValue; - char *Lookup(TokenType); - char *Lookup(void); + const char *Lookup(TokenType); + const char *Lookup(void); Token() : type(kUninitialized) {}; Token(TokenType t) : type(t) {}; Token(TokenType t, double x) : type(t), numberValue(x) {}; diff --git a/lab2/main.cc b/lab2/main.cc index 32a5458b06675d72bef7ffe811cc52ac633fc77c..49a4e43e1bd28ec5f925e1860f347f3428497fc6 100644 --- a/lab2/main.cc +++ b/lab2/main.cc @@ -9,11 +9,12 @@ int main(void) Parser parser; double val; - while (1) + while (true) { try { cout << "Expression: " << flush; + /* Implement the parser.Parse method */ val = parser.Parse(); cout << "Result: " << val << '\n' << flush; } diff --git a/lab3-4/Makefile.dependencies b/lab3-4/Makefile.dependencies index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..a87ec84413b39881b59bf29f39db2a4b10344677 100644 --- a/lab3-4/Makefile.dependencies +++ b/lab3-4/Makefile.dependencies @@ -0,0 +1,5 @@ +symtab.o: symtab.cc symtab.hh string.hh ast.hh codegen.hh +ast.o: ast.cc ast.hh symtab.hh string.hh codegen.hh +codegen.o: codegen.cc ast.hh symtab.hh string.hh codegen.hh +main.o: main.cc ast.hh symtab.hh string.hh codegen.hh parser.hh +string.o: string.cc string.hh diff --git a/lab3-4/ast.cc b/lab3-4/ast.cc index 3a640a5a7ccb414626e0a6156f6442861c9515d1..d62488c940bbec8a886c99bfed45340dc2ea77cf 100644 --- a/lab3-4/ast.cc +++ b/lab3-4/ast.cc @@ -45,7 +45,7 @@ void ASTNode::print(ostream& o) o << "ASTNode"; } -void ASTNode::xprint(ostream& o, char *cls) +void ASTNode::xprint(ostream& o, const char *cls) { o << "ASTNode (" << cls << ")"; } @@ -228,7 +228,7 @@ void BinaryOperation::print(ostream& o) xprint(o, "BinaryOperation"); } -void BinaryOperation::xprint(ostream& o, char *cls) +void BinaryOperation::xprint(ostream& o, const char *cls) { o << cls << " (left, right) [" << ShortSymbols << valueType << LongSymbols @@ -241,7 +241,7 @@ void BinaryOperation::xprint(ostream& o, char *cls) endChild(o); } -void Plus::print(ostream& o) { xprint(o, "Plus"); } // +void Plus::print(ostream& o) { xprint(o, "Plus"); } // void Minus::print(ostream& o) { xprint(o, "Minus"); } void Times::print(ostream& o) { xprint(o, "Times"); } void Divide::print(ostream& o) {xprint(o, "Divide"); } @@ -293,7 +293,7 @@ void BinaryRelation::print(ostream& o) xprint(o, "BinaryRelation"); } -void BinaryRelation::xprint(ostream& o, char *cls) +void BinaryRelation::xprint(ostream& o, const char *cls) { o << cls << " (left, right)\n"; beginChild(o); @@ -316,7 +316,7 @@ void BinaryCondition::print(ostream& o) xprint(o, "BinaryCondition"); } -void BinaryCondition::xprint(ostream& o, char *cls) +void BinaryCondition::xprint(ostream& o, const char *cls) { o << cls << " (left, right)\n"; beginChild(o); @@ -328,7 +328,7 @@ void BinaryCondition::xprint(ostream& o, char *cls) } void And::print(ostream& o) { xprint(o, "And"); } -void Or::print(ostream& o) { xprint(o, "Or"); } // +void Or::print(ostream& o) { xprint(o, "Or"); } // void Not::print(ostream& o) { diff --git a/lab3-4/ast.hh b/lab3-4/ast.hh index 7f886b902358683a65c6313d1bf4cfdc1e9f3b20..07c72669bb52fdcb12a8d1cee75c3b21d8ecdebb 100644 --- a/lab3-4/ast.hh +++ b/lab3-4/ast.hh @@ -59,7 +59,7 @@ protected: void endChild(ostream& o); void lastChild(ostream& o); virtual void print(ostream& o); - virtual void xprint(ostream& o, char* cls); + virtual void xprint(ostream& o, const char* cls); public: virtual VariableInformation *GenerateCode(QuadsList &q) = 0; @@ -318,7 +318,7 @@ class BinaryOperation : public Expression { protected: virtual void print(ostream& o); - virtual void xprint(ostream& o, char *); + virtual void xprint(ostream& o, const char *); public: Expression *left, *right; @@ -480,7 +480,7 @@ class BinaryRelation : public Condition { protected: virtual void print(ostream& o); - virtual void xprint(ostream& o, char *cls); + virtual void xprint(ostream& o, const char *cls); public: Expression *left; @@ -563,7 +563,7 @@ class BinaryCondition : public Condition { protected: virtual void print(ostream& o); - virtual void xprint(ostream&o, char *cls); + virtual void xprint(ostream&o, const char *cls); public: Condition *left, *right; diff --git a/lab3-4/codegen.cc b/lab3-4/codegen.cc index a49b68265f38f3674f39b3b18251ffd777455ef8..66697a24ef78324fd3ad0c559a64b0f38073815f 100644 --- a/lab3-4/codegen.cc +++ b/lab3-4/codegen.cc @@ -21,10 +21,10 @@ long QuadsList::labelCounter; * parse tree, but ensure that all exits from the code end up at a * particular label. This is easy to do for most parts of the parse * tree: just generate the code in the usual manner, then jump to the - * label. + * label. */ - + VariableInformation *ASTNode::GenerateCodeAndJump(QuadsList& q, long label) { @@ -51,15 +51,9 @@ VariableInformation *ASTNode::GenerateCodeAndJump(QuadsList& q, VariableInformation *ElseIfList::GenerateCodeAndJump(QuadsList &q, long lbl) { - long next; - VariableInformation *info; - /* --- Your code here --- */ - /* --- End your code --- */ - return NULL; - } @@ -74,7 +68,6 @@ void ArrayReference::GenerateAssignment(QuadsList& q, VariableInformation *val) { /* --- Your code here --- */ - /* --- End your code --- */ } @@ -94,17 +87,17 @@ void Identifier::GenerateAssignment(QuadsList& q, VariableInformation *val) } if (id->type == kIntegerType) { - q += new Quad(iassign, - dynamic_cast<SymbolInformation*>(val), - static_cast<SymbolInformation*>(NULL), - dynamic_cast<SymbolInformation*>(id)); + q += new Quad(iassign, + dynamic_cast<SymbolInformation*>(val), + static_cast<SymbolInformation*>(NULL), + dynamic_cast<SymbolInformation*>(id)); } else if (id->type == kRealType) { - q += new Quad(rassign, - dynamic_cast<SymbolInformation*>(val), - static_cast<SymbolInformation*>(NULL), - dynamic_cast<SymbolInformation*>(id)); + q += new Quad(rassign, + dynamic_cast<SymbolInformation*>(val), + static_cast<SymbolInformation*>(NULL), + dynamic_cast<SymbolInformation*>(id)); } else if (id->type == val->type) { @@ -118,7 +111,7 @@ void Identifier::GenerateAssignment(QuadsList& q, VariableInformation *val) * * Generate code for a list of statements. Make sure the code comes * out in the right order. - * + * * Note: The impelementation here is absolutely ridiculous since it * uses stack space proportional to the number of statements in the * list. A more sensible definition would simply iterate down the @@ -140,19 +133,16 @@ VariableInformation *StatementList::GenerateCode(QuadsList &q) /* * IfStatement::GenerateCode * - * If statements, particularly those with elseif branches are actually + * If statements, particularly those with elseif branches are actually * quite involved. They tend to use a lot of jumps. For the elseif - * branches you'll probably want to use the GenerateCodeAndJump method + * branches you'll probably want to use the GenerateCodeAndJump method * of ElseIfStatement (which you're also supposed to write.) */ VariableInformation *IfStatement::GenerateCode(QuadsList& q) { /* --- Your code here ---*/ - - /* --- End your code --- */ - return NULL; } @@ -168,13 +158,9 @@ VariableInformation *IfStatement::GenerateCode(QuadsList& q) VariableInformation *ElseIfList::GenerateCode(QuadsList& q) { - USEQ; - /* --- Your code here --- */ - /* --- End your code --- */ - - cerr << "Call to ElseIfList::GenerateCode. You probably didn't want to do this.\n"; // + cerr << "Call to ElseIfList::GenerateCode. You probably didn't want to do this.\n"; // abort(); } @@ -254,15 +240,15 @@ VariableInformation *BooleanConstant::GenerateCode(QuadsList& q) VariableInformation *ArrayReference::GenerateCode(QuadsList& q) { - /* --- Your code here --- */ - - /* --- End your code --- */ +/* --- Your code here --- */ + return NULL; +/* --- End your code --- */ } /* * Identifier::GenerateCode * - * Generate code to get the value of an identifier. Actually, we don't + * Generate code to get the value of an identifier. Actually, we don't * need to generate any code at all. We just return the identifier. */ @@ -291,14 +277,14 @@ VariableInformation *ReturnStatement::GenerateCode(QuadsList &q) abort(); } - q += new Quad(creturn, - static_cast<SymbolInformation*>(NULL), - static_cast<SymbolInformation*>(NULL), - dynamic_cast<SymbolInformation*>(info)); + q += new Quad(creturn, + static_cast<SymbolInformation*>(NULL), + static_cast<SymbolInformation*>(NULL), + dynamic_cast<SymbolInformation*>(info)); return NULL; } - + /* * ExpressionList::GenerateCode @@ -337,10 +323,10 @@ void ExpressionList::GenerateParameterList(QuadsList &q, if (expression->valueType == lastParam->type) { - q += new Quad(param, - dynamic_cast<SymbolInformation*>(info), - static_cast<SymbolInformation*>(NULL), - static_cast<SymbolInformation*>(NULL)); + q += new Quad(param, + dynamic_cast<SymbolInformation*>(info), + static_cast<SymbolInformation*>(NULL), + static_cast<SymbolInformation*>(NULL)); } else { @@ -348,7 +334,7 @@ void ExpressionList::GenerateParameterList(QuadsList &q, abort(); } } - + @@ -394,10 +380,10 @@ VariableInformation *IntegerToReal::GenerateCode(QuadsList& q) info = currentFunction->TemporaryVariable(kRealType); valueInfo = value->GenerateCode(q); - q += new Quad(itor, - dynamic_cast<SymbolInformation*>(valueInfo), - static_cast<SymbolInformation*>(NULL), - dynamic_cast<SymbolInformation*>(info)); + q += new Quad(itor, + dynamic_cast<SymbolInformation*>(valueInfo), + static_cast<SymbolInformation*>(NULL), + dynamic_cast<SymbolInformation*>(info)); return info; } @@ -413,10 +399,10 @@ VariableInformation *TruncateReal::GenerateCode(QuadsList& q) info = currentFunction->TemporaryVariable(kIntegerType); valueInfo = value->GenerateCode(q); - q += new Quad(rtrunc, - dynamic_cast<SymbolInformation*>(valueInfo), - static_cast<SymbolInformation*>(NULL), - dynamic_cast<SymbolInformation*>(info)); + q += new Quad(rtrunc, + dynamic_cast<SymbolInformation*>(valueInfo), + static_cast<SymbolInformation*>(NULL), + dynamic_cast<SymbolInformation*>(info)); return info; } @@ -460,11 +446,9 @@ static VariableInformation *BinaryGenerateCode(QuadsList& q, ASTNode *node, TypeInformation *type = NULL) { - VariableInformation *leftInfo, *rightInfo, *result; - - /* --- Your code here --- */ - - /* --- End your code --- */ + /* --- Your code here --- */ + return NULL; + /* --- End your code --- */ } /* @@ -595,9 +579,9 @@ VariableInformation *NotEqual::GenerateCode(QuadsList& q) r0 = BinaryGenerateCode(q, req, ieq, left, right, this, kIntegerType); auto result = currentFunction->TemporaryVariable(kIntegerType); q += new Quad(inot, - dynamic_cast<SymbolInformation*>(r0), - static_cast<SymbolInformation*>(NULL), - dynamic_cast<SymbolInformation*>(result)); + dynamic_cast<SymbolInformation*>(r0), + static_cast<SymbolInformation*>(NULL), + dynamic_cast<SymbolInformation*>(result)); return r0; } @@ -637,10 +621,10 @@ VariableInformation *Not::GenerateCode(QuadsList& q) } result = currentFunction->TemporaryVariable(kIntegerType); - q += new Quad(inot, - dynamic_cast<SymbolInformation*>(info), - static_cast<SymbolInformation*>(NULL), - dynamic_cast<SymbolInformation*>(result)); + q += new Quad(inot, + dynamic_cast<SymbolInformation*>(info), + static_cast<SymbolInformation*>(NULL), + dynamic_cast<SymbolInformation*>(result)); return result; } @@ -665,10 +649,10 @@ VariableInformation *FunctionCall::GenerateCode(QuadsList& q) if (arguments) arguments->GenerateParameterList(q, function->GetLastParam()); info = currentFunction->TemporaryVariable(function->GetReturnType()); - q += new Quad(call, - dynamic_cast<SymbolInformation*>(function), - static_cast<SymbolInformation*>(NULL), - dynamic_cast<SymbolInformation*>(info)); + q += new Quad(call, + dynamic_cast<SymbolInformation*>(function), + static_cast<SymbolInformation*>(NULL), + dynamic_cast<SymbolInformation*>(info)); return info; } @@ -719,242 +703,242 @@ ostream& Quad::print(ostream& o) { case iconst: o << setw(8) << "iconst " - << setw(8) << int1 - << setw(8) <<"-" + << setw(8) << int1 + << setw(8) <<"-" << setw(8) <<sym3; break; case rconst: o << setw(8) <<"rconst " << setw(8) <<real1 - << setw(8) <<"-" + << setw(8) <<"-" << setw(8) <<sym3; break; case iaddr: o << setw(8) <<"iaddr " - << setw(8) <<sym1 - << setw(8) <<"-" + << setw(8) <<sym1 + << setw(8) <<"-" << setw(8) <<sym3; break; - case itor: + case itor: o << setw(8) <<"itor " - << setw(8) <<sym1 - << setw(8) <<"-" + << setw(8) <<sym1 + << setw(8) <<"-" << setw(8) <<sym3; break; - case rtrunc: + case rtrunc: o << setw(8) <<"rtrunc " - << setw(8) <<sym1 - << setw(8) <<"-" + << setw(8) <<sym1 + << setw(8) <<"-" << setw(8) <<sym3; break; - case iadd: + case iadd: o << setw(8) << "iadd " - << setw(8) << sym1 - << setw(8) << sym2 + << setw(8) << sym1 + << setw(8) << sym2 << setw(8) << sym3; break; - case isub: + case isub: o << setw(8) << "isub " - << setw(8) << sym1 - << setw(8) << sym2 + << setw(8) << sym1 + << setw(8) << sym2 << setw(8) << sym3; break; - case imul: + case imul: o << setw(8) << "imul " - << setw(8) << sym1 - << setw(8) << sym2 + << setw(8) << sym1 + << setw(8) << sym2 << setw(8) << sym3; break; - case idiv: + case idiv: o << setw(8) << "idiv " - << setw(8) << sym1 - << setw(8) << sym2 + << setw(8) << sym1 + << setw(8) << sym2 << setw(8) << sym3; break; - case ipow: + case ipow: o << setw(8) << "ipow " - << setw(8) << sym1 - << setw(8) << sym2 + << setw(8) << sym1 + << setw(8) << sym2 << setw(8) << sym3; break; - case radd: + case radd: o << setw(8) << "radd " - << setw(8) << sym1 - << setw(8) << sym2 + << setw(8) << sym1 + << setw(8) << sym2 << setw(8) << sym3; break; - case rsub: + case rsub: o << setw(8) << "rsub " - << setw(8) << sym1 - << setw(8) << sym2 + << setw(8) << sym1 + << setw(8) << sym2 << setw(8) << sym3; break; - case rmul: + case rmul: o << setw(8) << "rmul " - << setw(8) << sym1 - << setw(8) << sym2 + << setw(8) << sym1 + << setw(8) << sym2 << setw(8) << sym3; break; - case rdiv: + case rdiv: o << setw(8) << "rdiv " - << setw(8) << sym1 - << setw(8) << sym2 + << setw(8) << sym1 + << setw(8) << sym2 << setw(8) << sym3; break; - case rpow: + case rpow: o << setw(8) << "rpow " - << setw(8) << sym1 - << setw(8) << sym2 + << setw(8) << sym1 + << setw(8) << sym2 << setw(8) << sym3; break; - case igt: + case igt: o << setw(8) << "igt " - << setw(8) << sym1 - << setw(8) << sym2 + << setw(8) << sym1 + << setw(8) << sym2 << setw(8) << sym3; break; - case ilt: + case ilt: o << setw(8) << "ilt " - << setw(8) << sym1 - << setw(8) << sym2 + << setw(8) << sym1 + << setw(8) << sym2 << setw(8) << sym3; break; - case ieq: + case ieq: o << setw(8) << "ieq " - << setw(8) << sym1 - << setw(8) << sym2 + << setw(8) << sym1 + << setw(8) << sym2 << setw(8) << sym3; break; - case rgt: + case rgt: o << setw(8) << "rgt " - << setw(8) << sym1 - << setw(8) << sym2 + << setw(8) << sym1 + << setw(8) << sym2 << setw(8) << sym3; break; - case rlt: + case rlt: o << setw(8) << "rlt " - << setw(8) << sym1 - << setw(8) << sym2 + << setw(8) << sym1 + << setw(8) << sym2 << setw(8) << sym3; break; - case req: + case req: o << setw(8) << "req " - << setw(8) << sym1 - << setw(8) << sym2 + << setw(8) << sym1 + << setw(8) << sym2 << setw(8) << sym3; break; - case iand: + case iand: o << setw(8) << "iand " - << setw(8) << sym1 - << setw(8) << sym2 + << setw(8) << sym1 + << setw(8) << sym2 << setw(8) << sym3; break; - case ior: + case ior: o << setw(8) << "ior " - << setw(8) << sym1 - << setw(8) << sym2 + << setw(8) << sym1 + << setw(8) << sym2 << setw(8) << sym3; break; - case inot: + case inot: o << setw(8) << "inot " - << setw(8) << sym1 - << setw(8) << "-" + << setw(8) << sym1 + << setw(8) << "-" << setw(8) << sym3; break; - case jtrue: + case jtrue: o << setw(8) << "jtrue " - << setw(8) << int1 - << setw(8) << sym2 + << setw(8) << int1 + << setw(8) << sym2 << setw(8) << "-"; break; - case jfalse: + case jfalse: o << setw(8) << "jfalse " - << setw(8) << int1 - << setw(8) << sym2 + << setw(8) << int1 + << setw(8) << sym2 << setw(8) << "-"; break; - case jump: + case jump: o << setw(8) << "jump " - << setw(8) << int1 - << setw(8) << "-" + << setw(8) << int1 + << setw(8) << "-" << setw(8) << "-"; break; - case clabel: + case clabel: o << setw(8) << "clabel " - << setw(8) << int1 - << setw(8) << "-" + << setw(8) << int1 + << setw(8) << "-" << setw(8) << "-"; break; - case istore: + case istore: o << setw(8) << "istore " - << setw(8) << sym1 - << setw(8) << "-" + << setw(8) << sym1 + << setw(8) << "-" << setw(8) << sym3; break; - case iload: + case iload: o << setw(8) << "iload " - << setw(8) << sym1 - << setw(8) << "-" + << setw(8) << sym1 + << setw(8) << "-" << setw(8) << sym3; break; - case rstore: + case rstore: o << setw(8) << "rstore " - << setw(8) << sym1 - << setw(8) << "-" + << setw(8) << sym1 + << setw(8) << "-" << setw(8) << sym3; break; - case rload: + case rload: o << setw(8) << "rload " - << setw(8) << sym1 - << setw(8) << "-" + << setw(8) << sym1 + << setw(8) << "-" << setw(8) << sym3; break; - case creturn: + case creturn: o << setw(8) << "creturn " - << setw(8) << "-" - << setw(8) << "-" + << setw(8) << "-" + << setw(8) << "-" << setw(8) << sym3; break; - case param: + case param: o << setw(8) << "param " - << setw(8) << sym1 - << setw(8) << "-" + << setw(8) << sym1 + << setw(8) << "-" << setw(8) << "-"; break; - case call: + case call: o << setw(8) << "call " - << setw(8) << sym1 - << setw(8) << "-" + << setw(8) << sym1 + << setw(8) << "-" << setw(8) << sym3; break; - case iassign: + case iassign: o << setw(8) << "iassign " - << setw(8) << sym1 - << setw(8) << "-" + << setw(8) << sym1 + << setw(8) << "-" << setw(8) << sym3; break; - case rassign: + case rassign: o << setw(8) << "rassign " - << setw(8) << sym1 - << setw(8) << "-" + << setw(8) << sym1 + << setw(8) << "-" << setw(8) << sym3; break; - case aassign: + case aassign: o << setw(8) << "aassign " - << setw(8) << sym1 - << setw(8) << int1 + << setw(8) << sym1 + << setw(8) << int1 << setw(8) << sym3; break; - case hcf: + case hcf: o << setw(8) << "hcf " - << setw(8) << "-" - << setw(8) << "-" + << setw(8) << "-" + << setw(8) << "-" << setw(8) << "-"; break; - case nop: + case nop: o << setw(8) << "nop " - << setw(8) << "-" - << setw(8) << "-" + << setw(8) << "-" + << setw(8) << "-" << setw(8) << "-"; break; default: @@ -976,8 +960,8 @@ void QuadsList::print_c(ostream& o) while (elem) { // o << elem->data << '\n'; - elem->data->print_c(o); - o << "\n"; + elem->data->print_c(o); + o << "\n"; elem = elem->next; } @@ -987,7 +971,7 @@ void QuadsList::print_c(ostream& o) void Quad::print_c(ostream& o) { o << " "; - static ::string ss = "("; + static ::string ss = (char*) "("; static bool firstParam = true; switch(opcode) { @@ -1000,195 +984,195 @@ void Quad::print_c(ostream& o) case rconst: o << setw(8) <<"real" << setw(8) << sym3 - << setw(8) << "=" + << setw(8) << "=" << setw(8) << real1; break; case iaddr: - o << setw(8) << "integer" - << setw(8) << sym3 - << setw(8) << "=" + o << setw(8) << "integer" + << setw(8) << sym3 + << setw(8) << "=" << setw(8) << "(integer)" << sym1; break; case itor: o << setw(8) << "real" - << setw(8) << sym3 - << setw(8) <<"=" + << setw(8) << sym3 + << setw(8) <<"=" << setw(8) << "(real)"<< sym1; break; case rtrunc: o << setw(8) << "integer" - << setw(8) << sym3 + << setw(8) << sym3 << setw(8) <<"=" << setw(8) << "(integer)" <<sym3; break; case iadd: o << setw(8) << "integer" - << setw(8) << sym3 - << setw(8) << " = " + << setw(8) << sym3 + << setw(8) << " = " << setw(8) << sym1 - << setw(8) << " + " + << setw(8) << " + " << setw(8) << sym2; break; case isub: o << setw(8) << "integer" - << setw(8) << sym3 - << setw(8) << " = " + << setw(8) << sym3 + << setw(8) << " = " << setw(8) << sym1 - << setw(8) << " - " + << setw(8) << " - " << setw(8) << sym2; break; case imul: o << setw(8) << "integer" << setw(8) << sym3 - << setw(8) << " = " + << setw(8) << " = " << setw(8) << sym1 - << setw(8) << " * " + << setw(8) << " * " << setw(8) << sym2; break; case idiv: o << setw(8) << "real" - << setw(8) << sym3 - << setw(8) << "=" + << setw(8) << sym3 + << setw(8) << "=" << setw(8) << sym1 - << setw(8) << "/" + << setw(8) << "/" << setw(8) << sym2; break; case ipow: o << setw(8) << "real" - << setw(8) << sym3 - << setw(8) << "= pow(" + << setw(8) << sym3 + << setw(8) << "= pow(" << setw(8) << sym1 - << setw(8) << "," + << setw(8) << "," << setw(8) << sym2 << ")"; break; case radd: o << setw(8) << "real" - << setw(8) << sym3 + << setw(8) << sym3 << setw(8) << "=" << setw(8) << sym1 - << setw(8) << "+" + << setw(8) << "+" << setw(8) << sym2; break; case rsub: o << setw(8) << "real" - << setw(8) << sym3 + << setw(8) << sym3 << setw(8) << "=" << setw(8) << sym1 - << setw(8) << "-" + << setw(8) << "-" << setw(8) << sym2; break; case rmul: o << setw(8) << "real" - << setw(8) << sym3 + << setw(8) << sym3 << setw(8) << "=" << setw(8) << sym1 - << setw(8) << "*" + << setw(8) << "*" << setw(8) << sym2; break; case rdiv: o << setw(8) << "real" - << setw(8) << sym3 + << setw(8) << sym3 << setw(8) << "=" << setw(8) << sym1 - << setw(8) << "/" + << setw(8) << "/" << setw(8) << sym2; break; case rpow: o << setw(8) << "real " - << setw(8) << sym3 - << setw(8) << "= pow(" + << setw(8) << sym3 + << setw(8) << "= pow(" << setw(8) << sym1 - << setw(8) << "," + << setw(8) << "," << setw(8) << sym2 << ")"; break; case igt: o << setw(8) << "conditional" - << setw(8) << sym3 + << setw(8) << sym3 << setw(8) << "=" << setw(8) << sym1 - << setw(8) << ">" + << setw(8) << ">" << setw(8) << sym2; break; case ilt: o << setw(8) << "conditional" - << setw(8) << sym3 + << setw(8) << sym3 << setw(8) << "=" << setw(8) << sym1 - << setw(8) << "<" + << setw(8) << "<" << setw(8) << sym2; break; case ieq: o << setw(8) << "conditional" - << setw(8) << sym3 - << setw(8) << "=" - << setw(8) << sym1 - << setw(8) << "==" - << setw(8) << sym2; + << setw(8) << sym3 + << setw(8) << "=" + << setw(8) << sym1 + << setw(8) << "==" + << setw(8) << sym2; break; case rgt: o << setw(8) << "conditional" - << setw(8) << sym3 + << setw(8) << sym3 << setw(8) << "=" << setw(8) << sym1 - << setw(8) << ">" + << setw(8) << ">" << setw(8) << sym2; break; case rlt: o << setw(8) << "conditional" - << setw(8) << sym3 + << setw(8) << sym3 << setw(8) << "=" << setw(8) << sym1 - << setw(8) << "<" + << setw(8) << "<" << setw(8) << sym2; break; case req: o << setw(8) << "conditional" - << setw(8) << sym3 + << setw(8) << sym3 << setw(8) << "=" << setw(8) << sym1 - << setw(8) << "==" + << setw(8) << "==" << setw(8) << sym2; break; case iand: o << setw(8) << "conditional" - << setw(8) << sym3 + << setw(8) << sym3 << setw(8) << "=" << setw(8) << sym1 - << setw(8) << "&&" + << setw(8) << "&&" << setw(8) << sym2; - break; + break; case ior: o << setw(8) << "conditional" - << setw(8) << sym3 + << setw(8) << sym3 << setw(8) << "=" << setw(8) << sym1 - << setw(8) << "||" + << setw(8) << "||" << setw(8) << sym2; break; case inot: o << setw(8) << "conditional" << setw(8) << sym3 << setw(8) << "=" - << setw(8) << "!" + << setw(8) << "!" << setw(8) << sym3; break; case jtrue: o << setw(8) << "if(" - << setw(8) << sym2 - << setw(8) << ")" - << setw(8) - << setw(8) << "goto clabel" << int1; + << setw(8) << sym2 + << setw(8) << ")" + << setw(8) + << setw(8) << "goto clabel" << int1; break; case jfalse: o << setw(8) << "if(!" - << setw(8) << sym2 << setw(8) << ")" - << setw(8) - << setw(8) << "goto clabel" << int1; + << setw(8) << sym2 << setw(8) << ")" + << setw(8) + << setw(8) << "goto clabel" << int1; break; case jump: o << setw(8) << "goto " << setw(8) << "clabel" - << int1 + << int1 << setw(8) << "/*jmp*/"; break; case clabel: @@ -1198,26 +1182,26 @@ void Quad::print_c(ostream& o) break; case istore: o << setw(8) << "" - << setw(8) << "*(integer*)" << sym3 + << setw(8) << "*(integer*)" << sym3 << setw(8) << "=" << setw(8) << sym1; break; break; case iload: - o << setw(8) << "integer" + o << setw(8) << "integer" << setw(8) << sym3 << setw(8) << "= /*iload*/" << setw(8) << "*(integer*)" << sym1; break; case rstore: o << setw(8) << "" - << setw(8) << "*(real*)" << sym3 + << setw(8) << "*(real*)" << sym3 << setw(8) << "=" << setw(8) << sym1; break; case rload: o - << setw(8) << "real" + << setw(8) << "real" << setw(8) << sym3 << setw(8) << "= /*rload*/" << setw(8) << "*(real*)" << sym1; @@ -1226,25 +1210,25 @@ void Quad::print_c(ostream& o) o << setw(8) << "return " << setw(8) << sym3 << setw(8) - << setw(8) << "/*Return statement*/"; + << setw(8) << "/*Return statement*/"; break; case param: { if (firstParam) { - ss = ss + sym1->id; - firstParam = false; + ss = ss + sym1->id; + firstParam = false; } else { - ss = ss + "," + sym1->id; + ss = ss + "," + sym1->id; } } break; case call: { o << setw(8) << "integer " << sym3 //Let it be ints for now.. - << setw(8) << "=" + << setw(8) << "=" << setw(8) << sym1 - << setw(8) << ss - << setw(8) << ")"; - ss = "("; //Reset callstack - firstParam = true; + << setw(8) << ss + << setw(8) << ")"; + ss = "("; //Reset callstack + firstParam = true; } break; case iassign: @@ -1260,11 +1244,11 @@ void Quad::print_c(ostream& o) case aassign: { ::string itVar = sym1->id + "_" + ::string(int1); o << setw(8) << "for(int " << itVar << " = 0 ;" - << setw(8) << itVar << "<" << int1 << ";" - << setw(8) << itVar << "++;)" //Increment & close for loop. - /*Assign the array*/ - << setw(8) << sym3 << "[" << itVar << "]" << "=" - << setw(8) << sym1 << "[" << itVar << "];"; + << setw(8) << itVar << "<" << int1 << ";" + << setw(8) << itVar << "++;)" //Increment & close for loop. + /*Assign the array*/ + << setw(8) << sym3 << "[" << itVar << "]" << "=" + << setw(8) << sym1 << "[" << itVar << "];"; } break; case hcf: @@ -1272,7 +1256,7 @@ void Quad::print_c(ostream& o) break; case nop: o << setw(8) << ";/*No operation*/" - << setw(8) << ""; + << setw(8) << ""; break; default: o << "unknown (" << opcode << ")"; diff --git a/lab3-4/main.cc b/lab3-4/main.cc index 651111cefd5cd06aee23e259598525764c8e88bd..d859fb226b860319103664fbdf2f32240ba16882 100644 --- a/lab3-4/main.cc +++ b/lab3-4/main.cc @@ -6,14 +6,12 @@ #include "symtab.hh" #include <unistd.h> -using namespace std; - extern int yyparse(void); extern int yydebug; extern int errorCount; extern int warningCount; -static char *optionString = "dhc"; +static const char *OPTION_STRING = "dhc"; void Usage(char *program) { @@ -33,10 +31,12 @@ int main(int argc, char **argv) { int option; extern FILE *yyin; - - // - // Set up the symbol table - // + + /* + Set up the symbol table. + Adds builtin functions used by the language. + Builtin functions include routines to print reals integers etc. + */ currentFunction = new FunctionInformation("main"); kIntegerType = new TypeInformation("integer", sizeof(long)); @@ -55,7 +55,7 @@ int main(int argc, char **argv) kIReadFunction->SetReturnType(kIntegerType); kFReadFunction->SetReturnType(kRealType); kIReadFunction->SetReturnType(kIntegerType); - + currentFunction->AddSymbol(kIntegerType); currentFunction->AddSymbol(kRealType); currentFunction->AddSymbol(kIPrintFunction); @@ -70,7 +70,7 @@ int main(int argc, char **argv) opterr = 0; optopt = '?'; - while ((option = getopt(argc, argv, optionString)) != EOF) + while ((option = getopt(argc, argv, OPTION_STRING)) != EOF) { switch (option) { @@ -82,13 +82,13 @@ int main(int argc, char **argv) break; case '?': Usage(argv[0]); - break; - case 'c': - std::cout << "/*Using standard-library*/\n"; - std::cout << "#include \"stl.h\"\n"; - SymbolInformation::outputFormat = SymbolInformation::kCFormat; - currentFunction->outputFormat = SymbolInformation::kCFormat; - break; + break; + case 'c': + std::cout << "/*Using standard-library*/\n"; + std::cout << "#include \"stl.h\"\n"; + SymbolInformation::outputFormat = SymbolInformation::kCFormat; + currentFunction->outputFormat = SymbolInformation::kCFormat; + break; } } @@ -102,7 +102,7 @@ int main(int argc, char **argv) } optind += 1; } - + if (optind < argc) Usage(argv[0]); @@ -113,4 +113,3 @@ int main(int argc, char **argv) int retcode = yyparse(); return retcode; } - diff --git a/lab3-4/parser.y b/lab3-4/parser.y index 054d45b20185835ec1a7abe30ead170194ad768c..b65b7b28541b04972985e3270b3d8a314ddd9e83 100644 --- a/lab3-4/parser.y +++ b/lab3-4/parser.y @@ -7,10 +7,10 @@ extern char *yytext; extern int yylineno, errorCount, warningCount; -extern FunctionInformation *currentFunction; +extern FunctionInformation *currentFunction; extern int yylex(void); -extern void yyerror(char *); +extern void yyerror(const char *); extern char CheckCompatibleTypes(Expression **, Expression **); extern char CheckAssignmentTypes(LeftValue **, Expression **); extern char CheckFunctionParameters(FunctionInformation *, @@ -45,12 +45,12 @@ extern ostream& warning(void); FunctionCall *call; LeftValue *lvalue; ElseIfList *elseIfList; - + VariableInformation *variable; TypeInformation *type; FunctionInformation *function; - ::string *id; + ::string *id; int integer; double real; void *null; @@ -81,7 +81,7 @@ extern ostream& warning(void); */ %token FUNCTION ID DECLARE ARRAY INTEGER OF REAL XBEGIN XEND IF THEN -%token ELSE WHILE DO ASSIGN RETURN GE LE EQ NE ARRAY TRUE FALSE PROGRAM +%token ELSE WHILE DO ASSIGN RETURN GE LE EQ NE TRUE FALSE PROGRAM %token ELSEIF @@ -184,10 +184,10 @@ functions : functions function */ function : - { - cerr << "Function here" << endl; - } - ; + { + cerr << "Function here" << endl; + } + ; /* --- End your code --- */ @@ -249,7 +249,7 @@ type : id else { typeInfo = info->SymbolAsType(); - + if (typeInfo == NULL) { error() << *($1) << " is not a type" << "\n" <<flush; @@ -299,7 +299,7 @@ statements : statements statement if ($2 == NULL) $$ = NULL; else - $$ = new StatementList($1, $2); + $$ = new StatementList($1, $2); } | /* Empty */ { @@ -403,7 +403,7 @@ returnstmt : RETURN expression error() << " attempt to return " << ShortSymbols << expr->valueType << '\n'; error() << " in function declared to return " - << ShortSymbols + << ShortSymbols << currentFunction->GetReturnType() << LongSymbols << '\n'; $$ = NULL; @@ -454,13 +454,13 @@ variable : id << *($1) << "\n" << flush; - + $$ = NULL; } else { varInfo = info->SymbolAsVariable(); - + if (varInfo == NULL) { error() @@ -545,7 +545,7 @@ call : funcname '(' expressions ')' id : ID { - $$ = new ::string(yytext); + $$ = new ::string(yytext); } ; @@ -576,13 +576,13 @@ real : REAL */ expression : - { - cerr << "Expression here" << endl; - } - ; + { + cerr << "Expression here" << endl; + } + ; /* --- End your code --- */ - + expressions : expressionz { @@ -620,10 +620,10 @@ expressionz : expressionz ',' expression */ condition : - { - cerr << "Condition here" << endl; - } - ; + { + cerr << "Condition here" << endl; + } + ; /* --- End your code --- */ @@ -632,7 +632,7 @@ condition : int errorCount = 0; int warningCount = 0; - + /* --- Your code here --- * @@ -642,14 +642,14 @@ int warningCount = 0; /* It is reasonable to believe that you will need a function * that checks that two expressions are of compatible types, * and if possible makes a type conversion. - * For your convenience a skeleton for such a function is + * For your convenience a skeleton for such a function is * provided below. It will be very similar to CheckAssignmentTypes. */ /* * CheckCompatibleTypes checks that the expressions indirectly pointed * to by left and right are compatible. If type conversion is - * necessary, the pointers left and right point to will be modified to + * necessary, the pointers left and right point to will be modified to * point to the node representing type conversion. That's why you have * to pass a pointer to pointer to Expression in these arguments. */ @@ -702,7 +702,7 @@ char CheckAssignmentTypes(LeftValue **left, Expression **right) /* * CheckFunctionParameters is used to check parameters passed to a - * function. func is the function we're passing parameters to, formals + * function. func is the function we're passing parameters to, formals * is a pointer to the last formal parameter we're checking against * and params is a pointer to the ExpressionList we're checking. If * type conversion is necessary, the Expressions pointed to by the @@ -769,7 +769,7 @@ char CheckFunctionParameters(FunctionInformation *func, << params->expression->valueType << '\n' << LongSymbols << flush; - return 0; + return 0; } } } @@ -800,7 +800,7 @@ char CheckReturnType(Expression **expr, TypeInformation *info) } -void yyerror(char *message) +void yyerror(const char *message) { error() << message << '\n' << flush; } diff --git a/lab3-4/string.cc b/lab3-4/string.cc index de2ddce039156017c6d5a7ac9baf17c33fe56272..46b485cf6bd8463a3092cabfeab2bab2821d2b7b 100644 --- a/lab3-4/string.cc +++ b/lab3-4/string.cc @@ -73,6 +73,16 @@ string::string(char *s) chunk_size = 10; } +string::string(const char *s) +{ + text = strdup(s); + if (text == NULL) + abort(); + size = strlen(s) + 1; + position = strlen(s); + chunk_size = 10; +} + string::string(char c, int sz) { text = (char *)malloc(sz); diff --git a/lab3-4/string.hh b/lab3-4/string.hh index b7fa56ff4d7ff66cce0fd04c5c82c609bc9d583e..f9aadea3af299b5aea918d3cb7d3b5080170fb4d 100644 --- a/lab3-4/string.hh +++ b/lab3-4/string.hh @@ -20,7 +20,7 @@ using std::ostream; // really necessary. If strings were considered read only (no // destructive update), then it would be possible to keep a pool of // strings with reference counts and just pass along references to -// that pool. +// that pool. // class string @@ -34,10 +34,14 @@ private: void ensure_size(int); public: + //To kill warnings and make this custom string play nice... + + class error {}; // Exception thrown when out of memory string(); // Default constructor creates empty string string(char *); // Create string from character pointer + string(const char *); // Create string from a constant character pointer string(char, int); // Create string filles with characters string(const string &); // Copy constructor string(int); // Convert an integer @@ -50,7 +54,7 @@ public: string& operator=(const string&); // Assignment operator string& operator=(const char *); // Assignment operator string& operator=(const char); // Assignment operator - + string& operator+=(const string&); // Append operator string& operator+=(const char); // Append operator string& operator+=(const char *); // Append operator diff --git a/lab3-4/symtab.cc b/lab3-4/symtab.cc index 337f5fc4124e3b7024351c20c0951b11c843dd1c..0014b6088462488b01d741ddd48c643ee9a53b68 100644 --- a/lab3-4/symtab.cc +++ b/lab3-4/symtab.cc @@ -44,7 +44,7 @@ ostream& SymbolInformation::print(ostream& o) break; case kCFormat: o << id; - break; + break; default: o << "Bad output format\n"; abort(); @@ -80,10 +80,10 @@ ostream& TypeInformation::print(ostream& o) { o << id; } - + o << " [" << size << "]"; break; - + case kShortFormat: if (elementType != NULL) { @@ -103,7 +103,7 @@ ostream& TypeInformation::print(ostream& o) } else { - o << id; + o << id; } break; @@ -200,21 +200,21 @@ ostream& FunctionInformation::print(ostream& o) tmp = tmp->prev; } o << LongSymbols; - o << '\n'; + o << '\n'; } else { o << " Locals: none\n"; } - + o << " Body: " << (void*)body << '\n'; if (body) o << body; - o << '\n'; - + o << '\n'; + o << " Quads: " << (void*)quads << '\n'; if (quads) o << quads; o << '\n'; - + o << symbolTable; break; @@ -240,59 +240,59 @@ ostream& FunctionInformation::print(ostream& o) break; case kCFormat: - /*C-Code preamble*/ - if (returnType == NULL) { - o << "void\n"; - } else { - o << returnType << "\n"; - } - - o << "" << id << "("; - //Parameters - if (lastParam != NULL) + /*C-Code preamble*/ + if (returnType == NULL) { + o << "void\n"; + } else { + o << returnType << "\n"; + } + + o << "" << id << "("; + //Parameters + if (lastParam != NULL) { tmp = lastParam; while (tmp != NULL) { - if (tmp->type->elementType != NULL){ //Array... - o << tmp->type->elementType << "*" << "\t"; - } else { - // o << tmp->type->elementType; - o << tmp->type << "\t"; - } - if (tmp->prev == NULL) { - o << tmp->id; - } else { - o << tmp->id << ","; - } - tmp = tmp->prev; + if (tmp->type->elementType != NULL){ //Array... + o << tmp->type->elementType << "*" << "\t"; + } else { + // o << tmp->type->elementType; + o << tmp->type << "\t"; + } + if (tmp->prev == NULL) { + o << tmp->id; + } else { + o << tmp->id << ","; + } + tmp = tmp->prev; } } - o << ")\n"; - /* Generate C-Code for the body! */ - o << "{\n"; - if (lastLocal) + o << ")\n"; + /* Generate C-Code for the body! */ + o << "{\n"; + if (lastLocal) { - o << "//Locals:\n"; + o << "//Locals:\n"; tmp = lastLocal; while (tmp != NULL) { - if (tmp->type->elementType != NULL){ //Array... - o << tmp->type->elementType; - o << "\t"; - o << tmp; - o << tmp->type << ";\n"; - } - else { - o << tmp->type << "\t" << tmp << ";\n"; - } - tmp = tmp->prev; + if (tmp->type->elementType != NULL){ //Array... + o << tmp->type->elementType; + o << "\t"; + o << tmp; + o << tmp->type << ";\n"; + } + else { + o << tmp->type << "\t" << tmp << ";\n"; + } + tmp = tmp->prev; } } - quads->print_c(o); - o << "}\n"; - break; - + quads->print_c(o); + o << "}\n"; + break; + default: o << "Bad output format.\n"; abort(); @@ -397,7 +397,7 @@ TypeInformation *FunctionInformation::AddArrayType(TypeInformation *elemType, else { - name = elemType->id + "<" + dimensions + ">."; + name = elemType->id + (char*)"<" + dimensions + (char*)">."; xinfo = symbolTable.LookupSymbol(name); if (xinfo == NULL) { @@ -430,14 +430,14 @@ FunctionInformation *FunctionInformation::AddFunction(const ::string& name, if (xinfo != NULL && xinfo->tag == kTypeInformation) { cerr << "Bug: you tried to create a function that's also a type\n"; - abort(); + abort(); } xinfo = symbolTable.LookupSymbol(name); if (xinfo != NULL) { cerr << "Bug: you tried to create a function with a name " - << "that's already in use\n"; + << "that's already in use\n"; } fn->id = name; @@ -458,7 +458,7 @@ VariableInformation *FunctionInformation::TemporaryVariable(TypeInformation *typ return info; } - + char FunctionInformation::OkToAddSymbol(const ::string& name) { diff --git a/lab3-4/symtab.hh b/lab3-4/symtab.hh index 7e06b3ede4fae221a4478d5d26018a81d8106a87..8c9ad58e1077a7846605cf983e508d8e6fa5b580 100644 --- a/lab3-4/symtab.hh +++ b/lab3-4/symtab.hh @@ -91,7 +91,7 @@ protected: friend class SymbolTable; friend ostream& LongSymbols(ostream&); friend ostream& SummarySymbols(ostream&); - friend ostream& ShortSymbols(ostream&); + friend ostream& ShortSymbols(ostream&); public: typedef enum { kFullFormat, kSummaryFormat, kShortFormat, kCFormat } tFormatType; static tFormatType outputFormat; @@ -100,8 +100,8 @@ public: SymbolTable *table; SymbolInformation(SymbolInformationType t, const ::string &i) : - tag(t), - id(i) {}; + tag(t), + id(i) {}; virtual ~SymbolInformation() {} virtual FunctionInformation *SymbolAsFunction(void) { return NULL; }; @@ -141,13 +141,13 @@ private: public: FunctionInformation(const ::string& i) : - SymbolInformation(kFunctionInformation, i), - parent(NULL), - returnType(NULL), - lastParam(NULL), - lastLocal(NULL), - body(NULL), - quads(NULL) {}; + SymbolInformation(kFunctionInformation, i), + parent(NULL), + returnType(NULL), + lastParam(NULL), + lastLocal(NULL), + body(NULL), + quads(NULL) {}; virtual FunctionInformation *SymbolAsFunction(void) { return this; }; @@ -164,7 +164,7 @@ public: FunctionInformation *AddFunction(const ::string&, FunctionInformation *); VariableInformation *AddParameter(const ::string&, TypeInformation *); - VariableInformation *AddVariable(const ::string&, TypeInformation *); + VariableInformation *AddVariable(const ::string&, TypeInformation *); SymbolInformation *AddSymbol(SymbolInformation *); TypeInformation *AddArrayType(TypeInformation *, int); @@ -197,10 +197,10 @@ public: virtual VariableInformation *SymbolAsVariable(void) { return this; }; VariableInformation(const ::string& i) : - SymbolInformation(kVariableInformation, i) {}; + SymbolInformation(kVariableInformation, i) {}; VariableInformation(const ::string& i, TypeInformation *t) : - SymbolInformation(kVariableInformation, i), - type(t) {}; + SymbolInformation(kVariableInformation, i), + type(t) {}; }; @@ -220,8 +220,8 @@ public: virtual TypeInformation *SymbolAsType(void) { return this; }; TypeInformation(const ::string& i, unsigned long s) : - SymbolInformation(kTypeInformation, i), - size(s) {}; + SymbolInformation(kTypeInformation, i), + size(s) {}; };