merge: dev update
This commit is contained in:
commit
89478b4336
14 changed files with 181 additions and 84 deletions
14
README.md
14
README.md
|
|
@ -7,12 +7,20 @@
|
||||||
TODO
|
TODO
|
||||||
|
|
||||||
### Build
|
### Build
|
||||||
|
run this command:
|
||||||
TODO
|
autoreconf --force --verbose --install
|
||||||
|
|
||||||
### Test
|
### Test
|
||||||
|
run this command:
|
||||||
|
./configure CFLAGS='-std=c99 -Werror -Wall -Wextra -Wvla'
|
||||||
|
then:
|
||||||
|
make
|
||||||
|
|
||||||
TODO
|
#### asan
|
||||||
|
run this command:
|
||||||
|
./configure CFLAGS='-std=c99 -Werror -Wall -Wextra -Wvla -g -fsanitize=address'
|
||||||
|
then:
|
||||||
|
make check
|
||||||
|
|
||||||
## Authors
|
## Authors
|
||||||
|
|
||||||
|
|
|
||||||
12
configure.ac
12
configure.ac
|
|
@ -1,6 +1,9 @@
|
||||||
# Init the 42sh project
|
# Init the 42sh project
|
||||||
AC_INIT([42sh], [1.0], [matteo.flebus@epita.fr])
|
AC_INIT([42sh], [1.0], [matteo.flebus@epita.fr])
|
||||||
|
|
||||||
|
# FLAGS="-std=c99 -pedantic -Werror -Wall -Wextra -Wvla"
|
||||||
|
# AC_SUBST([FLAGS])
|
||||||
|
|
||||||
# Setup Automake
|
# Setup Automake
|
||||||
AM_INIT_AUTOMAKE([subdir-objects] [foreign])
|
AM_INIT_AUTOMAKE([subdir-objects] [foreign])
|
||||||
|
|
||||||
|
|
@ -21,10 +24,17 @@ AC_PROG_CC
|
||||||
|
|
||||||
# List Makefiles in subdirectories
|
# List Makefiles in subdirectories
|
||||||
AC_CONFIG_FILES([
|
AC_CONFIG_FILES([
|
||||||
Makefile
|
|
||||||
src/Makefile
|
src/Makefile
|
||||||
src/ast/Makefile
|
src/ast/Makefile
|
||||||
src/parser/Makefile
|
src/parser/Makefile
|
||||||
src/lexer/Makefile
|
src/lexer/Makefile
|
||||||
|
src/io_backend/Makefile
|
||||||
|
src/execution/Makefile
|
||||||
|
src/expansion/Makefile
|
||||||
|
src/utils/Makefile
|
||||||
])
|
])
|
||||||
|
# TODO add tests Makefile here
|
||||||
|
# tests/Makefile
|
||||||
|
# tests/unit/Makefile
|
||||||
|
# tests/unit/utils/Makefile
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
# define the subdirectories
|
# define the subdirectories
|
||||||
SUBDIRS = \
|
SUBDIRS = \
|
||||||
ast \
|
|
||||||
parser \
|
parser \
|
||||||
lexer \
|
lexer \
|
||||||
io_backend \
|
io_backend \
|
||||||
execution \
|
execution \
|
||||||
expansin \
|
expansion \
|
||||||
utils
|
utils
|
||||||
|
|
||||||
bin_PROGRAMS = 42sh
|
bin_PROGRAMS = 42sh
|
||||||
|
|
@ -14,10 +13,7 @@ bin_PROGRAMS = 42sh
|
||||||
|
|
||||||
42sh_CPPFLAGS = -I%D%
|
42sh_CPPFLAGS = -I%D%
|
||||||
|
|
||||||
42sh_CFLAGS = -std=c99 -pedantic -Werror -Wall -Wextra -Wvla
|
|
||||||
|
|
||||||
42sh_LDADD = \
|
42sh_LDADD = \
|
||||||
ast/libast.a \
|
|
||||||
parser/libparser.a \
|
parser/libparser.a \
|
||||||
lexer/liblexer.a \
|
lexer/liblexer.a \
|
||||||
io_backend/libio_backend.a \
|
io_backend/libio_backend.a \
|
||||||
|
|
@ -27,20 +23,16 @@ bin_PROGRAMS = 42sh
|
||||||
|
|
||||||
|
|
||||||
################################################# Test
|
################################################# Test
|
||||||
|
#
|
||||||
bin_PROGRAMS = 42sh_asan
|
#42sh_asan_SOURCES = main.c
|
||||||
|
#
|
||||||
42sh_asan_SOURCES = main.c
|
#42sh_asan_CPPFLAGS = -I%D%
|
||||||
|
#
|
||||||
42sh_asan_CPPFLAGS = -I%D%
|
#42sh_asan_LDADD = \
|
||||||
|
# ast/lib_asan_ast.a \
|
||||||
42sh_asan_CFLAGS = -std=c99 -pedantic -Werror -Wall -Wextra -Wvla -g -fsanitize=address
|
# parser/lib_asan_parser.a \
|
||||||
|
# lexer/lib_asan_lexer.a \
|
||||||
42sh_asan_LDADD = \
|
# io_backend/lib_asan_io_backend.a \
|
||||||
ast/libast.a \
|
# expansion/lib_asan_expansion.a \
|
||||||
parser/libparser.a \
|
# execution/lib_asan_execution.a \
|
||||||
lexer/liblexer.a \
|
# utils/lib_asan_utils.a
|
||||||
io_backend/libio_backend.a \
|
|
||||||
expansion/libexpansion.a \
|
|
||||||
execution/libexecution.a \
|
|
||||||
utils/libutils.a
|
|
||||||
|
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
#ifndef AST_H
|
|
||||||
#define AST_H
|
|
||||||
|
|
||||||
#include "../utils/lists/lists.h"
|
|
||||||
|
|
||||||
enum ast_type
|
|
||||||
{
|
|
||||||
AST_END = 0,
|
|
||||||
AST_IF,
|
|
||||||
AST_CMD
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ast_cmd
|
|
||||||
{
|
|
||||||
struct list *cmd;
|
|
||||||
};
|
|
||||||
|
|
||||||
union ast_node;
|
|
||||||
|
|
||||||
struct ast
|
|
||||||
{
|
|
||||||
enum ast_type type;
|
|
||||||
union ast_node *data;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ast_if
|
|
||||||
{
|
|
||||||
struct ast *condition;
|
|
||||||
struct ast *then_clause;
|
|
||||||
struct ast *else_clause;
|
|
||||||
};
|
|
||||||
|
|
||||||
union ast_node
|
|
||||||
{
|
|
||||||
struct ast_if ast_if;
|
|
||||||
struct ast_cmd ast_cmd;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* ! AST_H */
|
|
||||||
|
|
@ -6,6 +6,4 @@ libexecution_a_SOURCES = \
|
||||||
|
|
||||||
libexecution_a_CPPFLAGS = -I$(top_srcdir)/src
|
libexecution_a_CPPFLAGS = -I$(top_srcdir)/src
|
||||||
|
|
||||||
libexecution_a_CFLAGS = -std=c99 -pedantic -Werror -Wall -Wextra -Wvla
|
|
||||||
|
|
||||||
noinst_LIBRARIES = libexecution.a
|
noinst_LIBRARIES = libexecution.a
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,4 @@ libexpansion_a_SOURCES = \
|
||||||
|
|
||||||
libexpansion_a_CPPFLAGS = -I$(top_srcdir)/src
|
libexpansion_a_CPPFLAGS = -I$(top_srcdir)/src
|
||||||
|
|
||||||
libexpansion_a_CFLAGS = -std=c99 -pedantic -Werror -Wall -Wextra -Wvla
|
|
||||||
|
|
||||||
noinst_LIBRARIES = libexpansion.a
|
noinst_LIBRARIES = libexpansion.a
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,4 @@ libio_backend_a_SOURCES = \
|
||||||
|
|
||||||
libio_backend_a_CPPFLAGS = -I$(top_srcdir)/src
|
libio_backend_a_CPPFLAGS = -I$(top_srcdir)/src
|
||||||
|
|
||||||
libio_backend_a_CFLAGS = -std=c99 -pedantic -Werror -Wall -Wextra -Wvla
|
|
||||||
|
|
||||||
noinst_LIBRARIES = libio_backend.a
|
noinst_LIBRARIES = libio_backend.a
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,4 @@ liblexer_a_SOURCES = \
|
||||||
|
|
||||||
liblexer_a_CPPFLAGS = -I$(top_srcdir)/src
|
liblexer_a_CPPFLAGS = -I$(top_srcdir)/src
|
||||||
|
|
||||||
liblexer_a_CFLAGS = -std=c99 -pedantic -Werror -Wall -Wextra -Wvla
|
|
||||||
|
|
||||||
noinst_LIBRARIES = liblexer.a
|
noinst_LIBRARIES = liblexer.a
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,4 @@ libparser_a_SOURCES = \
|
||||||
|
|
||||||
libparser_a_CPPFLAGS = -I$(top_srcdir)/src
|
libparser_a_CPPFLAGS = -I$(top_srcdir)/src
|
||||||
|
|
||||||
libparser_a_CFLAGS = -std=c99 -pedantic -Werror -Wall -Wextra -Wvla
|
|
||||||
|
|
||||||
noinst_LIBRARIES = libparser.a
|
noinst_LIBRARIES = libparser.a
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,8 @@
|
||||||
lib_LIBRARIES = libutils.a
|
lib_LIBRARIES = libutils.a
|
||||||
|
|
||||||
# libutils_a_SOURCES = \
|
libutils_a_SOURCES = \
|
||||||
# utils.c \
|
string_utils.c
|
||||||
# utils.h
|
|
||||||
|
|
||||||
# libutils_a_CPPFLAGS = -I$(top_srcdir)/src
|
libutils_a_CPPFLAGS = -I$(top_srcdir)/src
|
||||||
|
|
||||||
# libutils_a_CFLAGS = -std=c99 -pedantic -Werror -Wall -Wextra -Wvla
|
noinst_LIBRARIES = libutils.a
|
||||||
|
|
||||||
# noinst_LIBRARIES = libutils.a
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,4 @@ libast_a_SOURCES = \
|
||||||
|
|
||||||
libast_a_CPPFLAGS = -I$(top_srcdir)/src
|
libast_a_CPPFLAGS = -I$(top_srcdir)/src
|
||||||
|
|
||||||
libast_a_CFLAGS = -std=c99 -pedantic -Werror -Wall -Wextra -Wvla
|
|
||||||
|
|
||||||
noinst_LIBRARIES = libast.a
|
noinst_LIBRARIES = libast.a
|
||||||
68
src/utils/ast/ast.c
Normal file
68
src/utils/ast/ast.c
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
#include "ast.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
bool ast_is_if(struct ast *node)
|
||||||
|
{
|
||||||
|
assert(node != NULL);
|
||||||
|
return node->type == AST_IF;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ast_is_cmd(struct ast *node)
|
||||||
|
{
|
||||||
|
assert(node != NULL);
|
||||||
|
return node->type == AST_CMD;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ast_if *ast_get_if(struct ast *node)
|
||||||
|
{
|
||||||
|
assert(node != NULL);
|
||||||
|
assert(node->type == AST_IF);
|
||||||
|
return (struct ast_if *)node->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ast_cmd *ast_get_cmd(struct ast *node)
|
||||||
|
{
|
||||||
|
assert(node != NULL);
|
||||||
|
assert(node->type == AST_CMD);
|
||||||
|
return (struct ast_cmd *)node->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct ast *ast_create(enum ast_type type, void *data)
|
||||||
|
{
|
||||||
|
struct ast *node = malloc(sizeof(struct ast));
|
||||||
|
if (!node)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
node->type = type;
|
||||||
|
node->data = data;
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ast *ast_create_if(struct ast *condition, struct ast *then_clause,
|
||||||
|
struct ast *else_clause)
|
||||||
|
{
|
||||||
|
struct ast_if *if_data = malloc(sizeof(struct ast_if));
|
||||||
|
if (!if_data)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if_data->condition = condition;
|
||||||
|
if_data->then_clause = then_clause;
|
||||||
|
if_data->else_clause = else_clause;
|
||||||
|
|
||||||
|
return ast_create(AST_IF, if_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ast *ast_create_cmd(struct list *cmd)
|
||||||
|
{
|
||||||
|
struct ast_cmd *cmd_data = malloc(sizeof(struct ast_cmd));
|
||||||
|
if (!cmd_data)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
cmd_data->cmd = cmd;
|
||||||
|
|
||||||
|
return ast_create(AST_CMD, cmd_data);
|
||||||
|
}
|
||||||
73
src/utils/ast/ast.h
Normal file
73
src/utils/ast/ast.h
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
#ifndef AST_H
|
||||||
|
#define AST_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "../lists/lists.h"
|
||||||
|
|
||||||
|
enum ast_type
|
||||||
|
{
|
||||||
|
AST_END,
|
||||||
|
AST_IF,
|
||||||
|
AST_CMD
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ast_cmd
|
||||||
|
{
|
||||||
|
struct list *cmd;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ast_if
|
||||||
|
{
|
||||||
|
struct ast *condition;
|
||||||
|
struct ast *then_clause;
|
||||||
|
struct ast *else_clause;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ast
|
||||||
|
{
|
||||||
|
enum ast_type type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data associated with this AST node. It can be one of the following:
|
||||||
|
* - NULL (AST_END)
|
||||||
|
* - struct ast_if* (AST_IF)
|
||||||
|
* - struct ast_cmd* (AST_CMD)
|
||||||
|
*/
|
||||||
|
void *data;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given AST node is an if statement.
|
||||||
|
*/
|
||||||
|
bool ast_is_if(struct ast *node);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given AST node is a command.
|
||||||
|
*/
|
||||||
|
bool ast_is_cmd(struct ast *node);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the if statement data from the given AST node.
|
||||||
|
* Assumes that the node is of type AST_IF.
|
||||||
|
*/
|
||||||
|
struct ast_if *ast_get_if(struct ast *node);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the command data from the given AST node.
|
||||||
|
* Assumes that the node is of type AST_CMD.
|
||||||
|
*/
|
||||||
|
struct ast_cmd *ast_get_cmd(struct ast *node);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new AST node representing an if statement.
|
||||||
|
*/
|
||||||
|
struct ast *ast_create_if(struct ast *condition, struct ast *then_clause,
|
||||||
|
struct ast *else_clause);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new AST node representing a command.
|
||||||
|
*/
|
||||||
|
struct ast *ast_create_cmd(struct list *cmd);
|
||||||
|
|
||||||
|
#endif /* ! AST_H */
|
||||||
Loading…
Add table
Add a link
Reference in a new issue