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

📄 jsp_parser.y

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 Y
📖 第 1 页 / 共 3 页
字号:
%start page
%pure_parser
%token PLAIN NL WHITESPACE
%token START_TAG END_TAG
%token START_JSP END_JSP
%token ACTION_START JSP_USEBEAN JSP_SETPROPERTY JSP_GETPROPERTY JSP_INCLUDE JSP_FORWARD JSP_PLUGIN JSP_PARAMS JSP_PARAM JSP_FALLBACK ACTION_END
%token JSP_ID JSP_SCOPE JSP_CLASS JSP_TYPE JSP_BEANNAME
%token JSP_NAME JSP_PROPERTY JSP_PROPERTYPARAM JSP_VALUE JSP_EXPRESSION
%token JSP_PAGE JSP_FLUSH
%token JSP_CODE JSP_CODEBASE JSP_ALIGN JSP_ARCHIVE JSP_HEIGHT JSP_HSPACE JSP_JREVERSION JSP_JNAME JSP_VSPACE JSP_WIDTH JSP_NSPLUGINURL JSP_IEPLUGINURL
%token SCRIPTLET_START SCRIPTLET SCRIPTLET_END
%token DIRECTIVE_START DIR_PAGE DIR_INCLUDE DIR_TAGLIB BOOL STRING NUMBER DIRECTIVE_END
%token DIR_LANGUAGE DIR_EXTENDS DIR_IMPORT DIR_SESSION DIR_BUFFER DIR_AUTOFLUSH DIR_ISTHREADSAFE DIR_INFO DIR_ERRORPAGE DIR_CONTENTTYPE DIR_ISERRORPAGE
%token DIR_PREFIX DIR_URI
%token DIR_INCFILE
%token PUSH_INCLUDE POP_INCLUDE
%token DECLARATION_START DECLARATION DECLARATION_END
%token EXPRESSION_START EXPRESSION EXPRESSION_END
%token COMMENT_START COMMENT COMMENT_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/Servlet/JspParser/jsp_parser.y,v $
 * $Date: 2003/05/13 18:42:19 $
 *
 Description:
\*____________________________________________________________________________*/

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

#define DIRECTIVE_HDR(name, detail) if (PG->pass) fprintf( PG->out, "\n\t\t\t/**\n\t\t\t* Embedded Directive '%s' %s\n", name, detail)
#define DIRATTR_HDR() if (PG->pass) fprintf( PG->out, "\t\t\t* %s = ", (char *)pi3lval)

#define JSPACTION_HDR(name, detail) if (PG->pass) fprintf( PG->out, "\n\t\t\t/**\n\t\t\t* Embedded Action '%s' %s\n\t\t\t**/\n", name, detail)
//#define JSPATTR_HDR() if (PG->pass) fprintf( PG->out, "\t\t\t* %s = ", (char *)pi3lval)

#define YYERROR_VERBOSE
#define MAX_ERROR_COUNT 10
%}

%%
page :
		|	part
		;

part :		part part
		|	txt
		|	START_TAG tag END_TAG
		|	START_JSP jsp END_JSP
		|	error
			{
			if (pi3nerrs < MAX_ERROR_COUNT)
				{
				if (PG->pass) 
					{
					fprintf( PG->out, "/* >>>>> PARSE ERROR near token '%s', line %d <<<<< */\n", (char *)pi3lval, get_lineno(pp));
					}
				else
					{
					fprintf( stderr, "PARSE ERROR near token '%s', line %d\n", (char *)pi3lval, get_lineno(pp));
					};

				yyerrok; yyclearin;
				}
			else
				{
				fprintf( stderr, "Giving up due to too much errors (%d).\n", pi3nerrs);
				YYABORT;
				};
			}
		;

tag :		commt
		|	script
		|	decl
		|	expr
		|	dir
		;

txt :		PLAIN
			{
			if (PG->pass)
				{
				pi3write_plain( PG, (const char *)pi3lval );
				}
			}
		|	NL
			{
			if (PG->pass) fprintf( PG->out, "\t\t\tout.newLine();\n");
			}
		;

jsp :		usebean
		|	setprop
		|	getprop
		|	include
		|	forward
		|	plugin

usebean :	usebean_start usebean_text jsp_end
		|	usebean part
		;

setprop :	setprop_start setprop_text jsp_end
		;

getprop :	getprop_start getprop_text jsp_end
		;

include :	include_start include_text jsp_end
		;

forward :	forward_start forward_text jsp_end
		;

plugin :	plugin_start plugin_text jsp_end
		|	plugin plugin_body
		;

plugin_body : params
		|	fallback
		|	params fallback
		;

params :	params_start params_body jsp_end
		;

params_body : param_start param_text jsp_end
		|	params_body params_body
		;

fallback :	fallback_start PLAIN jsp_end
		;

commt :		cmt_start cmt_text cmt_end
		|	cmt_start cmt_end
		;

cmt_start : COMMENT_START
			{
			if (PG->pass) fprintf( PG->out, "\t\t\t\n\t\t\t/**\n\t\t\t");
			}
		;

cmt_end :	COMMENT_END
			{
			if (PG->pass) fprintf( PG->out, "\n\t\t\t**/\n");
			}
		;

cmt_text :	COMMENT
			{
			if (PG->pass) fprintf( PG->out, "%s", (char *)pi3lval);
			}
		|	WHITESPACE
			{
			if (PG->pass)
				{
				fprintf( PG->out, "%s", (char *)pi3lval);
				if ((((char *)pi3lval)[0]==13) || (((char *)pi3lval)[0]==10))
					fprintf( PG->out, "\t\t\t");
				};
			}
		|	cmt_text cmt_text
		;

script :	scr_start scr_text scr_end
		|	scr_start scr_end
		;

scr_start :	SCRIPTLET_START
			{
			if (PG->pass) fprintf( PG->out, "\n\t\t\t/**\n\t\t\t* Embedded Scriptlet\n\t\t\t**/\n\t\t\t");
			}
		;

scr_end :	SCRIPTLET_END
			{
			if (PG->pass) fprintf( PG->out, "\n\n");
			}
		;

scr_text :	SCRIPTLET
			{
			if (PG->pass) fprintf( PG->out, "%s", (char *)pi3lval);
			}
		|	WHITESPACE
			{
			if (PG->pass)
				{
				fprintf( PG->out, "%s", (char *)pi3lval);
				if ((((char *)pi3lval)[0]==13) || (((char *)pi3lval)[0]==10))
					fprintf( PG->out, "\t\t\t");
				};
			}
		|	scr_text scr_text
		;

decl :		dec_start dec_text dec_end
		|	dec_start dec_end
		;

dec_start :	DECLARATION_START
			{
			if (PG->pass) fprintf( PG->out, "\n\t\t\t/**\n\t\t\t* Embedded Declaration\n\t\t\t**/\n\t\t\t");
			}
		;

dec_end :	DECLARATION_END
			{
			if (PG->pass) fprintf( PG->out, "\n\n");
			}
		;

dec_text :	DECLARATION
			{
			if (PG->pass) fprintf( PG->out, "%s", (char *)pi3lval);
			}
		|	WHITESPACE
			{
			if (PG->pass)
				{
				fprintf( PG->out, "%s", (char *)pi3lval);
				if ((((char *)pi3lval)[0]==13) || (((char *)pi3lval)[0]==10))
					fprintf( PG->out, "\t\t\t");
				};
			}
		|	dec_text dec_text
		;

expr :		exp_start exp_text exp_end
		|	exp_start exp_end
		;

exp_start :	EXPRESSION_START
			{
			if (PG->pass) fprintf( PG->out, "\n\t\t\t/**\n\t\t\t* Embedded Expression\n\t\t\t**/\n");
			if (PG->pass) fprintf( PG->out, "\t\t\tout.print(");
			}
		;

exp_end	:	EXPRESSION_END
			{
			if (PG->pass) fprintf( PG->out, ");\n\n");
			}
		;

exp_text :	EXPRESSION
			{
			if (PG->pass) fprintf( PG->out, "%s", (char *)pi3lval);
			}
		|	WHITESPACE
			{
			if (PG->pass)
				{
				fprintf( PG->out, "%s", (char *)pi3lval);
				if ((((char *)pi3lval)[0]==13) || (((char *)pi3lval)[0]==10))
					fprintf( PG->out, "\t\t\t");
				};
			}
		|	exp_text exp_text
		;

dir :		page_start page_text dir_end
		|	incl_start incl_text dir_end
		|	tagl_start tagl_text dir_end
		;

page_start : DIRECTIVE_START DIR_PAGE
			{
			DIRECTIVE_HDR((char *)$2, "");
			PG->directive = DIR_PAGE;
			}
		;

incl_start : DIRECTIVE_START DIR_INCLUDE
			{
			DIRECTIVE_HDR((char *)$2, "");
			PG->directive = DIR_INCLUDE;
			}
		;

tagl_start : DIRECTIVE_START DIR_TAGLIB
			{
			DIRECTIVE_HDR((char *)$2, "(unsupported)");
			PG->directive = DIR_TAGLIB;
			}
		;

dir_end	:	DIRECTIVE_END
			{
			if (PG->pass) fprintf( PG->out, "\t\t\t**/\n\n");
			}
		;

page_text :	page_attr '=' '"' page_value '"'
			{
			if (PG->pass && (PG->dir_attribute != DIR_IMPORT))
				{
				if (!PG->page_attribs[PG->dir_attribute - DIR_LANGUAGE])
					{
					++PG->page_attribs[PG->dir_attribute - DIR_LANGUAGE];
					}
				else
					{
					fprintf( PG->out, "\n/**\n* ERROR: Multiple definitions of attribute '%s' found in page directive.\n**/\n", (char *)$1);
					YYABORT;							
					};
				};
			}
		|	WHITESPACE
		|	page_text page_text
		;

incl_text :	incl_attr '=' '"' push_inc page pop_inc '"'
		|	incl_attr '=' '"' incl_err '"'
		|	WHITESPACE
		|	incl_text incl_text
		;

incl_err :	ERROR_INCLUDES_TOO_DEEPLY
			{
			fprintf( stderr, "\n/*\n* ERROR: Includes nested to deeply for file: %s. \
Maximum depth is %d.\n**/\n", (char *)$1, MAX_IMPORT_DEPTH);
			YYABORT;
			}

		|	ERROR_CANT_OPEN_INCLUDE
			{
			fprintf( stderr, "\n/**\n* ERROR: Can't open include file: %s.\n**/\n", (char *)$1);
			YYABORT;
			}
		;

tagl_text :	tagl_attr '=' '"' tagl_value '"'
		|	WHITESPACE
		|	tagl_text tagl_text
		;

page_attr : DIR_LANGUAGE
			{
			DIRATTR_HDR();
			PG->dir_attribute = DIR_LANGUAGE;
			}
		|	DIR_EXTENDS
			{
			DIRATTR_HDR();
			PG->dir_attribute = DIR_EXTENDS;
			}
		|	DIR_IMPORT
			{
			DIRATTR_HDR();
			PG->dir_attribute = DIR_IMPORT;
			}
		|	DIR_SESSION
			{
			DIRATTR_HDR();
			PG->dir_attribute = DIR_SESSION;
			}
		|	DIR_BUFFER
			{
			DIRATTR_HDR();
			PG->dir_attribute = DIR_BUFFER;
			}
		|	DIR_AUTOFLUSH
			{
			DIRATTR_HDR();
			PG->dir_attribute = DIR_AUTOFLUSH;
			}
		|	DIR_ISTHREADSAFE
			{
			DIRATTR_HDR();
			PG->dir_attribute = DIR_ISTHREADSAFE;
			}
		|	DIR_INFO
			{
			DIRATTR_HDR();
			PG->dir_attribute = DIR_INFO;
			}
		|	DIR_ERRORPAGE
			{
			DIRATTR_HDR();
			PG->dir_attribute = DIR_ERRORPAGE;
			}
		|	DIR_CONTENTTYPE
			{
			DIRATTR_HDR();
			PG->dir_attribute = DIR_CONTENTTYPE;
			}
		|	DIR_ISERRORPAGE
			{
			DIRATTR_HDR();
			PG->dir_attribute = DIR_ISERRORPAGE;
			}
		;

⌨️ 快捷键说明

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