diff --git a/.gitignore b/.gitignore index d163863..04f33fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -build/ \ No newline at end of file +build/* +.cache \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 749c558..debb9de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,10 @@ +cmake_minimum_required(VERSION 3.16) project(lispy_stuff) -add_executable(main src/main.cpp) \ No newline at end of file +set(HEADER_FILES src/include/lex.hpp) +set(SOURCE_FILES src/main.cpp) + + +add_executable(main ${SOURCE_FILES} ${HEADER_FILES}) + +target_include_directories(main PRIVATE src/include/) \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0ee82bd --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# Lispy stuff + +Simple lisp-ish language compiler written in C++. + +Right now it doesn't compile much - it's just a parser. +The goal is to emit bytecode. The bytecode format is not decided yet. + +## Build + +I use cmake for the build system. I prefer to build out-of-tree, +here's how to build if you've never used cmake: + +```bash +cd build +cmake .. +make +``` + +## Development + +I use clangd as the language server. Appropriate `compile_commands.json` +(required for clangd, otherwise it can not find include files) is provided. +If you'd like to generate them yourself, just use cmake: + +```bash +cd build +cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 .. +cp compile_commands.json ../ +``` + + diff --git a/compile_commands.json b/compile_commands.json new file mode 100644 index 0000000..7be5003 --- /dev/null +++ b/compile_commands.json @@ -0,0 +1,8 @@ +[ +{ + "directory": "/home/haxala1r/Desktop/Programming/C++/lispy-stuff/build", + "command": "/usr/bin/c++ -I/home/haxala1r/Desktop/Programming/C++/lispy-stuff/src/include -o CMakeFiles/main.dir/src/main.cpp.o -c /home/haxala1r/Desktop/Programming/C++/lispy-stuff/src/main.cpp", + "file": "/home/haxala1r/Desktop/Programming/C++/lispy-stuff/src/main.cpp", + "output": "CMakeFiles/main.dir/src/main.cpp.o" +} +] \ No newline at end of file diff --git a/src/include/lex.hpp b/src/include/lex.hpp new file mode 100644 index 0000000..208d2eb --- /dev/null +++ b/src/include/lex.hpp @@ -0,0 +1,36 @@ +#pragma once +#include +#include +#include +#include + +enum TokenType { + OpenParen, + CloseParen, + Symbol, + String, + Int, + End +}; + +// Plain Old Data +struct Token { + enum TokenType type; + std::variant value; +}; + +class Lexer { +private: + // we use a stringstream for lexing purposes + std::stringstream ss; + +public: + Lexer(std::string); + Lexer(); + + void feed(std::string); + + Token next(); + std::vector collect(); +}; + diff --git a/src/lex.cpp b/src/lex.cpp new file mode 100644 index 0000000..fd82f23 --- /dev/null +++ b/src/lex.cpp @@ -0,0 +1,16 @@ +#include +#include + +Lexer::Lexer(std::string s) : ss(s) {} +Lexer::Lexer() : ss("") {} + +void Lexer::feed(std::string s) { + ss << s; +} + +Token Lexer::next() { + return {TokenType::CloseParen}; +} + + + diff --git a/src/main.cpp b/src/main.cpp index 257ddca..ac8a0dd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,10 @@ #include +#include +#include using namespace std; int main() { - cout << "hi" << endl; + cout << "hi " << endl; return 0; } \ No newline at end of file