add cmake build process + switch to bison

pull/1/head
cosmonaut 2021-04-18 14:10:15 -07:00
parent 5861d07b07
commit a849fa73c4
4 changed files with 32 additions and 5 deletions

2
.gitignore vendored
View File

@ -0,0 +1,2 @@
build/
CMakeCache.txt

21
CMakeLists.txt Normal file
View File

@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 2.8.12)
project(WRAITH_LANG C)
set(CMAKE_C_STANDARD 99)
find_package(BISON)
find_package(FLEX)
include_directories(${CMAKE_SOURCE_DIR})
BISON_TARGET(Parser wraith.y ${CMAKE_CURRENT_BINARY_DIR}/y.tab.c COMPILE_FLAGS -d)
FLEX_TARGET(Scanner wraith.lex ${CMAKE_CURRENT_BINARY_DIR}/lex.yy.c)
ADD_FLEX_BISON_DEPENDENCY(Scanner Parser)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(
wraith_compile
${BISON_Parser_OUTPUTS}
${FLEX_Scanner_OUTPUTS}
)

View File

@ -1,3 +1,7 @@
%{
#include "y.tab.h"
%}
%option noyywrap
%%

View File

@ -2,7 +2,6 @@
#include <stdio.h>
#include "ast.h"
#include "stack.h"
#define YYSTYPE struct Node*
void yyerror(FILE *fp, char *s)
{
fprintf (stderr, "%s\n", s);
@ -10,10 +9,13 @@ void yyerror(FILE *fp, char *s)
Stack *stack;
#define YYDEBUG 1
int yydebug=1;
extern char *yytext;
extern int yylex (void);
extern FILE *yyin;
%}
%define api.value.type {struct Node*}
%token NUMBER
%token INT
%token UINT
@ -234,8 +236,6 @@ Declarations : Declaration Declarations
}
%%
#include "lex.yy.c"
int main(int argc, char *argv[])
{
if (argc < 2)