add initial empty C, flex, and bison sources

This commit is contained in:
Josh Holtrop 2018-04-06 11:38:27 -04:00
parent 8d8c08cd85
commit 3ead22e0cf
5 changed files with 84 additions and 2 deletions

8
src/main.c Normal file
View File

@ -0,0 +1,8 @@
#include <stdio.h>
int main(int argc, char * argv[])
{
printf("coming soon...\n");
return 0;
}

4
src/parser/parser.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef PARSER_H
#define PARSER_H
#endif

15
src/parser/parser.l Normal file
View File

@ -0,0 +1,15 @@
%option nounput
%option bison-locations
%{
#include "parser.h"
#include "parser.tab.h"
%}
%x str
%%
%%

38
src/parser/parser.y Normal file
View File

@ -0,0 +1,38 @@
%{
#include <stdio.h>
#include "parser.h"
#include "parser.tab.h"
#define yyerror(msg) handle_error(msg, &yyloc)
int yylex(YYSTYPE *, YYLTYPE *);
static void handle_error(const char * str, const YYLTYPE * yylloc);
%}
%pure-parser
%locations
%error-verbose
%token PLUS;
%token MINUS;
%%
translation_unit: PLUS;
%%
static void handle_error(const char * str, const YYLTYPE * yylloc)
{
fprintf(stderr, "error: %s (line %d, column %d)\n",
str,
yylloc->first_line,
yylloc->first_column);
}
int yywrap(void)
{
return 1;
}

21
wscript
View File

@ -1,5 +1,22 @@
import sys
APP_NAME = "cxlc"
def options(opt):
opt.load("compiler_c");
def configure(conf):
pass
conf.load("compiler_c flex bison");
def build(bld):
pass
sources = bld.path.ant_glob("src/**/*.c")
lexer_source = "src/parser/parser.l"
parser_source = "src/parser/parser.y"
sources += [lexer_source, parser_source]
includes = ["src", "src/parser"]
cflags = ["-Wall", "-O2"]
bld.program(
source = sources,
cflags = cflags,
target = APP_NAME,
includes = includes)