⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 finsh.h

📁 中国人自己的c语言
💻 H
字号:
#ifndef __FINSH_H__
#define __FINSH_H__

#include <finsh/finsh_opts.h>

/* error code */
#define FINSH_ERROR_OK              0   /* No error */
#define FINSH_ERROR_INVALID_TOKEN	1	/* Invalid token */
#define FINSH_ERROR_EXPECT_TYPE		2	/* Expect a type */
#define FINSH_ERROR_UNKNOWN_TYPE	3	/* Unknown type */
#define FINSH_ERROR_VARIABLE_EXIST	4	/* Variable exist */
#define FINSH_ERROR_EXPECT_OPERATOR	5	/* Expect a operater */
#define FINSH_ERROR_MEMORY_FULL		6	/* Memory full */
#define FINSH_ERROR_UNKNOWN_OP		7 	/* Unknown operator */
#define FINSH_ERROR_UNKNOWN_NODE	8	/* Unknown node */
#define FINSH_ERROR_EXPECT_CHAR		9	/* Expect a character */
#define FINSH_ERROR_UNEXPECT_END	10	/* Unexpect end */
#define FINSH_ERROR_UNKNOWN_TOKEN	11	/* Unknown token */
#define FINSH_ERROR_NO_FLOAT		12	/* Float not supported */
#define FINSH_ERROR_UNKNOWN_SYMBOL	13	/* Unknown symbol */

typedef void (*syscall_func)();

/* system call table */
struct finsh_syscall
{
    /* the name of system call */
	u_char* name;

    /* the function address of system call */
	syscall_func func;
};
/* findout system call, which should be implemented in user program */
struct finsh_syscall* finsh_syscall_lookup(const u_char* name);

struct finsh_token
{
	char eof:4;
	char replay:4;

	int  position;
	u_char current_token;

	union {
		char char_value;
		int int_value;
		long long_value;
	};
	u_char string[128];

	u_char* line;
};

struct finsh_node
{
	/* node type */
	u_char type;

	/* node data type */
	u_char dtype;

	union
	{
		/* value node */
		char 	char_value;
		short 	short_value;
		int 	int_value;
		long 	long_value;
		void* 	ptr;
	};

	/* id node information */

	/* id node address, value or function */
	u_char avf;

	/* point to variable identifier or function identifier */
	union {
		struct finsh_var * var;
		struct finsh_syscall* func;
	};

	/* sibling node */
	struct finsh_node* sibling;

	/* child node */
	struct finsh_node* child;
};

struct finsh_parser
{
	u_char* parser_string;

    struct finsh_token token;
	struct finsh_node* root;
};

/* init finsh environment */
int finsh_init(struct finsh_parser* parser);
/* flush finsh node, text segment */
int finsh_flush(struct finsh_parser* parser);
/* reset all of finsh */
int finsh_reset(struct finsh_parser* parser);

/* run finsh parser to generate abstract synatx tree */
void finsh_parser_run (struct finsh_parser* parser, const unsigned char* string);
/* run compiler to compile abstract syntax tree */
int finsh_compiler_run(struct finsh_node* node);
/* run finsh virtual machine */
void finsh_vm_run();

/* get variable value */
struct finsh_var* finsh_var_lookup(const unsigned char* name);
/* get bottom value of stack */
long finsh_stack_bottom();

/* get error number of finsh */
u_char finsh_errno();
/* get error string */
const u_char* finsh_error_string(u_char type);


#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -