Anarres-Mud-Driver

 view release on metacpan or  search on metacpan

Compiler/parser.y  view on Meta::CPAN


%type <av> function_declarator
%type <av> argument_list arguments
%type <sv> argument
%type <sv> function_prologue

%type <av> variable_declarator variable_declarator_list
%type <av> variable_declarator_init variable_declarator_list_init

%type <str> L_VOID L_BASIC_TYPE
	/* This might point into an SvPV in the type cache. */
%type <str> type_specifier
	/* An SvPV. */
%type <sv> star_list
%type <number> opt_endrange
%type <number> type_modifier_list L_TYPE_MODIFIER

%type <av> class_member_list class_member

%type <number> L_PARAMETER
%type <number> integer L_INTEGER L_HEXINTEGER L_CHARACTER
%type <sv> L_STRING string string_const
%type <sv> L_IDENTIFIER identifier
%type <obj> function_name

%type <assoc> assoc_exp
%type <av> arg_list opt_arg_list opt_arg_list_comma
%type <av> assoc_arg_list opt_assoc_arg_list_comma
%type <av> array mapping

%type <obj> lvalue
%type <av> lvalue_list

%type <obj> block
%type <av> local_decls local_decl

%type <obj> statement
%type <av> statement_list
%type <obj> opt_else

%type <obj> list_exp exp cond_exp logical_exp compare_exp arith_exp
%type <obj> prefix_exp postfix_exp array_exp basic_exp
%type <obj> opt_nv_list_exp nv_list_exp opt_list_exp

%type <obj> closure

%pure_parser
%token_table

%start program

%%

program
		: program definition
		|	/* empty */
	;

definition
		: inheritance
		| global_decl
		| type_decl
		| function
		| prototype
	;

inheritance
		: L_INHERIT string_const ';'
		{
			/* printf("Inheriting %s\n", SvPVX($2)); */
			SvREFCNT_dec(
				yyparse_program_apply(yyparse_param,
						"inherit", &PL_sv_undef, $2));
		}
		| L_INHERIT identifier string_const ';'
		{
			printf("Inheriting %s as %s\n", SvPVX($3), SvPVX($2));
			SvREFCNT_dec(
				yyparse_program_apply(yyparse_param,
						"inherit", $2, $3));
		}
	;

identifier
		: L_IDENTIFIER
		{
			$$ = $1;
		}
	;

function_declarator
		: star_list identifier '(' arguments ')'
		{
			$$ = newAV();
			av_push($$, $1);
			av_push($$, $2);
			av_push($$, newRV_noinc((SV *)($4)));
		}
	;

variable_declarator
		: star_list identifier
		{
			$$ = newAV();
			av_push($$, $1);
			av_push($$, $2);
		}
	;

variable_declarator_list
		: variable_declarator
		{
			$$ = newAV();
			av_push($$, newRV_noinc((SV *)($1)));
		}
		| variable_declarator_list ',' variable_declarator
		{
			$$ = $1;
			av_push($$, newRV_noinc((SV *)($3)));
		}
	;

Compiler/parser.y  view on Meta::CPAN

		| closure
		{
			$$ = N_A1("Closure", $1);
		}
		| identifier
		{
			$$ = N_A1("Variable", $1);
		}
		| L_PARAMETER
		{
			$$ = N_A1("Parameter", newSViv($1));
		}
		| '$' '(' list_exp ')'
		{
			$$ = N_A1("Parameter", $3);
		}
		| '(' list_exp ')'
		{
			$$ = $2;
		}
		| function_name '(' opt_arg_list ')'
		{
			$$ = N_A1R("Funcall", $1, $3);
		}
		| L_SSCANF '(' exp lvalue_list ')'
		{
			$$ = N_A1R("Sscanf", $3, $4);
		}
		| L_CATCH '(' list_exp ')'
		{
			$$ = N_A1("Catch", $3);
		}
		| L_NEW '(' L_CLASS identifier ')'
		{
			$$ = N_A1("New", $4);
		}
		| array_exp L_ARROW identifier '(' opt_arg_list ')'
		{
			$$ = N_A2R("CallOther", $1, $3, $5);
		}
		| array_exp L_ARROW identifier
		{
			$$ = N_A2("Member", $1, $3);
		}
	;

lvalue_list
		:	/* empty */
		{
			$$ = newAV();
		}
		| lvalue_list ',' lvalue
		{
			av_push($1, $3);
			$$ = $1;
		}
	;



global_decl
		: type_modifier_list type_specifier variable_declarator_list ';'
		{
			int		 len;
			int		 i;
			SV		**svp;
			AV		*vdl;
			AV		*vd;
			SV		*name;
			const char		*type;
			SV		*stars;
			SV		*var;

			type = $2;
			vdl = $3;
			len = av_len(vdl);

			for (i = 0; i <= len; i++) {
				svp = av_fetch(vdl, i, FALSE);
				if (!svp) continue;

				/* The AV returned from variable_declarator */
				vd = (AV *)SvRV(*svp);

				/* These two should be guaranteed dereferencable */
				stars = *( av_fetch(vd, 0, FALSE) );
				name = *( av_fetch(vd, 1, FALSE) );
				var = yyparse_variable(name, type, stars, newSViv($1));

				/* XXX Check global modifiers, and possibly make these
				 * variables static. */

				if ($1 & M_STATIC) {
					SvREFCNT_dec(
						yyparse_program_apply(yyparse_param,
										"static", name, var));
				}
				else {
					SvREFCNT_dec(
						yyparse_program_apply(yyparse_param,
										"global", name, var));
				}
			}

			/* See local_decl for memory management notes. */
		}
	;

local_decls
		:	/* empty */
		{
			$$ = newAV();
		}
		| local_decls local_decl
		{
			SV		**svp;
			int		 len;
			int		 i;

			len = av_len($2);
			av_extend($1, av_len($1) + av_len($2) + 1);

			for (i = 0; i <= len; i++) {
				svp = av_fetch($2, i, FALSE);
				if (svp)
					av_push($1, *svp);
				else
					av_push($1, &PL_sv_undef);
			}

			$$ = $1;
		}
	;

local_decl
		: type_specifier variable_declarator_list_init ';'
		{
			int		 len;
			int		 i;
			SV		**svp;
			AV		*vdl;
			AV		*vd;
			SV		*name;
			const char		*type;
			SV		*stars;
			SV		*var;

			$$ = newAV();

			type = $1;
			vdl = $2;
			len = av_len(vdl);

			for (i = 0; i <= len; i++) {
				svp = av_fetch(vdl, i, FALSE);
				if (!svp) continue;

				/* The AV returned from variable_declarator_init */
				vd = (AV *)SvRV(*svp);

				/* These two should be guaranteed dereferencable */



( run in 0.833 second using v1.01-cache-2.11-cpan-ceb78f64989 )