Hi. I'm trying to compile code in g++ and I get the following errors:
In file included from scanner.hpp:8,
from scanner.cpp:5:
parser.hpp:14: error: ‘Scanner’ does not name a type
parser.hpp:15: error: ‘Token’ does not name a type
Here's my g++ command:
g++ parser.cpp scanner.cpp -Wall
Here's parser.hpp:
#ifndef PARSER_HPP
#define PARSER_HPP
#include <string>
#include <map>
#include "scanner.hpp"
using std::string;
class Parser
{
// Member Variables
private:
Scanner lex; // Lexical analyzer
Token look; // tracks the current lookahead token
// Member Functions
<some function declarations>
};
#endif
and here's scanner.hpp:
#ifndef SCANNER_HPP
#define SCANNER_HPP
#include <iostream>
#include <cctype>
#include <string>
#include <map>
#include "parser.hpp"
using std::string;
using std::map;
enum
{
// reserved words
BOOL, ELSE, IF, TRUE, WHILE, DO, FALSE, INT, VOID,
// punctuation and operators
LPAREN, RPAREN, LBRACK, RBRACK, LBRACE, RBRACE, SEMI, COMMA, PLUS, MINUS, TIMES,
DIV, MOD, AND, OR, NOT, IS, ADDR, EQ, NE, LT, GT, LE, GE,
// symbolic constants
NUM, ID, ENDFILE, ERROR
};
class Token
{
public:
int tag;
int value;
string lexeme;
Token() {tag = 0;}
Token(int t) {tag = t;}
};
class Num : public Token
{
public:
Num(int v) {tag = NUM; value = v;}
};
class Word : public Token
{
public:
Word() {tag = 0; lexeme = "default";}
Word(int t, string l) {tag = t; lexeme = l;}
};
class Scanner
{
private:
int line; // which line the compiler is currently on
int depth; // how deep in the parse tree the compiler is
map<string,Word> words; // list of reserved words and used identifiers
// Member Functions
public:
Scanner();
Token scan();
string printTag(int);
friend class Parser;
};
#endif
anyone see the problem? I feel like I'm missing something incredibly obvious.