renamed enum and struct
This commit is contained in:
@@ -7,8 +7,8 @@
|
||||
*/
|
||||
|
||||
char *input_g_err;
|
||||
token *tokens_g_err;
|
||||
term *terms_g_err;
|
||||
s_token *tokens_g_err;
|
||||
s_term *terms_g_err;
|
||||
|
||||
/**
|
||||
* PROGRAM
|
||||
@@ -50,7 +50,7 @@ static size_t count_any_of(const char *s, const char *set)
|
||||
return count;
|
||||
}
|
||||
|
||||
static void tokens_fill_null(token *tokens, size_t arg_len)
|
||||
static void tokens_fill_null(s_token *tokens, size_t arg_len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -64,7 +64,7 @@ static void tokens_fill_null(token *tokens, size_t arg_len)
|
||||
}
|
||||
}
|
||||
|
||||
static void terms_fill_null(term *terms, size_t terms_count_prediction)
|
||||
static void terms_fill_null(s_term *terms, size_t terms_count_prediction)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -99,7 +99,7 @@ int main(int ac, char **av)
|
||||
// lexerize
|
||||
arg_len = ft_strlen(input) + 1; // +1 for last END token
|
||||
ft_printf("-> tokens[%i]\n", arg_len); // debug
|
||||
token tokens[arg_len];
|
||||
s_token tokens[arg_len];
|
||||
tokens_g_err = tokens;
|
||||
tokens_fill_null(tokens, arg_len);
|
||||
ret = lexerize(input, tokens);
|
||||
@@ -111,7 +111,7 @@ int main(int ac, char **av)
|
||||
// parse
|
||||
terms_count_prediction = count_any_of(input, "-+=") + 2; // +1 for first term that can have no leading '+', +1 for last term == NULL
|
||||
ft_printf("-> terms[%i]\n", terms_count_prediction); // debug
|
||||
term terms[terms_count_prediction];
|
||||
s_term terms[terms_count_prediction];
|
||||
terms_g_err = terms;
|
||||
terms_fill_null(terms, terms_count_prediction);
|
||||
ret = parse(tokens, terms, terms_count_prediction);
|
||||
@@ -120,6 +120,10 @@ int main(int ac, char **av)
|
||||
stop_errors(ERROR_TERM_COUNT, "parser returned 0 term");
|
||||
}
|
||||
|
||||
// reduce
|
||||
s_polynom *polynom;
|
||||
reduce(terms, polynom);
|
||||
|
||||
// debug
|
||||
print_state();
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ static bool token_is_equal(const char *input, int input_pos, int *token_size)
|
||||
/**
|
||||
* LEXER
|
||||
*/
|
||||
int lexerize(const char *input, token *tokens)
|
||||
int lexerize(const char *input, s_token *tokens)
|
||||
{
|
||||
int tokens_count;
|
||||
int input_pos;
|
||||
|
||||
16
src/parser.c
16
src/parser.c
@@ -13,7 +13,7 @@
|
||||
NT | ! NUMBER | NT | ! SIGN | FACTOR | NT | NT
|
||||
*/
|
||||
|
||||
static term_sign get_sign(token *tokens, int i, int *token_count)
|
||||
static e_term_sign get_sign(s_token *tokens, int i, int *token_count)
|
||||
{
|
||||
// // forbidden tokens
|
||||
// if (tokens[i].type == TOKEN_POWER)
|
||||
@@ -52,7 +52,7 @@ static term_sign get_sign(token *tokens, int i, int *token_count)
|
||||
return tokens[i].type == TOKEN_SIGN_PLUS ? TERM_PLUS : TERM_MINUS;
|
||||
}
|
||||
|
||||
static double get_double_value(token token)
|
||||
static double get_double_value(s_token token)
|
||||
{
|
||||
if (token.tag != TOKEN_NUMBER)
|
||||
{
|
||||
@@ -66,7 +66,7 @@ static double get_double_value(token token)
|
||||
return token.value_int;
|
||||
}
|
||||
|
||||
static double get_coefficient(token *tokens, int i, int *token_count)
|
||||
static double get_coefficient(s_token *tokens, int i, int *token_count)
|
||||
{
|
||||
double coefficient;
|
||||
|
||||
@@ -129,7 +129,7 @@ static double get_coefficient(token *tokens, int i, int *token_count)
|
||||
return coefficient;
|
||||
}
|
||||
|
||||
static int get_exponent(token *tokens, int i, int *token_count)
|
||||
static int get_exponent(s_token *tokens, int i, int *token_count)
|
||||
{
|
||||
// // forbidden tokens
|
||||
// if (tokens[i].type == TOKEN_POWER)
|
||||
@@ -197,7 +197,7 @@ static int get_exponent(token *tokens, int i, int *token_count)
|
||||
return tokens[i].value_int;
|
||||
}
|
||||
|
||||
static void check_variables(token *tokens)
|
||||
static void check_variables(s_token *tokens)
|
||||
{
|
||||
int i;
|
||||
char var;
|
||||
@@ -222,12 +222,12 @@ static void check_variables(token *tokens)
|
||||
}
|
||||
}
|
||||
|
||||
int parse(token *tokens, term *terms, int terms_count_max)
|
||||
int parse(s_token *tokens, s_term *terms, int terms_count_max)
|
||||
{
|
||||
int i;
|
||||
int terms_count;
|
||||
int token_count;
|
||||
term_position term_position;
|
||||
e_term_position term_position;
|
||||
|
||||
check_variables(tokens);
|
||||
|
||||
@@ -251,7 +251,7 @@ int parse(token *tokens, term *terms, int terms_count_max)
|
||||
terms[terms_count].position = term_position;
|
||||
|
||||
// sign
|
||||
term_sign ret_sign = get_sign(tokens, i, &token_count);
|
||||
e_term_sign ret_sign = get_sign(tokens, i, &token_count);
|
||||
terms[terms_count].sign = ret_sign;
|
||||
i += token_count;
|
||||
// ft_printf("term[%i] get_sign: (%i)[%s], token_count: [%d]\n", terms_count, ret_sign, term_sign_to_str(ret_sign), token_count); // debug
|
||||
|
||||
7
src/reduce.c
Normal file
7
src/reduce.c
Normal file
@@ -0,0 +1,7 @@
|
||||
/* reduce.c */
|
||||
|
||||
#include "computorv1.h"
|
||||
|
||||
void reduce(s_term *terms, s_polynom *polynom)
|
||||
{
|
||||
}
|
||||
@@ -106,7 +106,7 @@ void print_state()
|
||||
print_context_terms();
|
||||
}
|
||||
|
||||
int stop_errors(program_error err, const char *details, ...)
|
||||
int stop_errors(e_program_error err, const char *details, ...)
|
||||
{
|
||||
// the base error message
|
||||
const char *msg = "error: error type is out of range";
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "computorv1.h"
|
||||
|
||||
const char *token_type_to_str(token_type enum_value)
|
||||
const char *token_type_to_str(e_token_type enum_value)
|
||||
{
|
||||
if (enum_value > TOKEN_END || enum_value < TOKEN_VARIABLE)
|
||||
return "invalid enum value";
|
||||
@@ -21,7 +21,7 @@ const char *token_type_to_str(token_type enum_value)
|
||||
return token_type_str[enum_value];
|
||||
}
|
||||
|
||||
const char *token_tag_to_str(token_tag enum_value)
|
||||
const char *token_tag_to_str(e_token_tag enum_value)
|
||||
{
|
||||
if (enum_value > TOKEN_FACTOR || enum_value < TOKEN_NO_TAG)
|
||||
return "invalid enum value";
|
||||
@@ -34,7 +34,7 @@ const char *token_tag_to_str(token_tag enum_value)
|
||||
return token_tag_str[enum_value];
|
||||
}
|
||||
|
||||
const char *term_position_to_str(term_position enum_value)
|
||||
const char *term_position_to_str(e_term_position enum_value)
|
||||
{
|
||||
if (enum_value > TERM_END || enum_value < TERM_LEFT)
|
||||
return "invalid enum value";
|
||||
@@ -46,7 +46,7 @@ const char *term_position_to_str(term_position enum_value)
|
||||
return term_position_str[enum_value];
|
||||
}
|
||||
|
||||
const char *term_sign_to_str(term_sign enum_value)
|
||||
const char *term_sign_to_str(e_term_sign enum_value)
|
||||
{
|
||||
if (enum_value > TERM_NULL || enum_value < TERM_PLUS)
|
||||
return "invalid enum value";
|
||||
|
||||
Reference in New Issue
Block a user