Soar Kernel  9.3.2 08-06-12
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Typedefs | Functions
parser.h File Reference

Go to the source code of this file.

Typedefs

typedef struct action_struct action
typedef struct agent_struct agent
typedef char Bool
typedef struct condition_struct condition
typedef union symbol_union Symbol
typedef char * test

Functions

void init_parser (void)
Symbolmake_symbol_for_current_lexeme (agent *thisAgent, bool allow_lti)
conditionparse_lhs (agent *thisAgent)
bool parse_lti (agent *thisAgent)
struct production_structparse_production (agent *thisAgent, unsigned char *rete_addition_result)
Bool parse_rhs (agent *thisAgent, action **dest_rhs)

Typedef Documentation

typedef struct action_struct action

Definition at line 30 of file parser.h.

typedef struct agent_struct agent

Definition at line 31 of file parser.h.

typedef char Bool

Definition at line 27 of file parser.h.

typedef struct condition_struct condition

Definition at line 29 of file parser.h.

typedef union symbol_union Symbol

Definition at line 32 of file parser.h.

typedef char* test

Definition at line 28 of file parser.h.

Function Documentation

void init_parser ( void  )
Symbol* make_symbol_for_current_lexeme ( agent thisAgent,
bool  allow_lti 
)

Definition at line 257 of file parser.cpp.

References abort_with_fatal_error(), BUFFER_MSG_SIZE, FLOAT_CONSTANT_LEXEME, lexeme_info::float_val, lexeme_info::id_letter, lexeme_info::id_number, IDENTIFIER_LEXEME, INT_CONSTANT_LEXEME, lexeme_info::int_val, agent_struct::lexeme, make_float_constant(), make_int_constant(), make_sym_constant(), make_variable(), NIL, smem_lti_get_id(), smem_lti_soar_make(), SMEM_LTI_UNKNOWN_LEVEL, lexeme_info::string, SYM_CONSTANT_LEXEME, lexeme_info::type, and VARIABLE_LEXEME.

Referenced by parse_disjunction_test(), parse_relational_test(), and parse_rhs_value().

{
switch (thisAgent->lexeme.type) {
case SYM_CONSTANT_LEXEME: return make_sym_constant (thisAgent, thisAgent->lexeme.string);
case VARIABLE_LEXEME: return make_variable (thisAgent, thisAgent->lexeme.string);
case INT_CONSTANT_LEXEME: return make_int_constant (thisAgent, thisAgent->lexeme.int_val);
case FLOAT_CONSTANT_LEXEME: return make_float_constant (thisAgent, thisAgent->lexeme.float_val);
if (!allow_lti) {
char msg[BUFFER_MSG_SIZE];
strncpy(msg, "parser.c: Internal error: ID found in make_symbol_for_current_lexeme\n", BUFFER_MSG_SIZE);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
else {
smem_lti_id lti_id = smem_lti_get_id( thisAgent, thisAgent->lexeme.id_letter, thisAgent->lexeme.id_number );
if ( lti_id == NIL ) {
char msg[BUFFER_MSG_SIZE];
strncpy(msg, "parser.c: Internal error: invalid long-term identifier found in make_symbol_for_current_lexeme\n", BUFFER_MSG_SIZE);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
else {
return smem_lti_soar_make( thisAgent, lti_id, thisAgent->lexeme.id_letter, thisAgent->lexeme.id_number, SMEM_LTI_UNKNOWN_LEVEL );
}
}
break;
default:
{ char msg[BUFFER_MSG_SIZE];
SNPRINTF(msg, BUFFER_MSG_SIZE, "parser.c: Internal error: bad lexeme type in make_symbol_for_current_lexeme\n, thisAgent->lexeme.string=%s\n", thisAgent->lexeme.string);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
}
return NIL; /* unreachable, but without it, gcc -Wall warns here */
}
condition* parse_lhs ( agent thisAgent)

Definition at line 1050 of file parser.cpp.

References NIL, and parse_cond_plus().

Referenced by parse_production().

{
c = parse_cond_plus (thisAgent);
if (!c) return NIL;
return c;
}
bool parse_lti ( agent thisAgent)

Definition at line 1791 of file parser.cpp.

References AT_LEXEME, get_lexeme(), get_lexer_allow_ids(), agent_struct::lexeme, set_lexer_allow_ids(), and lexeme_info::type.

Referenced by parse_relational_test(), parse_rhs_action(), and parse_rhs_value().

{
switch(thisAgent->lexeme.type) {
case AT_LEXEME:
{
Bool saved = get_lexer_allow_ids(thisAgent);
set_lexer_allow_ids(thisAgent, true);
get_lexeme(thisAgent);
set_lexer_allow_ids(thisAgent, saved);
}
return true;
default:
break;
}
return false;
}
struct production_struct* parse_production ( agent thisAgent,
unsigned char *  rete_addition_result 
)
read

Definition at line 1878 of file parser.cpp.

References add_production_to_rete(), CHUNK_PRODUCTION_TYPE, deallocate_action_list(), deallocate_condition_list(), DECLARED_I_SUPPORT, DECLARED_O_SUPPORT, production_struct::declared_support, DEFAULT_PRODUCTION_TYPE, destructively_reverse_action_list(), production_struct::documentation, DUPLICATE_PRODUCTION, excise_production(), FALSE, free_memory_block_for_string(), get_lexeme(), production_struct::interrupt, agent_struct::lexeme, make_memory_block_for_string(), make_production(), make_sym_constant(), agent_struct::name, condition_struct::next, NIL, parse_lhs(), parse_rhs(), print(), print_location_of_most_recent_lexeme(), print_with_symbols(), sym_constant_struct::production, QUOTED_STRING_LEXEME, R_PAREN_LEXEME, reset_placeholder_variable_generator(), reset_variable_generator(), RIGHT_ARROW_LEXEME, production_struct::rl_rule, rl_rule_meta(), rl_valid_template(), symbol_union::sc, lexeme_info::string, substitute_for_placeholders_in_action_list(), substitute_for_placeholders_in_condition_list(), SYM_CONSTANT_LEXEME, symbol_remove_ref(), agent_struct::sysparams, TEMPLATE_PRODUCTION_TYPE, TRACE_LOADING_SYSPARAM, TRUE, lexeme_info::type, UNDECLARED_SUPPORT, and USER_PRODUCTION_TYPE.

{
Symbol *name;
char *documentation;
condition *lhs, *lhs_top, *lhs_bottom;
action *rhs;
byte declared_support;
byte prod_type;
// voigtjr: added to parameter list so that CLI can ignore the error
// of a duplicate production with a different name
//byte rete_addition_result;
Bool rhs_okay;
Bool interrupt_on_match;
/* --- read production name --- */
if (thisAgent->lexeme.type!=SYM_CONSTANT_LEXEME) {
print (thisAgent, "Expected symbol for production name\n");
return NIL;
}
name = make_sym_constant (thisAgent, thisAgent->lexeme.string);
get_lexeme(thisAgent);
/* --- if there's already a prod with this name, excise it --- */
if (name->sc.production) {
excise_production (thisAgent, name->sc.production, (TRUE && thisAgent->sysparams[TRACE_LOADING_SYSPARAM]));
}
/* --- read optional documentation string --- */
if (thisAgent->lexeme.type==QUOTED_STRING_LEXEME) {
documentation = make_memory_block_for_string (thisAgent, thisAgent->lexeme.string);
get_lexeme(thisAgent);
} else {
documentation = NIL;
}
/* --- read optional flags --- */
declared_support = UNDECLARED_SUPPORT;
prod_type = USER_PRODUCTION_TYPE;
interrupt_on_match = FALSE;
while (TRUE) {
if (thisAgent->lexeme.type!=SYM_CONSTANT_LEXEME) break;
if (!strcmp(thisAgent->lexeme.string,":o-support")) {
declared_support = DECLARED_O_SUPPORT;
get_lexeme(thisAgent);
continue;
}
if (!strcmp(thisAgent->lexeme.string,":i-support")) {
declared_support = DECLARED_I_SUPPORT;
get_lexeme(thisAgent);
continue;
}
if (!strcmp(thisAgent->lexeme.string,":chunk")) {
prod_type = CHUNK_PRODUCTION_TYPE;
get_lexeme(thisAgent);
continue;
}
if (!strcmp(thisAgent->lexeme.string,":default")) {
get_lexeme(thisAgent);
continue;
}
if (!strcmp(thisAgent->lexeme.string,":template")) {
get_lexeme(thisAgent);
continue;
}
if (!strcmp(thisAgent->lexeme.string, ":interrupt")) {
interrupt_on_match = TRUE;
get_lexeme(thisAgent);
continue;
}
break;
} /* end of while (TRUE) */
/* --- read the LHS --- */
lhs = parse_lhs(thisAgent);
if (! lhs) {
print_with_symbols (thisAgent, "(Ignoring production %y)\n\n", name);
if (documentation) free_memory_block_for_string (thisAgent, documentation);
symbol_remove_ref (thisAgent, name);
/* if (! reading_from_top_level()) respond_to_load_errors (); AGR 527c */
return NIL;
}
/* --- read the "-->" --- */
if (thisAgent->lexeme.type!=RIGHT_ARROW_LEXEME) {
print (thisAgent, "Expected --> in production\n");
print_with_symbols (thisAgent, "(Ignoring production %y)\n\n", name);
if (documentation) free_memory_block_for_string (thisAgent, documentation);
symbol_remove_ref (thisAgent, name);
deallocate_condition_list (thisAgent, lhs);
/* if (! reading_from_top_level()) respond_to_load_errors (); AGR 527c */
return NIL;
}
get_lexeme(thisAgent);
/* --- read the RHS --- */
rhs_okay = parse_rhs (thisAgent, &rhs);
if (!rhs_okay) {
print_with_symbols (thisAgent, "(Ignoring production %y)\n\n", name);
if (documentation) free_memory_block_for_string (thisAgent, documentation);
symbol_remove_ref (thisAgent, name);
deallocate_condition_list (thisAgent, lhs);
/* if (! reading_from_top_level()) respond_to_load_errors (); AGR 527c */
return NIL;
}
/* --- finally, make sure there's a closing right parenthesis (but
don't consume it) --- */
if (thisAgent->lexeme.type!=R_PAREN_LEXEME) {
print (thisAgent, "Expected ) to end production\n");
if (documentation) free_memory_block_for_string (thisAgent, documentation);
print_with_symbols (thisAgent, "(Ignoring production %y)\n\n", name);
symbol_remove_ref (thisAgent, name);
deallocate_condition_list (thisAgent, lhs);
deallocate_action_list (thisAgent, rhs);
/* if (! reading_from_top_level()) respond_to_load_errors (); AGR 527c */
return NIL;
}
/* --- replace placeholder variables with real variables --- */
reset_variable_generator (thisAgent, lhs, rhs);
/* --- everything parsed okay, so make the production structure --- */
lhs_top = lhs;
for (lhs_bottom=lhs; lhs_bottom->next!=NIL; lhs_bottom=lhs_bottom->next);
p = make_production (thisAgent, prod_type, name, &lhs_top, &lhs_bottom, &rhs, TRUE);
if (!p) {
if (documentation) free_memory_block_for_string (thisAgent, documentation);
print_with_symbols (thisAgent, "(Ignoring production %y)\n\n", name);
symbol_remove_ref (thisAgent, name);
deallocate_condition_list (thisAgent, lhs_top);
deallocate_action_list (thisAgent, rhs);
/* if (! reading_from_top_level()) respond_to_load_errors (); AGR 527c */
return NIL;
}
if ( prod_type == TEMPLATE_PRODUCTION_TYPE )
{
if ( !rl_valid_template( p ) )
{
print_with_symbols( thisAgent, "Invalid Soar-RL template (%y)\n\n", name );
excise_production( thisAgent, p, false );
return NIL;
}
}
p->documentation = documentation;
p->declared_support = declared_support;
p->interrupt = interrupt_on_match;
*rete_addition_result = add_production_to_rete (thisAgent, p, lhs_top, NIL, TRUE);
deallocate_condition_list (thisAgent, lhs_top);
if (*rete_addition_result==DUPLICATE_PRODUCTION) {
excise_production (thisAgent, p, FALSE);
p = NIL;
}
if ( p && p->rl_rule && p->documentation )
{
rl_rule_meta( thisAgent, p );
}
return p;
}
Bool parse_rhs ( agent thisAgent,
action **  dest_rhs 
)

Definition at line 1817 of file parser.cpp.

References deallocate_action_list(), FALSE, agent_struct::lexeme, action_struct::next, NIL, parse_rhs_action(), R_PAREN_LEXEME, TRUE, and lexeme_info::type.

Referenced by parse_production().

{
action *all_actions, *new_actions, *last;
all_actions = NIL;
while (thisAgent->lexeme.type!=R_PAREN_LEXEME) {
new_actions = parse_rhs_action (thisAgent);
if (new_actions) {
for (last=new_actions; last->next!=NIL; last=last->next);
last->next = all_actions;
all_actions = new_actions;
} else {
deallocate_action_list (thisAgent, all_actions);
return FALSE;
}
}
*dest_rhs = all_actions;
return TRUE;
}