Commit 97a60c8c authored by Chris Müller's avatar Chris Müller
Browse files

move core into cherry tools. Start implementing parsing components

parent 0e6ef735
add_subdirectory(core)
add_subdirectory(runtime)
add_subdirectory(cherry)
set(SOURCES
main.c)
set(CORE_SOURCES
array.c
red_black_tree.c
map.c
parser.c
unicode.c)
add_executable(cherry ${SOURCES})
target_link_libraries(cherry readline)
set(INTERPRETER_SOURCES
cherry.c)
add_library(cherry-core SHARED ${CORE_SOURCES})
add_executable(cherry ${INTERPRETER_SOURCES})
target_link_libraries(cherry-core gc)
target_link_libraries(cherry readline cherry-core cherry-runtime)
#include <stdio.h>
#include <stdlib.h>
#include <readline/readline.h>
int main(int argc, char** argv)
{
printf("Welcome to Cherry 0.1\n");
while(1) {
char* line = readline("> ");
if(line && *line)
add_history(line);
free(line);
}
return 0;
}
/*
* Cherry programming language
* Copyright (C) 2013 Christoph Mueller
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "parser.h"
#include "array.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
struct Mapping {
byte* string;
enum CyTOK value;
};
struct CyContext*
cy_context_new(const byte* source, const char* filename)
{
struct CyContext* context = malloc(sizeof(struct CyContext));
struct CyFile* file = malloc(sizeof(struct CyFile));
file->filename = filename;
file->begin = source;
context->src = (byte*) source;
context->buffer = cy_array_new(sizeof(byte));
return context;
}
struct CyContext*
cy_context_repl_new(const byte* source)
{
return cy_context_new(source, 0);
}
void
cy_context_free(struct CyContext* context)
{
assert(context != 0);
cy_array_free(context->buffer);
free(context->file);
free(context);
}
const byte*
cy_tok_to_string(enum CyTOK token)
{
return 0;
}
enum CyTOK
cy_lex(struct CyContext* context)
{
return TOK_EOF;
}
/*
* Cherry programming language
* Copyright (C) 2013 Christoph Mueller
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "standard.h"
#include <stdlib.h>
#include <stdint.h>
struct CyArray;
struct CyFile {
const char* filename;
const byte* begin;
};
struct CyContext {
struct CyFile* file;
byte* src;
struct CyArray* buffer;
};
struct CyContext* cy_context_new(const byte* source, const char* filename);
struct CyContext* cy_context_repl_new(const byte* source);
void cy_context_free(struct CyContext* context);
enum CyTOK {
TOK_EOF,
TOK_ROUNDLEFTBRACE,
TOK_ROUNDRIGHTBRACE,
TOK_SQUARELEFTBRACE,
TOK_SQUARERIGHTBRACE,
TOK_COMMENT,
TOK_DOT,
TOK_STRING,
TOK_CHAR,
TOK_HEX,
TOK_DEC,
TOK_OCT,
TOK_BIN,
TOK_FLOAT,
TOK_DEFINE,
TOK_IDENTIFIER
};
const byte* cy_tok_to_string(enum CyTOK token);
enum CyTOK cy_lex(struct CyContext* context);
byte* cy_token_string(struct CyContext* context);
size_t cy_token_length(struct CyContext* context);
set(SOURCES
array.c
red_black_tree.c
map.c
unicode.c)
add_library(cherry-core ${SOURCES})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment