link-grammar-5.8.0/link-grammar/dict-sql/read-sql.c
/* ========================================================= */
/* Mini expression-parsing library.  This is a simplified subset of
 * what can be found in the file-backed dictionary.
 *
 * This does NOT support braces {} used to indicate optional connectors,
 * so using this in the SQL tables is NOT valid! It also does not
 * support cost brackets []. Costs are handled out-of-line.
 *
 * This is not meant to be "just like the text files, but different".
 */
Mini expression-parsing library.  This is a simplified subset of
what can be found in the file-backed dictionary.

This does NOT support braces {} used to indicate optional connectors,
so using this in the SQL tables is NOT valid. It also does not
support cost brackets []. Costs are handled out-of-line.

This is not meant to be "just like the text files, but different".
Mini expression - parsing library . This is a simplified subset of what can be found in the file - backed dictionary . This does NOT support braces {} used to indicate optional connectors so using this in the SQL tables is NOT valid . It also does not support cost brackets [] . Costs are handled out - of - line . This is not meant to be " just like the text files but different " .
static const char * make_expression(Dictionary dict,
                                    const char *exp_str, Exp** pex)
{
	*pex = NULL;
	Exp_type etype = CONNECTOR_type;
	const char * p = exp_str;
	while (*p && (lg_isspace(*p))) p++;
	if (0 == *p) return p;
	if ('(' == *p)
	{
		p = make_expression(dict, ++p, pex);
	}
	else
	{
		const char * con_start = p;
		while (*p && (isalnum(*p) || '*' == *p)) p++;
		assert (('+' == *p) || ('-' == *p),
				"Missing direction character in connector string: %s", con_start);
		Exp* e = Exp_create(dict->Exp_pool);
		e->dir = *p;
		e->type = CONNECTOR_type;
		e->operand_next = NULL;
		e->cost = 0.0;
		char * constr = NULL;
		if ('@' == *con_start)
		{
			constr = strndupa(con_start+1, p-con_start-1);
			e->multi = true;
		}
		else
		{
			constr = strndupa(con_start, p-con_start);
			e->multi = false;
		}
		e->condesc = condesc_add(&dict->contable,
		                           string_set_add(constr, dict->string_set));
		*pex = e;
	}
	p++;
	while (*p && (lg_isspace(*p))) p++;
	if (')' == *p || 0 == *p)
	{
		return p;
	}
	if ('&' == *p)
	{
		etype = AND_type; p++;
	}
	else if ('o' == *p && 'r' == *(p+1))
	{
		etype = OR_type; p+=2;
	}
	else
	{
		assert(false, "Bad rest of expression %s", exp_str);
	}
	Exp* rest = NULL;
	p = make_expression(dict, p, &rest);
	assert(NULL != rest, "Badly formed expression %s", exp_str);
	Exp* join = Exp_create(dict->Exp_pool);
	join->type = etype;
	join->operand_next = NULL;
	join->cost = 0.0;
	join->operand_first = *pex;
	(*pex)->operand_next = rest;
	rest->operand_next = NULL;
	*pex = join;
	return p;
}
static const char * make_expression ( Dictionary dict , const char * exp_str , Exp * * pex ) { * pex = NULL ; Exp_type etype = CONNECTOR_type ; const char * p = exp_str ; while ( * p && ( lg_isspace ( * p ) ) ) p ++ ; if ( 0 == * p ) return p ; if ( ' ' == * p ) { p = make_expression ( dict , ++ p , pex ) ; } else { const char * con_start = p ; while ( * p && ( isalnum ( * p ) || ' ' == * p ) ) p ++ ; assert ( ( ' ' == * p ) || ( ' ' == * p ) , " " , con_start ) ; Exp * e = Exp_create ( dict -> Exp_pool ) ; e -> dir = * p ; e -> type = CONNECTOR_type ; e -> operand_next = NULL ; e -> cost = 0.0 ; char * constr = NULL ; if ( ' ' == * con_start ) { constr = strndupa ( con_start + 1 , p - con_start - 1 ) ; e -> multi = true ; } else { constr = strndupa ( con_start , p - con_start ) ; e -> multi = false ; } e -> condesc = condesc_add ( & dict -> contable , string_set_add ( constr , dict -> string_set ) ) ; * pex = e ; } p ++ ; while ( * p && ( lg_isspace ( * p ) ) ) p ++ ; if ( ' ' == * p || 0 == * p ) { return p ; } if ( ' ' == * p ) { etype = AND_type ; p ++ ; } else if ( ' ' == * p && ' ' == * ( p + 1 ) ) { etype = OR_type ; p += 2 ; } else { assert ( false , " " , exp_str ) ; } Exp * rest = NULL ; p = make_expression ( dict , p , & rest ) ; assert ( NULL != rest , " " , exp_str ) ; Exp * join = Exp_create ( dict -> Exp_pool ) ; join -> type = etype ; join -> operand_next = NULL ; join -> cost = 0.0 ; join -> operand_first = * pex ; ( * pex ) -> operand_next = rest ; rest -> operand_next = NULL ; * pex = join ; return p ; }
Mini expression-parsing library.
Mini expression - parsing library .
/* Search for the start of a connector */ /* If it's an open paren, assume its the beginning of a new list */ /* Search for the end of a connector */ /* Connectors always end with a + or - */ /* Create an expression to hold the connector */ /* Is there any more? If not, return what we've got. */ /* Wait .. there's more! */ /* Join it all together. */