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

📄 scan-fct_pddl.y

📁 intel ipp4.1性能库的一些例子。
💻 Y
字号:
%{#ifdef YYDEBUG  extern int yydebug=1;#endif#include <stdio.h>#include <string.h> #include "ipp.h"#include "pddl.h"#include "pddl-types.h"#include "utilities.h"#include "memory.h"#ifndef SCAN_ERR#define SCAN_ERR#define DEFINE_EXPECTED            0#define PROBLEM_EXPECTED           1#define PROBNAME_EXPECTED          2#define LBRACKET_EXPECTED          3#define RBRACKET_EXPECTED          4#define DOMDEFS_EXPECTED           5#define REQUIREM_EXPECTED          6#define TYPEDLIST_EXPECTED         7#define DOMEXT_EXPECTED            8#define DOMEXTNAME_EXPECTED        9#define TYPEDEF_EXPECTED          10#define CONSTLIST_EXPECTED        11#define PREDDEF_EXPECTED          12 #define NAME_EXPECTED             13#define VARIABLE_EXPECTED         14#define ACTIONFUNCTOR_EXPECTED    15#define ATOM_FORMULA_EXPECTED     16#define EFFECT_DEF_EXPECTED       17#define NEG_FORMULA_EXPECTED      18#define NOT_SUPPORTED             19#define SITUATION_EXPECTED        20#define SITNAME_EXPECTED          21#define BDOMAIN_EXPECTED          22#define BADDOMAIN                 23#define INIFACTS                  24#define GOALDEF                   25#define ADLGOAL                   26#endifstatic char * serrmsg[] = {  "'define' expected",  "'problem' expected",  "problem name expected",  "'(' expected",  "')' expected",  "additional domain definitions expected",  "requirements (e.g. ':strips') expected",  "typed list of <%s> expected",  "domain extension expected",  "domain to be extented expected",  "type definition expected",  "list of constants expected",  "predicate definition expected",  "<name> expected",  "<variable> expected",  "action functor expected",  "atomic formula expected",  "effect definition expected",  "negated atomic formula expected",  "requirement %s not supported by this IPP version",    "'situation' expected",  "situation name expected",  "':domain' expected",  "this problem needs another domain file",  "initial facts definition expected",  "goal definition expected",  "first order logic expression expected",  NULL};void fcterr( int errno, char *par );static int sact_err;static char * sact_err_par = NULL;static Bool sis_negated = FALSE;%}%start file%union {  char string[MAX_LENGTH];  char* pstring;  PlNode* pPlNode;  FactList* pFactList;  TokenList* pTokenList;  TypedList* pTypedList;}%type <pstring> problem_name%type <pPlNode> adl_goal_description%type <pPlNode> adl_goal_description_star%type <pPlNode> literal_name_plus%type <pPlNode> literal_name%type <pTokenList> literal_term%type <pTokenList> atomic_formula_term%type <pTokenList> term_star%type <pstring> term%type <pTokenList> name_star%type <pTokenList> atomic_formula_name%type <pstring> predicate%type <pTypedList> typed_list_name%type <pTypedList> typed_list_variable%type <pTokenList> name_plus%token DEFINE_TOK%token PROBLEM_TOK%token SITUATION_TOK%token BSITUATION_TOK%token OBJECTS_TOK%token BDOMAIN_TOK%token INIT_TOK%token GOAL_TOK%token AND_TOK%token NOT_TOK%token <string> NAME%token <string> VARIABLE%token <string> TYPE%token EQUAL_TOK%token FORALL_TOK%token IMPLY_TOK%token OR_TOK%token EXISTS_TOK%token EITHER_TOK%token OPEN_PAREN%token CLOSE_PAREN%%/**********************************************************************/file:/* empty */|problem_definition  file;/**********************************************************************/problem_definition : OPEN_PAREN DEFINE_TOK         { fcterr( PROBNAME_EXPECTED, NULL ); }problem_name  problem_defs  CLOSE_PAREN                 {    gproblem_name = $4;  if ( gcmd_line.display_info ) {    fprintf(OUT,"\nproblem '%s' defined\n", gproblem_name);  }};/**********************************************************************/problem_name :OPEN_PAREN  PROBLEM_TOK  NAME  CLOSE_PAREN        {   $$ = new_token( strlen($3)+1 );  strcpy( $$, $3);};/**********************************************************************/base_domain_name :OPEN_PAREN  BDOMAIN_TOK  NAME  CLOSE_PAREN{   if (SAME != strcmp($3, gdomain_name))    {      fcterr( BADDOMAIN, NULL );      yyerror();    }}/**********************************************************************/problem_defs:/* empty */|objects_def  problem_defs|init_def  problem_defs|goal_def  problem_defs|base_domain_name  problem_defs;/**********************************************************************/objects_def:OPEN_PAREN  OBJECTS_TOK  typed_list_name  CLOSE_PAREN{   gparse_objects = $3;};/**********************************************************************/init_def:OPEN_PAREN  INIT_TOK{ fcterr( INIFACTS, NULL ); }literal_name_plus  CLOSE_PAREN{  gorig_initial_facts = new_pl_node(AND);  gorig_initial_facts->sons = $4;};/**********************************************************************/goal_def:OPEN_PAREN  GOAL_TOK{ fcterr( GOALDEF, NULL ); }adl_goal_description  CLOSE_PAREN{  $4->next = gorig_goal_facts;  gorig_goal_facts = $4;};/********************************************************************** * Goal description providing full ADL. * RETURNS a tree with the connectives in the nodes and the atomic  * predicates in the leafs. **********************************************************************/adl_goal_description:literal_term{   if (TRUE == sis_negated)    {      $$ = new_pl_node(NOT);      $$->sons = new_pl_node(ATOM);      $$->sons->atom = $1;      sis_negated = FALSE;    }  else    {      $$ = new_pl_node(ATOM);      $$->atom = $1;    }}|OPEN_PAREN  AND_TOK  adl_goal_description_star  CLOSE_PAREN{   $$ = new_pl_node(AND);  $$->sons = $3;}|OPEN_PAREN  OR_TOK  adl_goal_description_star  CLOSE_PAREN{   $$ = new_pl_node(OR);  $$->sons = $3;}|OPEN_PAREN  NOT_TOK  adl_goal_description  CLOSE_PAREN{   $$ = new_pl_node(NOT);  $$->sons = $3;}|OPEN_PAREN  IMPLY_TOK  adl_goal_description  adl_goal_description  CLOSE_PAREN{   PlNode * np = new_pl_node(NOT);  np->sons = $3;  np->next = $4;  $$ = new_pl_node(OR);  $$->sons = np;}|OPEN_PAREN  EXISTS_TOK OPEN_PAREN  typed_list_variable  CLOSE_PAREN adl_goal_description  CLOSE_PAREN{   PlNode *pln;  pln = new_pl_node(EX);  pln->parse_vars = $4;  $$ = pln;  pln->sons = $6;}|OPEN_PAREN  FORALL_TOK OPEN_PAREN  typed_list_variable  CLOSE_PAREN adl_goal_description  CLOSE_PAREN{   PlNode *pln;  pln = new_pl_node(ALL);  pln->parse_vars = $4;  $$ = pln;  pln->sons = $6;};/**********************************************************************/adl_goal_description_star:/* empty */{  $$ = NULL;}|adl_goal_description  adl_goal_description_star{  $1->next = $2;  $$ = $1;}/********************************************************************** * some expressions used in many different rules **********************************************************************/literal_term:OPEN_PAREN  NOT_TOK  atomic_formula_term  CLOSE_PAREN{   $$ = $3;  sis_negated = TRUE;}|atomic_formula_term{  $$ = $1;};/**********************************************************************/atomic_formula_term:OPEN_PAREN  predicate  term_star  CLOSE_PAREN{   $$ = new_token_list();  $$->item = $2;  $$->next = $3;};/**********************************************************************/term_star:/* empty */{  $$ = NULL;}|term  term_star{  $$ = new_token_list();  $$->item = $1;  $$->next = $2;};/**********************************************************************/term:NAME{   $$ = new_token(strlen($1) + 1);  strcpy($$, $1);}|VARIABLE{   $$ = new_token(strlen($1) + 1);  strcpy($$, $1);};/**********************************************************************/name_plus:NAME{  $$ = new_token_list();  $$->item = new_token(strlen($1) + 1);  strcpy($$->item, $1);}|NAME  name_plus{  $$ = new_token_list();  $$->item = new_token(strlen($1) + 1);  strcpy($$->item, $1);  $$->next = $2;}/**********************************************************************/typed_list_name:     /* returns TypedList *//* empty */{ $$ = NULL; }|NAME  EITHER_TOK  name_plus  CLOSE_PAREN  typed_list_name{   $$ = new_TypedList();  $$->name = new_token( strlen($1)+1 );  strcpy( $$->name, $1 );  $$->type = $3;  $$->next = $5;}|NAME  TYPE  typed_list_name   /* end of list for one type */{  $$ = new_TypedList();  $$->name = new_token( strlen($1)+1 );  strcpy( $$->name, $1 );  $$->type = new_token_list();  $$->type->item = new_token( strlen($2)+1 );  strcpy( $$->type->item, $2 );  $$->next = $3;}|NAME  typed_list_name        /* a list element (gets type from next one) */{  $$ = new_TypedList();  $$->name = new_token( strlen($1)+1 );  strcpy( $$->name, $1 );  if ( $2 ) {/* another element (already typed) is following */    $$->type = copy_token_list( $2->type );  } else {/* no further element - it must be an untyped list */    $$->type = new_token_list();    $$->type->item = new_token( strlen(STANDARD_TYPE)+1 );    strcpy( $$->type->item, STANDARD_TYPE );  }  $$->next = $2;};/***********************************************/typed_list_variable:     /* returns TypedList *//* empty */{ $$ = NULL; }|VARIABLE  EITHER_TOK  name_plus  CLOSE_PAREN  typed_list_variable{   $$ = new_TypedList();  $$->name = new_token( strlen($1)+1 );  strcpy( $$->name, $1 );  $$->type = $3;  $$->next = $5;}|VARIABLE  TYPE  typed_list_variable   /* end of list for one type */{  $$ = new_TypedList();  $$->name = new_token( strlen($1)+1 );  strcpy( $$->name, $1 );  $$->type = new_token_list();  $$->type->item = new_token( strlen($2)+1 );  strcpy( $$->type->item, $2 );  $$->next = $3;}|VARIABLE  typed_list_variable        /* a list element (gets type from next one) */{  $$ = new_TypedList();  $$->name = new_token( strlen($1)+1 );  strcpy( $$->name, $1 );  if ( $2 ) {/* another element (already typed) is following */    $$->type = copy_token_list( $2->type );  } else {/* no further element - it must be an untyped list */    $$->type = new_token_list();    $$->type->item = new_token( strlen(STANDARD_TYPE)+1 );    strcpy( $$->type->item, STANDARD_TYPE );  }  $$->next = $2;};/**********************************************************************/predicate:NAME{   $$ = new_token(strlen($1) + 1);  strcpy($$, $1);}|EQUAL_TOK{   $$ = new_token( strlen(EQ_STR)+1 );  strcpy( $$, EQ_STR );};/**********************************************************************/literal_name_plus:literal_name{  $$ = $1;}|literal_name literal_name_plus{   $$ = $1;   $$->next = $2;} /**********************************************************************/literal_name:OPEN_PAREN  NOT_TOK  atomic_formula_name  CLOSE_PAREN{   PlNode * tmp;  tmp = new_pl_node(ATOM);  tmp->atom = $3;  $$ = new_pl_node(NOT);  $$->sons = tmp;}|atomic_formula_name{  $$ = new_pl_node(ATOM);  $$->atom = $1;};/**********************************************************************/atomic_formula_name:OPEN_PAREN  predicate  name_star  CLOSE_PAREN{   $$ = new_token_list();  $$->item = $2;  $$->next = $3;};/**********************************************************************/name_star:/* empty */{ $$ = NULL; }|NAME  name_star{  $$ = new_token_list();  $$->item = new_token(strlen($1) + 1);  strcpy($$->item, $1);  $$->next = $2;};%%#include "lex.fct_pddl.c"/********************************************************************** * Functions **********************************************************************//* call	bison -pfct -bscan-fct scan-fct.y*/void fcterr( int errno, char *par ){  sact_err = errno;  if ( sact_err_par )    free( sact_err_par );  if ( par )    {      sact_err_par = new_token( strlen(par)+1 );      strcpy( sact_err_par, par);    }  else    sact_err_par = NULL;}int yyerror( char *msg ){  fflush( stdout );  fprintf(stderr,"\n%s: syntax error in line %d, '%s':\n", 	  gact_filename, lineno, yytext );  if ( sact_err_par )    {      fprintf(stderr, "%s%s\n", serrmsg[sact_err], sact_err_par );    }  else    fprintf(stderr,"%s\n", serrmsg[sact_err] );  switch (sact_err)    {    case NOT_SUPPORTED:      exit( NOT_SUPPORTED_ERROR_CODE );    case BADDOMAIN:      exit( BADDOMAIN_ERROR_CODE );    default:      exit( FCT_PARSE_ERROR_CODE );     }}void load_fct_file( char *filename ){  FILE *fp;/* pointer to input files */  char tmp[MAX_LENGTH] = "";  /* open fact file */  if( ( fp = fopen( filename, "r" ) ) == NULL )     {      sprintf(tmp, "\nipp: can't find fact file: %s\n\n", filename );      perror(tmp);      exit( FCT_MISSING_ERROR_CODE );    }  gact_filename = filename;  lineno = 1;   yyin = fp;  yyparse();  fclose( fp );/* and close file again */}/* void  *//* get_fct_file_name(char * filename) *//* { *//*   FILE *fp;/* pointer to input files */ /*   char tmp[MAX_LENGTH] = ""; *//*   /* open fact file */ /*   if( ( fp = fopen( filename, "r" ) ) == NULL )  *//*     { *//*       sprintf(tmp, "\nipp: can't find fact file: %s\n\n", filename ); *//*       perror(tmp); *//*       output_time(IO_ERROR); *//*       exit( FCT_MISSING_ERROR_CODE ); *//*     } *//*   gact_filename = filename; *//*   lineno = 1;  *//*   yyin = fp; *//*   yyparse(); *//*   fclose( fp );/* and close file again */ /* } */

⌨️ 快捷键说明

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