wip parsing and error
This commit is contained in:
@@ -12,6 +12,6 @@ typedef enum
|
||||
ERROR_SENTINEL,
|
||||
} program_error;
|
||||
|
||||
int stop_errors(program_error err, const char *format, ...);
|
||||
int stop_errors(program_error err, token *tokens, char *input, const char *format, ...);
|
||||
|
||||
#endif
|
||||
174
headers/lexer.h
174
headers/lexer.h
@@ -5,180 +5,6 @@
|
||||
#include "errors.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
/**
|
||||
* PROPOSITION 1
|
||||
*/
|
||||
|
||||
// typedef enum
|
||||
// {
|
||||
// TOKEN_VARIABLE, // x, y, etc.
|
||||
// TOKEN_NUMBER, // int or double
|
||||
// TOKEN_POWER, // ^ or **
|
||||
// TOKEN_SIGN, // + or -
|
||||
// TOKEN_FACTOR, // * or / or :
|
||||
// TOKEN_EQUAL, // =
|
||||
// TOKEN_END // null (end of input)
|
||||
// } token_type;
|
||||
//
|
||||
// typedef enum
|
||||
// {
|
||||
// TOKEN_NUMBER_INT, // int
|
||||
// TOKEN_NUMBER_DOUBLE, // double
|
||||
// TOKEN_SIGN_ADD, // +
|
||||
// TOKEN_SIGN_MINUS, // -
|
||||
// TOKEN_FACTOR_MULTIPLICATION, // *
|
||||
// TOKEN_FACTOR_DIVISION, // / or :
|
||||
// } token_subtype;
|
||||
//
|
||||
// typedef struct
|
||||
// {
|
||||
// token_type type;
|
||||
// token_subtype subtype;
|
||||
// union
|
||||
// {
|
||||
// char value_char;
|
||||
// double value_double;
|
||||
// };
|
||||
// } token;
|
||||
|
||||
/**
|
||||
* PROPOSITION 2
|
||||
*/
|
||||
|
||||
// // TYPES and SUBTYPES
|
||||
|
||||
// typedef enum
|
||||
// {
|
||||
// TOKEN_VARIABLE, // x, y, etc.
|
||||
// TOKEN_NUMBER, // int or double
|
||||
// TOKEN_POWER, // ^ or **
|
||||
// TOKEN_SIGN, // + or -
|
||||
// TOKEN_FACTOR, // * or / or :
|
||||
// TOKEN_EQUAL, // =
|
||||
// TOKEN_END // null (end of input)
|
||||
// } token_type;
|
||||
//
|
||||
// typedef enum
|
||||
// {
|
||||
// NUMBER_INT,
|
||||
// NUMBER_DOUBLE
|
||||
// } number_subtype;
|
||||
//
|
||||
// typedef enum
|
||||
// {
|
||||
// SIGN_ADD, // +
|
||||
// SIGN_MINUS // -
|
||||
// } sign_subtype;
|
||||
//
|
||||
// typedef enum
|
||||
// {
|
||||
// FACTOR_MULTIPLICATION, // *
|
||||
// FACTOR_DIVISION, // / or :
|
||||
// } factor_subtype;
|
||||
//
|
||||
// // DATA
|
||||
//
|
||||
// typedef struct
|
||||
// {
|
||||
// char value; // e.g., 'x', 'y'
|
||||
// } token_variable;
|
||||
//
|
||||
// typedef struct
|
||||
// {
|
||||
// number_subtype subtype;
|
||||
// double value;
|
||||
// } token_number;
|
||||
//
|
||||
// typedef struct
|
||||
// {
|
||||
// sign_subtype subtype;
|
||||
// char value;
|
||||
// } token_sign;
|
||||
//
|
||||
// typedef struct
|
||||
// {
|
||||
// factor_subtype subtype;
|
||||
// char value;
|
||||
// } token_factor;
|
||||
//
|
||||
// typedef struct
|
||||
// {
|
||||
// char value;
|
||||
// } token_power;
|
||||
//
|
||||
// typedef struct
|
||||
// {
|
||||
// char value;
|
||||
// } token_equal;
|
||||
//
|
||||
// typedef struct
|
||||
// {
|
||||
// char value;
|
||||
// } token_end;
|
||||
//
|
||||
// // TOKEN
|
||||
//
|
||||
// typedef union
|
||||
// {
|
||||
// token_variable variable; // value
|
||||
// token_number number; // subtype [INT, DOUBLE], value
|
||||
// token_sign sign; // subtype [PLUS, MINUS], value
|
||||
// token_factor factor; // subtype [MULT, DIV], value
|
||||
// token_power power; // value
|
||||
// token_equal equal; // value
|
||||
// token_end end; // value
|
||||
// } token_data;
|
||||
//
|
||||
// typedef struct
|
||||
// {
|
||||
// token_type type;
|
||||
// token_data data;
|
||||
// } token;
|
||||
|
||||
/**
|
||||
* PROPOSITION 3
|
||||
*/
|
||||
|
||||
// typedef enum
|
||||
// {
|
||||
// TOKEN_VARIABLE, // x, y, etc.
|
||||
// TOKEN_NUMBER, // int or double
|
||||
// TOKEN_POWER, // ^ or **
|
||||
// TOKEN_SIGN, // + or -
|
||||
// TOKEN_FACTOR, // * or / or :
|
||||
// TOKEN_EQUAL, // =
|
||||
// TOKEN_END // null (end of input)
|
||||
// } token_type;
|
||||
//
|
||||
// typedef enum
|
||||
// {
|
||||
// TOKEN_NO_SUBTYPE,
|
||||
// // NUMBER
|
||||
// TOKEN_NUMBER_INT,
|
||||
// TOKEN_NUMBER_DOUBLE,
|
||||
// // SIGN
|
||||
// TOKEN_SIGN_PLUS,
|
||||
// TOKEN_SIGN_MINUS,
|
||||
// // FACTOR
|
||||
// TOKEN_FACTOR_MULTIPLICATION,
|
||||
// TOKEN_FACTOR_DIVISION,
|
||||
// } token_subtype;
|
||||
//
|
||||
// typedef struct
|
||||
// {
|
||||
// token_type type;
|
||||
// token_subtype subtype;
|
||||
// union
|
||||
// {
|
||||
// char value_char;
|
||||
// double value_double;
|
||||
// };
|
||||
// } token;
|
||||
|
||||
/**
|
||||
* PROPOSITION 4
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TOKEN_VARIABLE, // x, y, etc.
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
#ifndef PARSER_H
|
||||
#define PARSER_H
|
||||
|
||||
#include "libft.h"
|
||||
#include "lexer.h"
|
||||
#include "errors.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TERM_LEFT, // a in "a = b"
|
||||
@@ -25,7 +20,7 @@ typedef struct
|
||||
term_position position;
|
||||
term_sign sign;
|
||||
double coefficient;
|
||||
int exponent;
|
||||
double exponent;
|
||||
} term;
|
||||
|
||||
int parse(token *tokens, term *terms, int terms_count_max);
|
||||
|
||||
Reference in New Issue
Block a user