- I have 2 classes together with their header files called lexer.cpp and lexer.h , token.cpp and token.h
- These are needed to create a compiler. At the moment I'm still doing the lexemes, dividing and reading the Tokens.
- Now I have a method which will read every character I load from the file, and when for example it identifies that it is an integer, it will return a Token (which are the Tokens in token.cpp)
The Problem:
In token.cpp I have an enum class Token which has all the tokens that can be read by my compiler (coding will be provided below)
Now in
- Lexer.cpp I have to call this class (enum class Token in Token.cpp). In token.h I just declared the class name
- Lexer.h I wrote the name of the method that is to be used in Lexer.cpp
But they are generating some errors.
Error:
Code:
Lexer.cpp
Token Lexer::getNextToken(char ch)
{
return Token::tkDigit;
}
lexer.h
#ifndef lexer
#define lexer
#include "token.h"
class Lexer
{
public:
char ReadChar();
bool IsDigit (char ch);
bool IsAlpha (char ch);
bool IsIdentation (char ch);
Token getNextToken (char ch);
};
#endif // lexer.h
Token.h
#ifndef token
#define token
enum class Token
{
tkLetter,
tkDigit,
tkPrintable,
tkType,
//Literals
tkBooleanLiteral,
tkIntegerLiteral,
tkRealLiteral,
tkCharLiteral,
tkStringLiteral,
tkUnitLiteral,
tkLiteral,
tkIndentifier,
//Operations
tkMultpicativeOp,
tkAdditiveOp,
tkRelationalOp,
//Params and Calls
tkActualParams,
tkFunctionCall,
//cast and factors
tkTypeCast,
tkSubExpression,
tkUnary,
tkFactor,
//Terms and Declarations
tkTerm,
tkSimpleExpression,
tkExpression,
tkAssignment,
tkVariableDecl,
tkFormalParam,
tkFunctionDecl,
//Statements
tkReadStatement,
tkWriteStatement,
tkIfStatement,
tkWhileStatement,
tkHaltStatement,
tkStatement,
tkBlock,
tkSxl,
};
#endif // token