Incomplete type of struct forward declaration

I’m working on a compiler project requiring two Lexer and Parser structs respectively. My Parser is supposed to be able to control our Lexer struct and call its member functions when needed for things like retrieving tokens to parse statements correctly.

I’ve written two separate .h files to contain forward declarations to all of the structs, however I’m seeing a bunch of incomplete type "(insert struct name) is not allowed" errors. I believe there’s something wrong with my forward declaration’s that I don’t understand.

Furthermore, there are some errors regarding static local variables in my Parser struct in parser.cpp . I’ve put comments where the errors occur!

For added context, I’m following a tutorial for this project, which you can find here.

Here is the following logic I’m using, alongside some comments for extra details:

// lexer.h

#ifndef LEXER
#define LEXER

struct Lexer;
struct TokenType;
struct Token;

#endif
// parser.h
#ifndef PARSER
#define PARSER

struct Parser;

#endif
// test.cpp, file where we call the Lexer + Parser

Lexer lex { source }; // incomplete type "Lexer" is not allowedC/C++(70)
lex.init_source(); // incomplete type "Lexer" is not allowedC/C++(70)

Parser parse { std::move(lex) }; // incomplete type "Parser" is not allowedC/C++(70)
parse.init(); // incomplete type "Parser" is not allowedC/C++(70)
parse.program(); // incomplete type "Parser" is not allowedC/C++(70)
// lexer.cpp, lexer component of compiler

struct TokenType // need to access this in parser.cpp since we use the enum values there
{
    enum Token
    {
        ENDOFFILE = -1,
        NEWLINE = 0,
        NUMBER = 1,
        ... // bunch of other tokens
};

struct Token
{
    std::string tokenText {}; // raw text of token
    int tokenKind; // enum value of token from TokenType::Token
};

struct Lexer
{
    std::string source {}; // source string
    size_t curPos = 0; // current index in string array/source, size_t used to ensure no conversions later
    char curChar = ' '; // current character in string

    ... // bunch of other member functions
};
// parser.cpp, parser component of compiler

struct Parser
{
    Lexer lex; // attempt to pass Lexer object to Parser, as seen in test.cpp

    // the variable declarations here are bugging out and are marked as undefined everywhere where they're used, even though they should have static duration and thus act somewhat like global variables? 
    void nextToken()
    {
        static auto peekToken = lex.getToken(); // accessing Lexer struct member functions here, would be able to work if we could actually send the Lexer's components through the member variable above
        static auto curToken = peekToken;
    }

    bool checkToken(auto tokenKind) // enum value of token(s) in TokenType::Token in lexer.cpp
    {
        return tokenKind == curToken.tokenKind; // error here cuz curToken is undefined
    }

    bool checkPeek(auto tokenKind)
    {
        return tokenKind == peekToken.tokenKind; // same error here with peekToken
    }

    void match(auto tokenKind)
    {
        if (!(checkToken(tokenKind)))
        { 
            abort("Expected token enum ", tokenKind, ", got ", curToken.tokenKind); // another error here with curToken
        }
        nextToken();
    }

    void nl()
    {
        std::cout << "NEWLINEn";

        match(TokenType::Token::NEWLINE); // incomplete type "TokenType" is not allowedC/C++(70), also: 'TokenType::Token' has not been declared
        while (checkToken(TokenType::Token::NEWLINE)) // same errors here as above
        {
            nextToken();
        }
    }

    void expression()
    {
        ;
    }

    void statement()
    {
        if (checkToken(TokenType::Token::PRINT)) // same errors here as above
        {
            std::cout << "STATEMENT-PRINTn";
            nextToken();

            if (checkToken(TokenType::Token::STRING)) // same errors here as above
            {
                nextToken();
            }
            else // expression given otherwise
            {
                expression();
            }
        }

        nl(); // output newline
    }

    void program()
    {
        std::cout << "[TRACE] PROGRAMn";

        // parse all statements in program until EOF is reached in source file
        while (!(checkToken(TokenType::Token::ENDOFFILE))) // same errors here as above
        {
            statement();
        }
    }

    void init() // init initializes peekToken and curToken on Parser object initialization
    {
        nextToken();
        nextToken();
    }    
};

Lemme know if you guys need additional information or explanation 🙂

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật