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

📄 wsgram.y

📁 The Kannel Open Source WAP and SMS gateway works as both an SMS gateway, for implementing keyword b
💻 Y
📖 第 1 页 / 共 2 页
字号:
%{/* * * wsgram.y * * Author: Markku Rossi <mtr@iki.fi> * * Copyright (c) 1999-2000 WAPIT OY LTD. *		 All rights reserved. * * Bison grammar for the WMLScript compiler. * */#include "wmlscript/wsint.h"#define YYPARSE_PARAM	pctx#define YYLEX_PARAM	pctx/* The required yyerror() function.  This is actually not used but to   report the internal parser errors.  All other errors are reported   by using the `wserror.h' functions. */extern void yyerror(char *msg);#if WS_DEBUG/* Just for debugging purposes. */WsCompilerPtr global_compiler = NULL;#endif /* WS_DEBUG */%}/* The possible semantic values. */%union{    WsUInt32 integer;    WsFloat vfloat;    char *identifier;    WsUtf8String *string;    WsBool boolean;    WsList *list;    WsFormalParm *parm;    WsVarDec *vardec;    WsPragmaMetaBody *meta_body;    WsStatement *stmt;    WsExpression *expr;}/* Tokens. *//* Language literals. */%token tINVALID tTRUE tFALSE tINTEGER tFLOAT tSTRING/* Identifier. */%token tIDENTIFIER/* Keywords. */%token tACCESS tAGENT tBREAK tCONTINUE tIDIV tIDIVA tDOMAIN tELSE tEQUIV%token tEXTERN tFOR tFUNCTION tHEADER tHTTP tIF tISVALID tMETA tNAME tPATH%token tRETURN tTYPEOF tUSE tUSER tVAR tWHILE tURL/* Keywords not used by WMLScript */%token tDELETE tIN tLIB tNEW tNULL tTHIS tVOID tWITH/* Future reserved keywords. */%token tCASE tCATCH tCLASS tCONST tDEBUGGER tDEFAULT tDO tENUM tEXPORT%token tEXTENDS tFINALLY tIMPORT tPRIVATE tPUBLIC tSIZEOF tSTRUCT tSUPER%token tSWITCH tTHROW tTRY/* Punctuation. */%token tEQ tLE tGE tNE tAND tOR tPLUSPLUS tMINUSMINUS%token tLSHIFT tRSSHIFT tRSZSHIFT tADDA tSUBA tMULA tDIVA tANDA tORA tXORA%token tREMA tLSHIFTA tRSSHIFTA tRSZSHIFTA/* Assign semantic values to tokens and non-terminals. */%type <integer> tINTEGER%type <vfloat> tFLOAT%type <string> tSTRING%type <identifier> tIDENTIFIER%type <string> MetaPropertyName MetaContent MetaScheme%type <meta_body> MetaBody%type <boolean> ExternOpt%type <list> FormalParameterListOpt FormalParameterList%type <list> StatementListOpt StatementList%type <list> Block Arguments ArgumentList VariableDeclarationList%type <vardec> VariableDeclaration%type <stmt> Statement ReturnStatement VariableStatement IfStatement%type <stmt> IterationStatement ForStatement%type <expr> ExpressionOpt Expression AssignmentExpression%type <expr> ConditionalExpression LogicalORExpression%type <expr> LogicalANDExpression BitwiseORExpression%type <expr> BitwiseXORExpression BitwiseANDExpression%type <expr> EqualityExpression RelationalExpression ShiftExpression%type <expr> AdditiveExpression MultiplicativeExpression UnaryExpression%type <expr> PostfixExpression CallExpression PrimaryExpression%type <expr> VariableInitializedOpt/* Options for bison. *//* Generate reentrant parser. */%pure_parser/* This grammar has one shift-reduce conflict.  It comes from the   if-else statement. */%expect 1%%/* A compilation unit. */CompilationUnit:	  Pragmas FunctionDeclarations	| FunctionDeclarations	| error		{ ws_error_syntax(pctx, @1.first_line); }	;/* Pragmas. */Pragmas:	  Pragma	| Pragmas Pragma	;Pragma:	  tUSE PragmaDeclaration ';'	| error		{ ws_error_syntax(pctx, @1.first_line); }	;PragmaDeclaration:	  ExternalCompilationUnitPragma	| AccessControlPragma	| MetaPragma	;ExternalCompilationUnitPragma:	  tURL tIDENTIFIER tSTRING	  	{ ws_pragma_use(pctx, @2.first_line, $2, $3); }	;AccessControlPragma:	  tACCESS AccessControlSpecifier	;AccessControlSpecifier:	  tDOMAIN tSTRING	  	{		    WsCompiler *compiler = (WsCompiler *) pctx;		    /* Pass this to the byte-code */		    if (!ws_bc_add_pragma_access_domain(compiler->bc, $2->data,						        $2->len))		        ws_error_memory(pctx);		    ws_lexer_free_utf8(compiler, $2);		}	| tPATH tSTRING	  	{		    WsCompiler *compiler = (WsCompiler *) pctx;		    /* Pass this to the byte-code */		    if (!ws_bc_add_pragma_access_path(compiler->bc, $2->data,						      $2->len))		        ws_error_memory(pctx);		    ws_lexer_free_utf8(compiler, $2);		}	| tDOMAIN tSTRING tPATH tSTRING	  	{		    WsCompiler *compiler = (WsCompiler *) pctx;		    WsBool success = WS_TRUE;		    /* Pass these to the byte-code */		    if (!ws_bc_add_pragma_access_domain(compiler->bc, $2->data,						        $2->len))		        success = WS_FALSE;		    if (!ws_bc_add_pragma_access_path(compiler->bc, $4->data,						      $4->len))		        success = WS_FALSE;		    if (!success)		        ws_error_memory(pctx);		    ws_lexer_free_utf8(compiler, $2);		    ws_lexer_free_utf8(compiler, $4);		}	;MetaPragma:	  tMETA MetaSpecifier	;MetaSpecifier:	  MetaName	| MetaHttpEquiv	| MetaUserAgent	;MetaName:	  tNAME MetaBody		{		    WsCompiler *compiler = (WsCompiler *) pctx;		    /* Meta information for the origin servers.  Show it                     * to the user if requested. */		    if (compiler->params.meta_name_cb)		        (*compiler->params.meta_name_cb)(					$2->property_name, $2->content,					$2->scheme,					compiler->params.meta_name_cb_context);		    /* We do not need the MetaBody anymore. */		    ws_pragma_meta_body_free(compiler, $2);		}	;MetaHttpEquiv:	  tHTTP tEQUIV MetaBody	  	{		    WsCompiler *compiler = (WsCompiler *) pctx;		    /* Meta information HTTP header that should be                     * included to an HTTP response header.  Show it to                     * the user if requested. */		    if (compiler->params.meta_http_equiv_cb)		        (*compiler->params.meta_http_equiv_cb)(				$3->property_name,				$3->content,				$3->scheme,				compiler->params.meta_http_equiv_cb_context);		    /* We do not need the MetaBody anymore. */		    ws_pragma_meta_body_free(compiler, $3);		}	;MetaUserAgent:	  tUSER tAGENT MetaBody		{		    WsBool success;		    WsCompiler *compiler = (WsCompiler *) pctx;		    /* Pass this pragma to the byte-code */		    if ($3) {		        if ($3->scheme)		  	    success			  = ws_bc_add_pragma_user_agent_property_and_scheme(						compiler->bc,						$3->property_name->data,						$3->property_name->len,						$3->content->data,						$3->content->len,						$3->scheme->data,						$3->scheme->len);		        else		  	    success = ws_bc_add_pragma_user_agent_property(						compiler->bc,						$3->property_name->data,						$3->property_name->len,						$3->content->data,						$3->content->len);		        /* Free the MetaBody. */		        ws_pragma_meta_body_free(compiler, $3);		        if (!success)		  	    ws_error_memory(pctx);		    }		}	;MetaBody:	  MetaPropertyName MetaContent		{ $$ = ws_pragma_meta_body(pctx, $1, $2, NULL); }	| MetaPropertyName MetaContent MetaScheme		{ $$ = ws_pragma_meta_body(pctx, $1, $2, $3); }	;MetaPropertyName: tSTRING;MetaContent: tSTRING;MetaScheme: tSTRING;/* Function declarations. */FunctionDeclarations:	  FunctionDeclaration	| FunctionDeclarations FunctionDeclaration	;FunctionDeclaration:	  ExternOpt tFUNCTION tIDENTIFIER '(' FormalParameterListOpt ')' Block	  SemicolonOpt		{		    char *name = ws_strdup($3);		    ws_lexer_free_block(pctx, $3);		    if (name)		        ws_function(pctx, $1, name, @3.first_line, $5, $7);		    else		        ws_error_memory(pctx);		}	;ExternOpt:	  /* empty */	{ $$ = WS_FALSE; }	| tEXTERN	{ $$ = WS_TRUE;  }	;FormalParameterListOpt:	  /* empty */		{ $$ = ws_list_new(pctx); }	| FormalParameterList	;SemicolonOpt:	  /* empty */	| ';'	;FormalParameterList:	  tIDENTIFIER		{                    char *id;                    WsFormalParm *parm;		    id = ws_f_strdup(((WsCompiler *) pctx)->pool_stree, $1);                    parm = ws_formal_parameter(pctx, @1.first_line, id);		    ws_lexer_free_block(pctx, $1);		    if (id == NULL || parm == NULL) {		        ws_error_memory(pctx);		        $$ = NULL;		    } else {		        $$ = ws_list_new(pctx);		        ws_list_append(pctx, $$, parm);		    }		}	| FormalParameterList ',' tIDENTIFIER		{                    char *id;                    WsFormalParm *parm;		    id = ws_f_strdup(((WsCompiler *) pctx)->pool_stree, $3);                    parm = ws_formal_parameter(pctx, @1.first_line, id);		    ws_lexer_free_block(pctx, $3);		    if (id == NULL || parm == NULL) {		        ws_error_memory(pctx);		        $$ = NULL;		    } else

⌨️ 快捷键说明

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