我试图编译G ++代码,我得到以下错误:
在文件从scanner.hpp包括:8,
从scanner.cpp:5:
parser.hpp:14:错误:“扫描仪”没有指定类型
parser.hpp:15:错误:“令牌”没有指定类型
这里是我的G ++命令:
克++ parser.cpp scanner.cpp -Wall
这里的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
和这里的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
任何人看到这个问题? 我觉得我失去了一些东西难以置信明显。