diff --git a/lab2/lab2.hh b/lab2/lab2.hh index 892c4d0060c6de5743689ab54aa26f5b9e5fc336..ca7d04db1fc851e8f0e777eb0f9fa224a66d47e6 100644 --- a/lab2/lab2.hh +++ b/lab2/lab2.hh @@ -24,10 +24,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..57020795a4d41fe7e2b8e7191ee033fd4c43b1f6 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", @@ -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) { @@ -312,12 +312,12 @@ ostream& operator<<(ostream& s, ScannerError& e) // 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) {};