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

📄 parse.y

📁 开放源码的Boot
💻 Y
字号:
%{#include <stdio.h>#include <ctype.h>#include <stdlib.h>#include <string.h>#include "nodes.h"void yyerror (char *s);struct node *config_node;extern void *xmalloc (size_t size);%}%union {	char *string;	struct node *node;	unsigned long integer;	unsigned int flags;};%token ARGS%token FLAGS%token <integer> INTEGER%token INITRD%token KERNEL%token NAME%token NORDLOAD%token NORDPROMPT%token PASSWORD%token PATH%token PONARGS%token <size> RAMDISK%token RDLOAD%token RDPROMPT%token RDSTART%token READONLY%token READWRITE%token RISCOS%token ROOT%token <string> STRING%token CONFIG%type <node> kernelpart%type <node> kernelbits%type <node> kernel%type <node> riscos%type <node> file%type <node> descriptor%type <node> riscospart%type <node> riscosbits%type <node> configpart%type <node> configbits%type <node> cfg%type <flags> flags%type <flags> flagbits;%%config:		file		{			config_node = $1;		}	;file:		descriptor		{			$$ = $1;		}	|	descriptor file		{			$1->next = $2;			$$ = $1;		}	;descriptor:	kernel		{			$$ = $1;		}	|	riscos		{			$$ = $1;		}	|	cfg		{			$$ = $1;		}	;kernel:		KERNEL '{' kernelbits		{			struct node *node;			node = xmalloc (sizeof (struct node));			node->type = KERNEL;			node->u.n = $3;			$$ = node;		}	;riscos:		RISCOS '{' riscosbits		{			struct node *node;			node = xmalloc (sizeof (struct node));			node->type = RISCOS;			node->u.n = $3;			$$ = node;		}	;cfg:		CONFIG '{' configbits		{			struct node *node;			node = xmalloc (sizeof (struct node));			node->type = CONFIG;			node->u.n = $3;			$$ = node;		}	;kernelbits:	kernelpart '}' ';'		{			$$ = $1;		}	|	kernelpart kernelbits		{			$1->next = $2;			$$ = $1;		}	;riscosbits:	riscospart '}' ';'		{			$$ = $1;		}	|	riscospart riscosbits		{			$1->next = $2;			$$ = $1;		}	;configbits:	configpart '}' ';'		{			$$ = $1;		}	;kernelpart:	NAME '=' STRING ';'		{			struct node *node;			node = xmalloc (sizeof (struct node));			node->type = NAME;			node->u.string = xmalloc (strlen ($3)+1);			strcpy (node->u.string, $3);			$$ = node;		}	|	ARGS '=' STRING ';'		{			struct node *node;			node = xmalloc (sizeof (struct node));			node->type = ARGS;			node->u.string = xmalloc (strlen ($3)+1);			strcpy (node->u.string, $3);			$$ = node;		}	|	FLAGS '=' flags		{			struct node *node;			node = xmalloc (sizeof (struct node));			node->type = FLAGS;			node->u.flags = $3;			$$ = node;		}	|	INITRD '=' STRING ';'		{			struct node *node;			node = xmalloc (sizeof (struct node));			node->type = INITRD;			node->u.string = xmalloc (strlen ($3)+1);			strcpy (node->u.string, $3);			$$ = node;		}	|	PASSWORD '=' STRING ';'		{			struct node *node;			node = xmalloc (sizeof (struct node));			node->type = PASSWORD;			node->u.string = xmalloc (strlen ($3)+1);			strcpy (node->u.string, $3);			$$ = node;		}	|	PATH '=' STRING ';'		{			struct node *node;			node = xmalloc (sizeof (struct node));			node->type = PATH;			node->u.string = xmalloc (strlen ($3)+1);			strcpy (node->u.string, $3);			$$ = node;		}	|	RAMDISK '=' INTEGER ';'		{			struct node *node;			node = xmalloc (sizeof (struct node));			node->type = RAMDISK;			node->u.size = $3;			$$ = node;		}	|	RDSTART '=' INTEGER ';'		{			struct node *node;			node = xmalloc (sizeof (struct node));			node->type = RDSTART;			node->u.offset = $3;			$$ = node;		}	|	ROOT '=' STRING ';'		{			struct node *node;			node = xmalloc (sizeof (struct node));			node->type = ROOT;			node->u.string = xmalloc (strlen ($3)+1);			strcpy (node->u.string, $3);			$$ = node;		}	;riscospart:	NAME '=' STRING ';'		{			struct node *node;			node = xmalloc (sizeof (struct node));			node->type = NAME;			node->u.string = xmalloc (strlen ($3)+1);			strcpy (node->u.string, $3);			$$ = node;		}	|	ARGS '=' STRING ';'		{			struct node *node;			node = xmalloc (sizeof (struct node));			node->type = ARGS;			node->u.string = xmalloc (strlen ($3)+1);			strcpy (node->u.string, $3);			$$ = node;		}	|	PASSWORD '=' STRING ';'		{			struct node *node;			node = xmalloc (sizeof (struct node));			node->type = PASSWORD;			node->u.string = xmalloc (strlen ($3)+1);			strcpy (node->u.string, $3);			$$ = node;		}	;configpart:	ROOT '=' STRING ';'		{			struct node *node;			node = xmalloc (sizeof (struct node));			node->type = ROOT;			node->u.string = xmalloc (strlen ($3)+1);			strcpy (node->u.string, $3);			$$ = node;		}	;flags:		flagbits ';'		{			$$ = $1;		}	|	flagbits flags		{			$$ = $1 | $2;			$$ = $$ & ((~$$) >> 16);		}flagbits:	RDLOAD		{			$$ = FLAG_RDLOAD;		}	|	NORDLOAD		{			$$ = FLAG_RDLOAD << 16;		}	|	RDPROMPT		{			$$ = FLAG_RDPROMPT;		}	|	NORDPROMPT		{			$$ = FLAG_RDPROMPT << 16;		}	|	READONLY		{			$$ = FLAG_READONLY;		}	|	READWRITE		{			$$ = FLAG_READONLY << 16;		}	|	PONARGS		{			$$ = FLAG_PONARGS;		}	;		%%void yyerror (char *s){	fprintf (stderr, "%s\n", s);}

⌨️ 快捷键说明

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