remove individuals headers to avoid circular dependencies

This commit is contained in:
hugogogo
2026-05-03 11:29:01 +02:00
parent 42cfdf9734
commit cdc066c935
9 changed files with 213 additions and 194 deletions

View File

@@ -1,10 +1,104 @@
/* computorv1.h */
#ifndef COMPUTORV1_H
#define COMPUTORV1_H
#include "libft.h"
#include "lexer.h"
#include "parser.h"
#include "errors.h"
#include <stdio.h> // tmp for printf, for float debug
#include <stdio.h> // tmp for printf, for float debug
#include <stdarg.h> // for va_list
#include <stdbool.h>
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* LEXER.C
*/
typedef enum
{
TOKEN_VARIABLE, // x, y, etc.
TOKEN_NUMBER_INT, // int
TOKEN_NUMBER_DOUBLE, // double
TOKEN_POWER, // ^ or **
TOKEN_SIGN_PLUS, // +
TOKEN_SIGN_MINUS, // -
TOKEN_FACTOR_MULT, // *
TOKEN_FACTOR_DIV, // / or :
TOKEN_EQUAL, // =
TOKEN_END // null (end of input)
} token_type;
typedef enum
{
TOKEN_NO_TAG,
TOKEN_NUMBER,
TOKEN_SIGN,
TOKEN_FACTOR,
} token_tag;
typedef struct
{
token_type type;
token_tag tag;
union
{
char value_char;
double value_double;
};
} token;
int lexerize(const char *input, token *tokens);
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* PARSER.C
*/
typedef enum
{
TERM_LEFT, // a in "a = b"
TERM_RIGHT, // b in "a = b"
TERM_END, // last term
} term_position;
typedef enum
{
TERM_PLUS, // +
TERM_MINUS, // -
TERM_NULL, // null -> for the last term
} term_sign;
typedef struct
{
term_position position;
term_sign sign;
double coefficient;
double exponent;
} term;
int parse(token *tokens, term *terms, int terms_count_max);
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* ERRORS.C
*/
typedef enum
{
ERROR_BASE = 1, // start at 1 to avoid exit(0) for errors
ERROR_TOKEN_COUNT,
ERROR_UNKNOWN_TOKEN,
ERROR_NUMBER_TOO_BIG,
ERROR_PARSING,
ERROR_TERM_COUNT,
ERROR_TOKEN_POSITION,
ERROR_VAR_DIFF,
ERROR_SENTINEL, // last token not used, only for enum count
} program_error;
int stop_errors(program_error err, const char *format, ...);
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* GLOBALS
*/
extern char *input_g_err;
extern token *tokens_g_err;
#endif

View File

@@ -1,17 +0,0 @@
#ifndef ERRORS_H
#define ERRORS_H
typedef enum
{
ERROR_BASE = 1, // Start at 1 to avoid exit(0) for errors
ERROR_UNKNOWN_TOKEN,
ERROR_NUMBER_TOO_BIG,
ERROR_PARSING,
ERROR_TOKEN_POSITION,
ERROR_VAR_DIFF,
ERROR_SENTINEL,
} program_error;
int stop_errors(program_error err, token *tokens, char *input, const char *format, ...);
#endif

View File

@@ -1,43 +0,0 @@
#ifndef LEXER_H
#define LEXER_H
#include "libft.h"
#include "errors.h"
#include <stdbool.h>
typedef enum
{
TOKEN_VARIABLE, // x, y, etc.
TOKEN_NUMBER_INT, // int
TOKEN_NUMBER_DOUBLE, // double
TOKEN_POWER, // ^ or **
TOKEN_SIGN_PLUS, // +
TOKEN_SIGN_MINUS, // -
TOKEN_FACTOR_MULT, // *
TOKEN_FACTOR_DIV, // / or :
TOKEN_EQUAL, // =
TOKEN_END // null (end of input)
} token_type;
typedef enum
{
TOKEN_NO_TAG,
TOKEN_NUMBER,
TOKEN_SIGN,
TOKEN_FACTOR,
} token_tag;
typedef struct
{
token_type type;
token_tag tag;
union
{
char value_char;
double value_double;
};
} token;
int lexerize(const char *input, token *tokens);
#endif

View File

@@ -1,28 +0,0 @@
#ifndef PARSER_H
#define PARSER_H
typedef enum
{
TERM_LEFT, // a in "a = b"
TERM_RIGHT, // b in "a = b"
TERM_END, // last term
} term_position;
typedef enum
{
TERM_PLUS, // +
TERM_MINUS, // -
TERM_NULL, // null -> for the last term
} term_sign;
typedef struct
{
term_position position;
term_sign sign;
double coefficient;
double exponent;
} term;
int parse(token *tokens, term *terms, int terms_count_max);
#endif