DeveloperBreeze

Tutorials Programming Tutorials, Guides & Best Practices

Explore 149+ expertly crafted tutorials tutorials, components, and code examples. Stay productive and build faster with proven implementation strategies and design patterns from DeveloperBreeze.

Implementing a Domain-Specific Language (DSL) with LLVM and C++

Tutorial February 12, 2025

#ifndef DSL_PARSER_H
#define DSL_PARSER_H

#include "Lexer.h"
#include "AST.h"
#include <memory>

class Parser {
public:
    Parser(Lexer& lexer);
    std::unique_ptr<ASTNode> parseExpression();

private:
    Lexer& lexer;
    Token currentToken;

    void eat(TokenType type);
    std::unique_ptr<ASTNode> factor();
    std::unique_ptr<ASTNode> term();
};

#endif // DSL_PARSER_H

Implementation: Parser.cpp