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

📄 psp_parser.y

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 Y
字号:
%start page
%pure_parser
%token PLAIN NL WHITESPACE SHEBANG
%token START_TAG END_TAG
%token SCRIPTLET_START SCRIPTLET SCRIPTLET_END
%token DIRECTIVE_START DIR_PAGE DIR_INCLUDE DIRECTIVE_END
%token DIR_INCFILE
%token DIR_PARSLEN BOOL
%token PUSH_INCLUDE POP_INCLUDE
%token EXPRESSION_START EXPRESSION EXPRESSION_END
%token ERROR_INCLUDES_TOO_DEEPLY ERROR_CANT_OPEN_INCLUDE

%{
/*____________________________________________________________________________*\
 *

 Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.

 These sources, libraries and applications are
 FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
 as long as the following conditions are adhered to.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:

 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer. 

 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.

 3. The name of the author may not be used to endorse or promote products
    derived from this software without specific prior written permission. 

 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE AUTHORS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 OF THE POSSIBILITY OF SUCH DAMAGE.

 *____________________________________________________________________________*|
 *
 * $Source: /cvsroot/pi3web/Pi3Web_200/Source/Pi3Perl/PspParser/psp_parser.y,v $
 * $Date: 2003/05/13 18:42:12 $
 *
 Description:
\*____________________________________________________________________________*/

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <assert.h>
#include "psp_scanner.h"

#define YYERROR_VERBOSE
#define MAX_ERROR_COUNT 10
%}

%%
page :
		|	part
		;

part :		part part
		|	txt
			{
			cb_plain(PG, (char *)$1);
			}
		|	SHEBANG PLAIN NL
			{
			cb_shebang(PG, (char *)$1);
			}
		|	START_TAG tag END_TAG
		|	error
			{
			if (pi3nerrs < MAX_ERROR_COUNT)
				{
				sprintf( PG->msgbuf, "PARSE ERROR near token '%s', line %d\n", (char *)pi3lval, get_lineno(pp));
				if ( cb_error(PG, PG->msgbuf) )
					{
					YYABORT;
					};
				yyerrok; yyclearin;
				}
			else
				{
				sprintf( PG->msgbuf, "Giving up due to too much errors (%d).\n", pi3nerrs);
				cb_error(PG, PG->msgbuf);
				YYABORT;
				};
			}
		;

tag :		script
		|	expr
		|	dir
		;

txt :		PLAIN
		|	NL
		;

script :	SCRIPTLET_START scr_text SCRIPTLET_END
			{
			cb_scriptlet(PG, (char *)$2);
			}
		|	SCRIPTLET_START SCRIPTLET_END
		;

scr_text :	SCRIPTLET
		|	WHITESPACE
		|	scr_text scr_text
		;

expr :		EXPRESSION_START exp_text EXPRESSION_END
			{
			cb_expression(PG, (char *)$2);
			}
		|	EXPRESSION_START EXPRESSION_END
		;

exp_text :	EXPRESSION
		|	WHITESPACE
		|	exp_text exp_text
		;

dir :		DIRECTIVE_START DIR_INCLUDE WHITESPACE incl_text DIRECTIVE_END
		|	DIRECTIVE_START DIR_PAGE WHITESPACE page_text DIRECTIVE_END
		;

incl_text :	DIR_INCFILE '=' '"' PUSH_INCLUDE page POP_INCLUDE '"'
		|	DIR_INCFILE '=' '"' incl_err '"'
		;

page_text :	DIR_PARSLEN '=' '"' BOOL '"'
			{
			cb_parsedlen(PG, (int)$4);
			}
		;

incl_err :	ERROR_INCLUDES_TOO_DEEPLY
			{
			sprintf( PG->msgbuf, "Includes nested to deeply for file: %s. \
Maximum depth is %d.", (char *)$1, MAX_IMPORT_DEPTH);
			cb_error(PG, PG->msgbuf);
			YYABORT;
			}

		|	ERROR_CANT_OPEN_INCLUDE
			{
			sprintf( PG->msgbuf, "Can't open include file: %s.", (char *)$1);
			cb_error(PG, PG->msgbuf);
			YYABORT;
			}
		;
%%

⌨️ 快捷键说明

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