예제 #1
0
파일: workspace.c 프로젝트: imclab/nip2
/* Make up a new definition.
 */
Symbol *
workspace_add_def( Workspace *ws, const char *str )
{
	Column *col = workspace_column_pick( ws );
	Symbol *sym;
	char *name;

#ifdef DEBUG
	printf( "workspace_add_def: %s\n", str );
#endif /*DEBUG*/

        if( !str || strspn( str, WHITESPACE ) == strlen( str ) )
		return( NULL );

	/* Try parsing as a "fred = 12" style def. 
	 */
	attach_input_string( str );
	if( (name = parse_test_define()) ) {
		sym = symbol_new( ws->sym->expr->compile, name );
		IM_FREE( name );
		attach_input_string( str + 
			IM_CLIP( 0, input_state.charpos - 1, strlen( str ) ) );
	}
	else {
		/* That didn't work. Make a sym from the col name.
		 */
		sym = workspace_add_symbol( ws );
		attach_input_string( str );
	}

	if( !symbol_user_init( sym ) || 
		!parse_rhs( sym->expr, PARSE_RHS ) ) {
		/* Another parse error.
		 */
		expr_error_get( sym->expr );

		/* Block changes to error_string ... symbol_destroy() 
		 * can set this for compound objects.
		 */
		error_block();
		IDESTROY( sym );
		error_unblock();

		return( NULL );
	}

	/* If we're redefining a sym, it might have a row already.
	 */
	if( !sym->expr->row )
		(void) row_new( col->scol, sym, &sym->expr->root );
	symbol_made( sym );
	workspace_set_modified( ws, TRUE );

	return( sym );
}
예제 #2
0
        static bool call_rule_definition(
            RHS const& rhs
          , char const* rule_name
          , Iterator& first, Iterator const& last
          , Context const& context, ActualAttribute& attr
          , ExplicitAttrPropagation)
        {
            boost::ignore_unused(rule_name);

            typedef traits::make_attribute<Attribute, ActualAttribute> make_attribute;

            // do down-stream transformation, provides attribute for
            // rhs parser
            typedef traits::transform_attribute<
                typename make_attribute::type, Attribute, parser_id>
            transform;

            typedef typename make_attribute::value_type value_type;
            typedef typename transform::type transform_attr;
            value_type made_attr = make_attribute::call(attr);
            transform_attr attr_ = transform::pre(made_attr);

            bool ok_parse
              //Creates a place to hold the result of parse_rhs
              //called inside the following scope.
              ;
            {
             // Create a scope to cause the dbg variable below (within
             // the #if...#endif) to call it's DTOR before any
             // modifications are made to the attribute, attr_ passed
             // to parse_rhs (such as might be done in
             // traits::post_transform when, for example,
             // ActualAttribute is a recursive variant).
#if defined(BOOST_SPIRIT_X3_DEBUG)
                context_debug<Iterator, transform_attr>
                dbg(rule_name, first, last, attr_, ok_parse);
#endif
                ok_parse = parse_rhs(rhs, first, last, context, attr_, attr_
                   , mpl::bool_
                     < (  RHS::has_action
                       && !ExplicitAttrPropagation::value
                       )
                     >()
                  );
            }
            if (ok_parse)
            {
                // do up-stream transformation, this integrates the results
                // back into the original attribute value, if appropriate
                traits::post_transform(attr, std::forward<transform_attr>(attr_));
            }
            return ok_parse;
        }
예제 #3
0
static expr *parse_rhs(expr *lhs, int priority)
{
	for(;;){
    int this_pri, next_pri;
		e_op op;
		expr *rhs;

		op = tok_cur;
		if(!is_op(op))
			return lhs; /* eof, rparen and colon covered here */

		this_pri = PRECEDENCE(op);
    if(this_pri > priority)
      return lhs;

		/* eat the op */
		tok_next();

		/* special case for ternary */
		if(op == tok_question){
			expr *if_t = parse();

			if(tok_cur != tok_colon)
				CPP_DIE("colon expected for ternary-? operator");
			tok_next();

			rhs = parse();

			lhs = expr_new_top(lhs, if_t, rhs);
		}else{
			rhs = parse_primary();

			/* now on the next op, or eof (in which case, precedence returns -1 */
			next_pri = PRECEDENCE(tok_cur);
			if(next_pri < this_pri) {
				/* next is tighter, give it our rhs as its lhs */
				rhs = parse_rhs(rhs, next_pri);
			}

			lhs = expr_op(op, lhs, rhs);
		}
  }
}
예제 #4
0
파일: win_math.c 프로젝트: timburrow/ovj3
/************************************************************************
*                                                                       *
*  Process the Image Math string "cmd".
*  (STATIC)								*
*									*/
void
Win_math::exec_string(char *cmd)
{
    int i;
    int n;
    int err = FALSE;
    char *pc;

    // The following get pointed to mallocated memory
    ParmList dst_frames = NULL;
    ParmList dst_ddls = NULL;
    ParmList src_ddls = NULL;
    ParmList src_ddl_vecs = NULL;
    ParmList src_strings = NULL;
    ParmList src_constants = NULL;
    ParmList parmtree = NULL;
    char *exec_path = NULL;

    win_print_msg("Math: Parsing...");

    /* Change New-Lines to Spaces */
    while (pc=strchr(cmd, '\n')){
	*pc = ' ';
    }

    /* Parse the left hand side */
    int nout = parse_lhs(cmd, &dst_frames);
    if (!nout){
	err = TRUE;
    }
    /*printParm(dst_frames);/*CMP*/

    /* Parse images on right hand side */
    int nin = parse_rhs(cmd, &src_ddls, &src_ddl_vecs,
			&src_strings, &src_constants);
    if (!nin){
	err = TRUE;
    }
    /*printParm(src_ddls);/*CMP*/
    /*printParm(src_strings);/*CMP*/

    /* Get the executable, compiling if necessary */
    if (!err){
	win_print_msg("Math: Compiling program...");
	if (!(exec_path = get_program(cmd))){
	    err = TRUE;
	}
    }
    /*fprintf(stderr,"exec_path=%s\n", exec_path);/*CMP*/

    /* Execute the program */
    parmtree = allocParm("parmtree", PL_PARM, 5);
    setParmParm(parmtree, src_ddls, 0);
    setParmParm(parmtree, dst_frames, 1);
    setParmParm(parmtree, src_strings, 2);
    setParmParm(parmtree, src_constants, 3);
    setParmParm(parmtree, src_ddl_vecs, 4);
    /*printParm(parmtree);/*CMP*/
    if (!err){
	win_print_msg("Math: Executing program...");
	if (!exec_program(exec_path, parmtree, &dst_ddls)){
	    err = TRUE;
	}
    }

    /* Display the results */
    /*printParm(dst_ddls);/*CMP*/
    void *vst;
    int frame;
    Gframe *gf;
    n = countParm(dst_ddls);
    for (i=0; i<n; i++){
	getPtrParm(dst_ddls, &vst, i);
	DDLSymbolTable *st = (DDLSymbolTable *)vst;
	getIntParm(dst_frames, &frame, i);
	/*fprintf(stderr,"st=0x%x, frame=%d\n", st, frame);/*CMP*/
	if (st && frame){
	    char *fname;
	    st->GetValue("filename", fname);
	    char *newname = (char *)malloc(strlen(fname) + 20);
	    sprintf(newname,"%s-mathout#%d", fname, i+1);
	    st->SetValue("filename", newname);
	    free(newname);
	    gf = Gframe::get_frame_by_number(frame);
	    int display_data = TRUE;
	    int math_result = TRUE;
	    Frame_data::load_ddl_data(gf, NULL, NULL, &display_data, TRUE,
				      (DDLSymbolTable *)st, math_result);
	}
    }

    /* Free memory */
    free(parmtree);		// Also frees params under it
    free(dst_ddls);

    win_print_msg("Math: Done.");
}
예제 #5
0
static expr *parse(void)
{
  return parse_rhs(parse_primary(), MAX_PRI);
}