adding subtypes

This commit is contained in:
hugogogo
2026-05-02 09:42:04 +02:00
parent bcbd3b2abb
commit 16d882e352
4 changed files with 307 additions and 54 deletions

View File

@@ -5,25 +5,172 @@
#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, // int
TOKEN_NUMBER_DOUBLE, // double
TOKEN_POWER, // ^ or **
TOKEN_SIGN, // + or -
TOKEN_FACTOR, // * or /
TOKEN_EQUAL, // =
TOKEN_END // null (end of input)
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;
int value_int;
double value_double;
};
} token;