summaryrefslogtreecommitdiff
path: root/sos-code-article6/sos/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'sos-code-article6/sos/main.c')
-rw-r--r--sos-code-article6/sos/main.c61
1 files changed, 32 insertions, 29 deletions
diff --git a/sos-code-article6/sos/main.c b/sos-code-article6/sos/main.c
index 37f1d68..546dbe7 100644
--- a/sos-code-article6/sos/main.c
+++ b/sos-code-article6/sos/main.c
@@ -79,7 +79,7 @@ static void dump_backtrace(const struct sos_cpu_state *cpu_state,
sos_bool_t on_console,
sos_bool_t on_bochs)
{
- static void backtracer(sos_vaddr_t PC,
+ void backtracer(sos_vaddr_t PC,
sos_vaddr_t params,
sos_ui32_t depth,
void *custom_arg)
@@ -599,24 +599,23 @@ struct syntax_node
};
};
-static void func_parser(struct syntax_node ** syntax_tree)
-{
- static struct syntax_node *alloc_node_num(int val);
- static struct syntax_node *alloc_node_var(const char * name);
- static struct syntax_node *alloc_node_binop(char op,
+// BEGIN AUX FUNCTIONS
+ struct syntax_node *alloc_node_num(int val);
+ struct syntax_node *alloc_node_var(const char * name);
+ struct syntax_node *alloc_node_binop(char op,
struct syntax_node *parm_left,
struct syntax_node *parm_right);
- static struct syntax_node *alloc_node_unarop(char op,
+ struct syntax_node *alloc_node_unarop(char op,
struct syntax_node *parm);
- static struct syntax_node * get_expr();
- static struct syntax_node * get_expr_lr(struct syntax_node *n);
- static struct syntax_node * get_term();
- static struct syntax_node * get_term_lr(struct syntax_node *n);
- static struct syntax_node * get_factor();
- static struct syntax_node * get_scalar();
+ struct syntax_node * get_expr();
+ struct syntax_node * get_expr_lr(struct syntax_node *n);
+ struct syntax_node * get_term();
+ struct syntax_node * get_term_lr(struct syntax_node *n);
+ struct syntax_node * get_factor();
+ struct syntax_node * get_scalar();
/* Create a new node to store a number */
- static struct syntax_node *alloc_node_num(int val)
+ struct syntax_node *alloc_node_num(int val)
{
struct syntax_node *n
= (struct syntax_node*) sos_kmalloc(sizeof(struct syntax_node), 0);
@@ -625,7 +624,7 @@ static void func_parser(struct syntax_node ** syntax_tree)
return n;
}
/* Create a new node to store a variable */
- static struct syntax_node *alloc_node_var(const char * name)
+ struct syntax_node *alloc_node_var(const char * name)
{
struct syntax_node *n
= (struct syntax_node*) sos_kmalloc(sizeof(struct syntax_node), 0);
@@ -634,7 +633,7 @@ static void func_parser(struct syntax_node ** syntax_tree)
return n;
}
/* Create a new node to store a binary operator */
- static struct syntax_node *alloc_node_binop(char op,
+ struct syntax_node *alloc_node_binop(char op,
struct syntax_node *parm_left,
struct syntax_node *parm_right)
{
@@ -647,7 +646,7 @@ static void func_parser(struct syntax_node ** syntax_tree)
return n;
}
/* Create a new node to store a unary operator */
- static struct syntax_node *alloc_node_unarop(char op,
+ struct syntax_node *alloc_node_unarop(char op,
struct syntax_node *parm)
{
struct syntax_node *n
@@ -660,7 +659,7 @@ static void func_parser(struct syntax_node ** syntax_tree)
/* Raise an exception: transfer control back to main context,
without unrolling the whole recursion */
- static void parser_exception(const char *str)
+ void parser_exception(const char *str)
{
sos_bochs_printf("Parser exception: %s\n", str);
sos_cpu_context_switch(& st_parser, st_main);
@@ -668,7 +667,7 @@ static void func_parser(struct syntax_node ** syntax_tree)
/* Consume the current terminal "number" token and ask for a new
token */
- static int get_number()
+ int get_number()
{
int v;
if (data_lexer_to_parser.type != LEX_IS_NUMBER)
@@ -679,7 +678,7 @@ static void func_parser(struct syntax_node ** syntax_tree)
}
/* Consume the current terminal "variable" token and ask for a new
token */
- static void get_str(char name[STR_VAR_MAXLEN])
+ void get_str(char name[STR_VAR_MAXLEN])
{
if (data_lexer_to_parser.type != LEX_IS_VAR)
parser_exception("Expected variable");
@@ -688,7 +687,7 @@ static void func_parser(struct syntax_node ** syntax_tree)
}
/* Consume the current terminal "operator" token and ask for a new
token */
- static char get_op()
+ char get_op()
{
char op;
if (data_lexer_to_parser.type != LEX_IS_OPER)
@@ -699,7 +698,7 @@ static void func_parser(struct syntax_node ** syntax_tree)
}
/* Consume the current terminal "parenthese" token and ask for a new
token */
- static void get_par()
+ void get_par()
{
if ( (data_lexer_to_parser.type != LEX_IS_OPENPAR)
&& (data_lexer_to_parser.type != LEX_IS_CLOSEPAR) )
@@ -708,13 +707,13 @@ static void func_parser(struct syntax_node ** syntax_tree)
}
/* Parse an Expression */
- static struct syntax_node * get_expr()
+ struct syntax_node * get_expr()
{
struct syntax_node *t = get_term();
return get_expr_lr(t);
}
/* Parse an Expr_lr */
- static struct syntax_node * get_expr_lr(struct syntax_node *n)
+ struct syntax_node * get_expr_lr(struct syntax_node *n)
{
if ( (data_lexer_to_parser.type == LEX_IS_OPER)
&& ( (data_lexer_to_parser.operator == '+')
@@ -728,13 +727,13 @@ static void func_parser(struct syntax_node ** syntax_tree)
return n;
}
/* Parse a Term */
- static struct syntax_node * get_term()
+ struct syntax_node * get_term()
{
struct syntax_node *f1 = get_factor();
return get_term_lr(f1);
}
/* Parse a Term_lr */
- static struct syntax_node * get_term_lr(struct syntax_node *n)
+ struct syntax_node * get_term_lr(struct syntax_node *n)
{
if ( (data_lexer_to_parser.type == LEX_IS_OPER)
&& ( (data_lexer_to_parser.operator == '*')
@@ -748,7 +747,7 @@ static void func_parser(struct syntax_node ** syntax_tree)
return n;
}
/* Parse a Factor */
- static struct syntax_node * get_factor()
+ struct syntax_node * get_factor()
{
if ( (data_lexer_to_parser.type == LEX_IS_OPER)
&& ( (data_lexer_to_parser.operator == '-')
@@ -769,7 +768,7 @@ static void func_parser(struct syntax_node ** syntax_tree)
return get_scalar();
}
/* Parse a Scalar */
- static struct syntax_node * get_scalar()
+ struct syntax_node * get_scalar()
{
if (data_lexer_to_parser.type != LEX_IS_NUMBER)
{
@@ -780,7 +779,11 @@ static void func_parser(struct syntax_node ** syntax_tree)
return alloc_node_num(get_number());
}
+// END AUX FUNCTIONS
+
+static void func_parser(struct syntax_node ** syntax_tree)
+{
/*
* Body of the function
*/
@@ -841,7 +844,7 @@ static void func_eval(struct func_eval_params *parms)
{
/* The internal (recursive) nested function to evaluate each node of
the syntax tree */
- static int rec_eval(const struct syntax_node *n,
+ int rec_eval(const struct syntax_node *n,
const char* var_name[], int var_val[], int nb_vars)
{
switch (n->type)