Ejemplo n.º 1
0
static int rdp_check_disjoint(void * base)
{
  int bad = 0; 
  set_ work = SET_NULL; 
  
  rdp_data * temp =(rdp_data *) symbol_next_symbol_in_scope(base); 
  
  while (temp != NULL)
  {
    if (set_includes_element(& rdp_production_set, temp->kind)&& temp->kind != K_SEQUENCE)
    {
      rdp_list * left = temp->list; 
      
      while (left != NULL)
      {
        rdp_list * right = left->next; 
        
        while (right != NULL)
        {
          /* First check for disjoint on epsilon */
          if (left->production->contains_null && right->production->contains_null)
          {
            text_message(TEXT_ERROR, "LL(1) violation - rule \'%s\'\n", temp->id); 
            text_printf(" productions %s ::= ", left->production->id); 
            rdp_print_sub_item(left->production, 1); 
            text_printf(".\n and %s ::= ", right->production->id); 
            rdp_print_sub_item(right->production, 1); 
            text_printf(".\n are both nullable \n"); 
            left->production->ll1_violation = 1; 
            right->production->ll1_violation = 1; 
            bad = 1; 
          }
          
          set_assign_set(& work, & left->production->first); 
          set_intersect_set(& work, & right->production->first); 
          
          if (set_cardinality(& work)!= 0)
          {
            text_message(TEXT_ERROR, "LL(1) violation - rule \'%s\'\n", temp->id); 
            text_printf(" productions %s ::= ", left->production->id); 
            rdp_print_sub_item(left->production, 1); 
            text_printf(".\n and %s ::= ", right->production->id); 
            rdp_print_sub_item(right->production, 1); 
            text_printf(".\n share these start tokens: "); 
            set_print_set(& work, rdp_token_string, 78); 
            text_printf("\n"); 
            left->production->ll1_violation = 1; 
            right->production->ll1_violation = 1; 
            bad = 1; 
          }
          right = right->next; 
        }
        left = left->next; 
      }
    }
    temp =(rdp_data *) symbol_next_symbol_in_scope(temp); 
  }
  return bad; 
}
Ejemplo n.º 2
0
void pretty_open(char * sourcefilename, char * outputfilename)
{
  if (strcmp(sourcefilename, outputfilename)== 0)
    text_message(TEXT_FATAL, "temporary output filename is the same as the source filename"); 
  
  if (* outputfilename == '-')
    outputfile = stdout; 
  else if ((outputfile = fopen(outputfilename, "w"))== NULL)
    text_message(TEXT_FATAL, "unable to open output file \'%s\'", outputfilename); 
}
Ejemplo n.º 3
0
void text_print_statistics(void)
{
  long symbolcount = text_top - text_bot, 

  linecount =(text_bot - last_char)+ maxtext;

  if (text_bot == NULL)
    text_message(TEXT_INFO, "Text buffer uninitialised\n"); 
  else
    text_message(TEXT_INFO, "Text buffer size %u bytes with %lu bytes free\n", 
  maxtext, maxtext - symbolcount - linecount); 
}
Ejemplo n.º 4
0
int rdp_bad_grammar(void * base)
{
  int bad = 0; 
  
  /* Check for empties */
  if (rdp_verbose)
    text_message(TEXT_INFO, "Checking for empty alternates\n"); 
  bad |= rdp_check_empties(base); 
  
  /* Count productions and produce statistics */
  rdp_count_productions(base); 
  
  /* Check promotion operators on start production */
  if (rdp_start_prod->promote_default != PROMOTE_DONT)
    text_message(TEXT_WARNING, "default promotion operator \'%s\' on start production \'%s\' will not be applied at top level\n", 
  rdp_start_prod->promote_default == PROMOTE ? "^": 
  rdp_start_prod->promote_default == PROMOTE_AND_COPY ? "^^": "??", 
  rdp_start_prod->id); 
  
  /* find first sets */
  if (rdp_verbose)
    text_message(TEXT_INFO, "Generating first sets\n"); 
  rdp_find_first(base); 
  
  /* find follow sets */
  if (rdp_verbose)
    text_message(TEXT_INFO, "Generating follow sets\n"); 
  rdp_find_follow(base); 
  
  /* check for C reserved words */
  if (rdp_verbose)
    text_message(TEXT_INFO, "Checking for clashes with reserved words\n"); 
  bad |= rdp_check_reserved_words(); 
  
  /* check that for each production, all alternates have unique start tokens */
  if (rdp_verbose)
    text_message(TEXT_INFO, "Checking for disjoint first sets\n"); 
  bad |= rdp_check_disjoint(base); 
  
  /* check nullable brackets don't contain nullable productions */
  if (rdp_verbose)
    text_message(TEXT_INFO, "Checking for nested nullable subrules\n"); 
  bad |= rdp_check_nested_nullable(base); 
  
  /* check that first(a) - follow (a) is empty for nullable a */
  if (rdp_verbose)
    text_message(TEXT_INFO, "Checking nullable rules\n"); 
  bad |= rdp_check_nullable(base); 
  
  /* add first() to follow() for iterations so that error handling doesn't just eat entire file! */
  if (rdp_verbose)
    text_message(TEXT_INFO, "Updating follow sets\n"); 
  rdp_update_follow_sets(base); 
  /* re-close follow sets */
  rdp_find_follow(base); 
  
  return bad; 
}
Ejemplo n.º 5
0
static void rdp_find_follow(void * base)
{
  rdp_data * temp; 
  unsigned follow_pass = 0; 
  
  do
  {
    follow_pass++; 
    rdp_follow_changed = 0; 
    temp =(rdp_data *) symbol_next_symbol_in_scope(base); 
    while (temp != NULL)
    {
      if (temp->kind == K_SEQUENCE) /* only need to scan sequences */
        rdp_follow_sequence(temp); 
      else
        rdp_follow_alternate(temp); 
      temp =(rdp_data *) symbol_next_symbol_in_scope(temp); 
    }
  }
  while (rdp_follow_changed); 
    
  if (rdp_verbose)
    text_message(TEXT_INFO, "Follow sets stabilised after %u pass%s\n", follow_pass, follow_pass == 1 ? "": "es"); 
  
}
Ejemplo n.º 6
0
/* Check if we have a nullable alternate inside a nullable iterator */
static int rdp_check_nested_nullable(void * base)
{
  int bad = 0; 
  rdp_data * temp =(rdp_data *) symbol_next_symbol_in_scope(base); 
  
  while (temp != NULL)
  {
    if (set_includes_element(& rdp_production_set, temp->kind)&& temp->kind != K_SEQUENCE)
    {
      rdp_list * inner = temp->list; 
      
      while (inner != NULL)
      {
        
        if (temp->lo == 0 && inner->production->contains_null)
        {
          text_message(TEXT_ERROR, "LL(1) violation - rule \'%s\'\n is nullable but contains the nullable subrule\n", temp->id); 
          text_printf(" %s ::= ", inner->production->id); 
          rdp_print_sub_item(inner->production, 1); 
          text_printf(".\n"); 
          bad = 1; 
          temp->ll1_violation = 1; 
          inner->production->ll1_violation = 1; 
        }
        inner = inner->next; 
      }
    }
    temp =(rdp_data *) symbol_next_symbol_in_scope(temp); 
  }
  return bad; 
}
Ejemplo n.º 7
0
static void statement(void)
{
  char* name;
  integer val;
  char* str;
  {
    if (scan_test(NULL, SCAN_P_ID, NULL))
    {
      scan_test(NULL, SCAN_P_ID, &statement_stop);
      name = SCAN_CAST->id;
      scan_();
       if (symbol_lookup_key(mini, &name, NULL) == NULL)\
                 {\
                   text_message(TEXT_ERROR, "Undeclared variable '%s'\n", name);\
                   symbol_insert_key(mini, &name, sizeof(char*), sizeof(mini_data));\
                 }\
              
      scan_test(NULL, RDP_T_61 /* = */, &statement_stop);
      scan_();
      val = e1();
       mini_cast(symbol_lookup_key(mini, &name, NULL))->i = val; 
    }
    else
    if (scan_test(NULL, RDP_T_print, NULL))
    {
      scan_test(NULL, RDP_T_print, &statement_stop);
      scan_();
      scan_test(NULL, RDP_T_40 /* ( */, &statement_stop);
      scan_();
      { /* Start of rdp_statement_3 */
        while (1)
        {
          scan_test_set(NULL, &rdp_statement_3_first, &statement_stop);
          {
            if (scan_test_set(NULL, &rdp_statement_1_first, NULL))
            {
              val = e1();
               printf("%li", val); 
            }
            else
            if (scan_test(NULL, RDP_T_34 /* " */, NULL))
            {
              str = String();
               printf("%s", str); 
            }
            else
              scan_test_set(NULL, &rdp_statement_3_first, &statement_stop)            ;
            }
          if (SCAN_CAST->token != RDP_T_44 /* , */) break;
          scan_();
        }
      } /* end of rdp_statement_3 */
      scan_test(NULL, RDP_T_41 /* ) */, &statement_stop);
      scan_();
    }
    else
      scan_test_set(NULL, &statement_first, &statement_stop)    ;
    scan_test_set(NULL, &statement_stop, &statement_stop);
   }
}
Ejemplo n.º 8
0
static int rdp_check_nullable(void * base)
{
  int bad = 0; 
  rdp_data * temp =(rdp_data *) symbol_next_symbol_in_scope(base); 
  set_ work = SET_NULL; 
  
  while (temp != NULL)
  {
    if (temp->contains_null &&(temp->kind != K_CODE))
    {
      set_assign_set(& work, & temp->first); 
      set_intersect_set(& work, & temp->follow); 
      
      if (set_cardinality(& work)!= 0)
      {
        text_message(TEXT_ERROR, "LL(1) violation - rule\n %s ::= ", temp->id); 
        rdp_print_sub_item(temp, 1); 
        text_printf(".\n contains null but first and follow sets both include: "); 
        
        set_print_set(& work, rdp_token_string, 78); 
        text_printf("\n"); 
        temp->ll1_violation = 1; 
        bad = 1; 
      }
    }
    temp =(rdp_data *) symbol_next_symbol_in_scope(temp); 
  }
  return bad; 
}
Ejemplo n.º 9
0
static void dec_body(rdp_tree_node_data* rdp_tree)
{
  char* name;
  {
    if (rdp_tree_update) memcpy(rdp_tree, text_scan_data, sizeof(scan_data));
    scan_test(NULL, SCAN_P_ID, &dec_body_stop);
    name = SCAN_CAST->id;
    scan_();
    if (scan_test(NULL, RDP_T_61 /* = */, NULL))
    { /* Start of rdp_dec_body_1 */
      while (1)
      {
        {
          scan_test(NULL, RDP_T_61 /* = */, &dec_body_stop);
          scan_();
          e0(rdp_add_child("e0", rdp_tree));
          }
        break;   /* hi limit is 1! */
      }
    } /* end of rdp_dec_body_1 */
    else
    {
      /* default action processing for rdp_dec_body_1*/
    }
     symbol_insert_key(mini, &name, sizeof(char*), sizeof(mini_data)); \
                if (*name == '_' && *(name+1) == '_')\
                  text_message(TEXT_ERROR_ECHO, "variable names must not begin with two underscores\n");\
             
    scan_test_set(NULL, &dec_body_stop, &dec_body_stop);
   }
}
Ejemplo n.º 10
0
static void scan_skip(set_ * stop) /* scan until a token in stop set appears */
{
  while (!set_includes_element(stop, SCAN_CAST->token))
    scan_();                  /* Don't add tokens to tree when skipping! */
  
  if (scan_show_skips)
    text_message(TEXT_ERROR_ECHO, "Skipping to...\n"); 
}
Ejemplo n.º 11
0
int text_print_total_errors(void)
{
  if (totalerrors != 0 || totalwarnings != 0 || echo)
    text_message(TEXT_INFO, "%u error%s and %u warning%s\n", 
  totalerrors, (totalerrors == 1 ? "": "s"), 
  totalwarnings, (totalwarnings == 1 ? "": "s"));
  
  return totalerrors != 0; 
}
Ejemplo n.º 12
0
char * text_insert_char(const char c)
{
  char * start = text_top; 
  
  if (text_top >= last_char)
  {
    #if 0
    /* Dump buffer on overflow */
    text_message(TEXT_INFO, "Ran out of text space - dumping buffer\n"); 
    text_dump(); 
    #endif
    text_message(TEXT_FATAL, "Ran out of text space\n"); 
  }
  else
    * text_top++ = c; 

  return start; 
}
Ejemplo n.º 13
0
void pretty_close(char * sourcefilename, char * outputfilename)
{
  unsigned long useful_lexeme_count = lexeme_count - comment_count - eoln_count; 
  char * backup_filename = text_force_filetype(sourcefilename, "bak"); 
  
  fclose(outputfile); 
  
  remove(backup_filename); 
  
  if (rename(sourcefilename, backup_filename)!= 0)
    text_message(TEXT_FATAL, "unable to rename \'%s\' to \'%s\'\n", sourcefilename, backup_filename); 
  
  if (rename(outputfilename, sourcefilename)!= 0)
    text_message(TEXT_FATAL, "unable to rename \'%s\' to \'%s\'\n", outputfilename, sourcefilename); 
  
  text_printf("%s,%lu,%lu,%.2lf\n", sourcefilename, 
  last_line, 
  useful_lexeme_count, 
  (double) useful_lexeme_count /(double) last_line); 
}
Ejemplo n.º 14
0
void rdp_check_token_valid(char * id)
{
  if (id == NULL)
    return; 
  
  if (* id == 0)
    text_message(TEXT_ERROR_ECHO, "empty tokens are not allowed: use [ ... ] instead\n"); 
  /* Test for embedded spaces in token */
  {
    int bad = 0; 
    
    while (* id != 0)
    {
      bad |= !isgraph(* id); 
      id++; 
    }
    
    if (bad)
      text_message(TEXT_ERROR_ECHO, "tokens must not contain spaces or control characters\n"); 
  }
}
Ejemplo n.º 15
0
int scan_test_set(const char * production, set_ * valid, set_ * stop)
{
  if (!set_includes_element(valid, SCAN_CAST->token))
  {
    if (stop != NULL)
    {
      if (production != NULL)
        text_message(TEXT_ERROR_ECHO, "In rule \'%s\', scanned ", production); 
      else
        text_message(TEXT_ERROR_ECHO, "Scanned ");
      set_print_element(SCAN_CAST->token, scan_token_names); 
      text_printf(" whilst expecting %s", set_cardinality(valid)== 1 ? "": "one of ");
      set_print_set(valid, scan_token_names, 60); 
      text_printf("\n"); 
      scan_skip(stop); 
    }
    return 0;
  }
  else
    return 1;
}
Ejemplo n.º 16
0
void respond_ls(t_socket *connection, t_message packet) {
    char *params = (char *) malloc(sizeof(char) * packet.size - 2);
    strncpy(params, packet.data, packet.size - 3);
    params[packet.size - 3] = '\0';

    char *output = (char *) calloc(1048576, 1);
    ls(params, output);
    text_message(connection, TYPE_SCREEN, output);
    if (output != NULL)
        free(output);
    if (params != NULL)
        free(params);
}
Ejemplo n.º 17
0
int scan_test(const char * production, const int valid, set_ * stop)
{
  if (valid != SCAN_CAST->token)
  {
    if (stop != NULL)
    {
      if (production != NULL)
        text_message(TEXT_ERROR_ECHO, "In rule \'%s\', scanned ", production); 
      else
        text_message(TEXT_ERROR_ECHO, "Scanned ");
      set_print_element(SCAN_CAST->token, scan_token_names); 
      text_printf(" whilst expecting "); 

      set_print_element(valid, scan_token_names); 
      text_printf("\n");
      scan_skip(stop); 
    }
    return 0; 
  }
  else
    return 1; 
}
Ejemplo n.º 18
0
void rdp_check_prod_name_valid(char * id)
{
  if ((strncmp("rdp_", id, 4)== 0)||
    (strncmp("RDP_", id, 4)== 0)||
  (strncmp("args_", id, 5)== 0)||
  (strncmp("mem_", id, 4)== 0)||
  (strncmp("set_", id, 4)== 0)||
  (strncmp("scan_", id, 5)== 0)||
  (strncmp("SCAN_", id, 5)== 0)||
  (strncmp("sym_", id, 4)== 0)||
  (strncmp("text_", id, 5)== 0))
  text_message(TEXT_ERROR_ECHO, "identifier \'%s\' begins with a reserved name\n", id); 
}
Ejemplo n.º 19
0
static int rdp_check_identifier(char * id)
{
  rdp_data * s =(rdp_data *) symbol_lookup_key(rdp, & id, NULL); 
  
  if (s != NULL)
  {
    if (s->kind == K_PRIMARY)
    {
      text_message(TEXT_ERROR, "identifier \'%s\' is a C++ reserved word or library identifier\n", id); 
      return 1; 
    }
  }
  return 0; 
}
Ejemplo n.º 20
0
FILE * text_open(char * s)
{
  FILE * handle,
  * old = file;

  if (* s == '-')
    handle = stdin;
  else
    handle = fopen(s, "r");   /* try and get the file */

  if (handle != NULL)         /* we found a file */
  {
    if (old != NULL)          /* save current file context */
    {
      struct source_list * temp =(struct source_list *) mem_calloc(1, sizeof(struct source_list));

      /* load descriptor block */
      temp->errors = errors;
      temp->file = file;
      temp->first_char = first_char;
      temp->last_char = last_char;
      temp->linenumber = linenumber;
      temp->name = name;
      temp->text_char = text_char;
      temp->text_current = text_current;
      memcpy(&(temp->text_scan_data), text_scan_data, sizeof(scan_data));
      temp->symbol_first_char = symbol_first_char;
      temp->warnings = warnings;

      /* link descriptor block into head of list */
      temp->previous = source_descriptor_list;
      source_descriptor_list = temp;
    }

    /* re-initialise file context */
    errors = 0;
    file = handle;
    linenumber = 0;
    name = s;
    warnings = 0;

    if (echo)
      text_message(TEXT_INFO, "\n");

    text_current = last_char = first_char = last_char - 1;  /* make new buffer region below current line */
  }
  
  return handle; 
}
Ejemplo n.º 21
0
void text_init(const long max_text, const unsigned max_errors, const unsigned max_warnings, const unsigned tab_width)
{
  tabwidth = tab_width; 
  maxtext =(size_t) max_text;  /* set text buffer size */
  
  if ((long) maxtext != max_text)
    text_message(TEXT_WARNING, "-T%lu too large for architecture: recast to -T%u\n", max_text, maxtext); 
  maxerrors = max_errors;     /* set maximum number of errors per file */
  maxwarnings = max_warnings;  /* set maximum number of warnings per file */
  
  text_bot =(char *) mem_malloc(maxtext);  /* allocate text buffer */
  
  text_top = text_bot;        /* top of text character */
  text_current = last_char = first_char = text_bot + maxtext;  /* make new buffer region below top of text */
}
Ejemplo n.º 22
0
static void rdp_first(rdp_data * prod)
{
  if (prod->in_use)           /* something has gone wrong */
  {
    text_message(TEXT_ERROR, "LL(1) violation - rule \'%s\' is left recursive\n", prod->id);  /* and return */
    prod->ll1_violation = 1; 
    return; 
  }
  
  if (!prod->first_done)      /* something to do */
  {
    rdp_list * list = prod->list;  /* set up alternates pointer */
    
    prod->in_use = 1;         /* mark this production as being processed */
    
    if (prod->kind == K_SEQUENCE) /* sequences are treated differently */
    {
      prod->contains_null = 1;  /* set up list flag */
      while (list != NULL && prod->contains_null) /* scan until non-empty alternate is found */
      {
        if (!list->production->first_done) /* do first */
          rdp_first(list->production); 
        
        set_unite_set(& prod->first, & list->production->first);  /* add alternate first set to production first set */
        prod->contains_null = list->production->contains_null;  /* set contains_null flag */
        
        list = list->next; 
      }
    }
    else
      while (list != NULL)    /* scan all alternates */
    {
      if (!list->production->first_done) /* do first */
        rdp_first(list->production); 
      
      set_unite_set(& prod->first, & list->production->first);  /* add alternate first set to production first set */
      prod->contains_null |= list->production->contains_null;  /* OR in contains_null flag */
      list = list->next; 
    }
    prod->in_use = 0;         /* production is no longer in use */
    prod->first_done = 1;     /* first set is now complete */
    /* and set cardinality */
    prod->first_cardinality = set_cardinality(& prod->first); 
  }
}
Ejemplo n.º 23
0
void respond_cd(t_socket *connection, t_message packet) {
    char *params = (char *) malloc(sizeof(char) * packet.size - 2);
    strncpy(params, packet.data, packet.size - 3);
    params[packet.size - 3] = '\0';

    char buffer[2048];

    if (!cd(params)) {
        sprintf(buffer, "remote chdir at '%s'\n", params);
        text_message(connection, TYPE_SCREEN, buffer);
    }
    else if (errno == EACCES)
        enqueue_message(connection, error_message(2, packet.sequence));
    else
        enqueue_message(connection, error_message(1, packet.sequence));

    if (params != NULL)
        free(params);
}
Ejemplo n.º 24
0
static integer e5(void)
{
  integer result;
  char* name;
  {
    if (scan_test(NULL, SCAN_P_ID, NULL))
    {
      scan_test(NULL, SCAN_P_ID, &e5_stop);
      name = SCAN_CAST->id;
      scan_();
       if (symbol_lookup_key(mini, &name, NULL) == NULL)\
                 {\
                   text_message(TEXT_ERROR, "Undeclared variable '%s'\n", name);\
                   symbol_insert_key(mini, &name, sizeof(char*), sizeof(mini_data));\
                 }\
              
 result = mini_cast(symbol_lookup_key(mini, &name, NULL))->i; 
    }
    else
    if (scan_test(NULL, SCAN_P_INTEGER, NULL))
    {
      scan_test(NULL, SCAN_P_INTEGER, &e5_stop);
      result = SCAN_CAST->data.i;
      scan_();
    }
    else
    if (scan_test(NULL, RDP_T_40 /* ( */, NULL))
    {
      scan_test(NULL, RDP_T_40 /* ( */, &e5_stop);
      scan_();
      result = e1();
      scan_test(NULL, RDP_T_41 /* ) */, &e5_stop);
      scan_();
    }
    else
      scan_test_set(NULL, &e5_first, &e5_stop)    ;
    scan_test_set(NULL, &e5_stop, &e5_stop);
   }
  return result;
}
Ejemplo n.º 25
0
static integer e2(void)
{
  integer result;
  integer right;
  {
    result = e3();
    if (scan_test_set(NULL, &rdp_e2_2_first, NULL))
    { /* Start of rdp_e2_2 */
      while (1)
      {
        {
          if (scan_test(NULL, RDP_T_42 /* * */, NULL))
          {
            scan_test(NULL, RDP_T_42 /* * */, &e2_stop);
            scan_();
            right = e3();
             result *= right; 
          }
          else
          if (scan_test(NULL, RDP_T_47 /* / */, NULL))
          {
            scan_test(NULL, RDP_T_47 /* / */, &e2_stop);
            scan_();
            right = e3();
             if (result == 0)       \
                               text_message(TEXT_FATAL_ECHO, "Divide by zero attempted\n"); \
                             else result /= right; \
                          
          }
          else
            scan_test_set(NULL, &rdp_e2_2_first, &e2_stop)          ;
          }
        if (!scan_test_set(NULL, &rdp_e2_2_first, NULL)) break;
      }
    } /* end of rdp_e2_2 */
    scan_test_set(NULL, &e2_stop, &e2_stop);
   }
  return result;
}
Ejemplo n.º 26
0
static void text_close(void)
{
  struct source_list * temp = source_descriptor_list;

  if (file == NULL)
    return;

  linenumber = 0;             /* switch off line number on messages */

  fclose(file);               /* close the file */
  file = NULL;

  if (source_descriptor_list != NULL) /* unload next file if there is one */
  {
    source_descriptor_list = source_descriptor_list->previous;

    errors = temp->errors;
    file = temp->file;
    first_char = temp->first_char;
    last_char = temp->last_char;
    linenumber = temp->linenumber;
    name = temp->name;
    text_char = temp->text_char;
    text_current = temp->text_current;
    memcpy(text_scan_data, &(temp->text_scan_data), sizeof(scan_data));
    symbol_first_char = temp->symbol_first_char;
    warnings = temp->warnings;

    free(temp);               /* give the storage back */

    if (echo)
    {
      text_message(TEXT_INFO, "\n");
      text_echo_line();       /* reecho line in case there are errors */
    }
  }
}
Ejemplo n.º 27
0
static void rdp_count_productions(void * base)
{
  unsigned primaries = 0, 
  internals = 0, 
  codes = 0; 
  
  rdp_data * temp =(rdp_data *) symbol_next_symbol_in_scope(base); 
  
  while (temp != NULL)
  {
    if (temp->kind == K_PRIMARY)
      primaries++; 
    else if (temp->kind == K_CODE)
      codes++; 
    else
      internals++; 
    
    temp =(rdp_data *) symbol_next_symbol_in_scope(temp); 
  }
  
  if (rdp_verbose)
    text_message(TEXT_INFO, "%u rules, %u tokens, %u actions, %u subrules\n", 
  primaries, rdp_token_count - SCAN_P_TOP + 1, codes, internals); 
}
Ejemplo n.º 28
0
double calc_zfill_gradient2(FLOWCOMP_T *grad0, FLOWCOMP_T  *grad1,
                         GENERIC_GRADIENT_T  *grad2)

{ 
   
   double time    = 0.0;                    /* longest duration of gradient */
   double duration0, duration1, duration2;  /* gradient durations */
   
   ZERO_FILL_GRADIENT_T zf_grad0,zf_grad1, zf_grad2; /* define zero-fill grad structure in case of flow comp */

   if ((ix > 1) && !sglarray) return(grad0->duration);
   

   /* find longest gradient duration */
   duration0 = grad0->duration;//- grad[0]->tramp; /* duration of a square gradient with same integral & amplitude */
   duration1 = grad1->duration;// - grad[1]->tramp;
   duration2 = grad2->duration;// - grad[2]->tramp;
  
   time = MAX(MAX(duration0,duration1),duration2);  /* should already be granulated */
   text_message("time is %f", time);

/* zerofill new duration for each gradient */

    initZeroFillGradient(&zf_grad0); /* initialize zerofill structure for pe grad */
   // strcpy(zf_grad0.name,"zfgrad0");   /*fill in the unique name, otherwise the name will be repeated for each zerofill pattern*/
     strcpy(zf_grad0.name,"zfgrad0");  
   

    zf_grad0.numPoints= grad0->numPoints ;/* assign number of waveform points */
    zf_grad0.dataPoints = grad0->dataPoints; /* assign waveform to be zero-filled */
    zf_grad0.newDuration= time; /* duration of the fc grad for readout */
    zf_grad0.location = FRONT; /* add zero at front of waveform */
    zeroFillGradient(&zf_grad0);
    if (zf_grad0.error) abort_message("Gradient library error --> Check text window \n");
    //Now put it back
    grad0->duration=time ;
    grad0->numPoints=zf_grad0.numPoints ;/* assign number of waveform points */
    grad0->dataPoints= zf_grad0.dataPoints ;  /* assign waveform to be zero-filled */
    writeToDisk(grad0->dataPoints, grad0->numPoints, 0, grad0->resolution,
				     TRUE /*rolout*/, grad0->name); 
    initZeroFillGradient(&zf_grad1); /* initialize zerofill structure for pe grad */
    strcpy(zf_grad1.name,"zfgrad1");   /*fill in the unique name, otherwise the name will be repeated for each zerofill pattern*/
   

    zf_grad1.numPoints= grad1->numPoints ;/* assign number of waveform points */
    zf_grad1.dataPoints = grad1->dataPoints; /* assign waveform to be zero-filled */
    zf_grad1.newDuration= time; /* duration of the fc grad for readout */
    zf_grad1.location = FRONT; /* add zero at front of waveform */
    zeroFillGradient(&zf_grad1);
    if (zf_grad1.error) abort_message("Gradient library error --> Check text window \n");
    //Now put it back
    grad1->duration=time ;
    grad1->numPoints=zf_grad1.numPoints ;/* assign number of waveform points */
    grad1->dataPoints= zf_grad1.dataPoints ;  /* assign waveform to be zero-filled */
    writeToDisk(grad1->dataPoints, grad1->numPoints, 0, grad1->resolution,
				     grad1->rollOut, grad1->name); 

    initZeroFillGradient(&zf_grad2); /* initialize zerofill structure for pe grad */
    strcpy(zf_grad2.name,"zfgrad2");   /*fill in the unique name, otherwise the name will be repeated for each zerofill pattern*/
    

    zf_grad2.numPoints= grad2->numPoints ;/* assign number of waveform points */
    zf_grad2.dataPoints = grad2->dataPoints; /* assign waveform to be zero-filled */
    zf_grad2.newDuration= time; /* duration of the fc grad for readout */
    zf_grad2.location = FRONT; /* add zero at front of waveform */
    zeroFillGradient(&zf_grad2);
    if (zf_grad2.error) abort_message("Gradient library error --> Check text window \n");
    //Now put it back
    grad2->duration=time ;
    grad2->numPoints=zf_grad2.numPoints ;/* assign number of waveform points */
    grad2->dataPoints= zf_grad2.dataPoints ;  /* assign waveform to be zero-filled */
    writeToDisk(grad2->dataPoints, grad2->numPoints, 0, grad2->resolution,
				     grad2->rollOut, grad2->name); 
   

   return(time); 

}
Ejemplo n.º 29
0
void calc_grad_duty(double time)
   {
   double  gradenergy[3],gradduty[3];
   double  mult=1.0;
   double  currentlimit,RMScurrentlimit;
   double  sglduty,dutylimit;
   int     checksilent,r,nrcvrs,arraydim,error=0;
   char    rcvrs[MAXSTR];

   currentlimit = getval("currentlimit");
   RMScurrentlimit = getval("RMScurrentlimit");
   getRealSetDefault(GLOBAL, "sglduty", &sglduty,0.0);
   dutylimit = RMScurrentlimit/currentlimit;
   checksilent = option_check("checksilent");

   /* Adjust array dimenstion for multiple receivers */
   nrcvrs = 0;
   getstr("rcvrs",rcvrs);
   arraydim = getvalnwarn("arraydim");
   for (r = 0; r < strlen(rcvrs); r++) {
     if (rcvrs[r] == 'y') nrcvrs++;
   }
   arraydim /= nrcvrs;

   if (seqcon[2] == 'c')
     mult *= nv;
   if (seqcon[3] == 'c')
     mult *= nv2;

   if (!checkflag)
     mult *= arraydim;

   getgradpowerintegral(gradenergy);
   gradduty[0] = sqrt(gradenergy[0]/(mult*time));
   gradduty[1] = sqrt(gradenergy[1]/(mult*time));
   gradduty[2] = sqrt(gradenergy[2]/(mult*time));

   if (sglduty && ((checkflag && !checksilent) || (!checksilent && ix == arraydim))) {
     text_message("Grad energy X: %.3g    Grad energy Y: %.3g    Grad energy Z: %.3g",gradenergy[0],gradenergy[1],gradenergy[2]);
     text_message("Grad duty X: %.3g%%    Grad duty Y: %.3g%%    Grad duty Z: %.3g%%",100*gradduty[0],100*gradduty[1],100*gradduty[2]);
   }

   if ((gradduty[0] > dutylimit) && ((checkflag && !checksilent) || (!checksilent && ix == arraydim))) {
     text_message("%s: X gradient duty cycle %5.1f%% exceeds allowed limit of %5.1f%%",seqfil,100*gradduty[0],100*dutylimit);
     error = 1;
   }
   if ((gradduty[1] > dutylimit) && ((checkflag && !checksilent) || (!checksilent && ix == arraydim))) {
     text_message("%s: Y gradient duty cycle %5.1f%% exceeds allowed limit of %5.1f%%",seqfil,100*gradduty[1],100*dutylimit);
     error = 1;
   }
   if ((gradduty[2] > dutylimit) && ((checkflag && !checksilent) || (!checksilent && ix == arraydim))) {
     text_message("%s: Z gradient duty cycle %5.1f%% exceeds allowed limit of %5.1f%%",seqfil,100*gradduty[2],100*dutylimit);
     error = 1;
   }
   if (error) {
     if (sglduty)
       warn_message("%s: Duty cycle exceeds allowed limit",seqfil);
     else
       abort_message("%s: Duty cycle exceeds allowed limit",seqfil);
   }
   }
Ejemplo n.º 30
0
pulsesequence()
{
   double 	d3 = getval("d3"),
                vtcomplvl = getval("vtcomplvl"),
		gzlvl = getval("gzlvl"),
		shapedpw90 = getvalnwarn("shapedpw90"),
		shapedpw180 = getvalnwarn("shapedpw180"),
		shapedpwr90 = getvalnwarn("shapedpwr90"),
		shapedpwr180 = getvalnwarn("shapedpwr180"),
		gt,gts,lvlf;
   int		hs_gradtype;
   char		shaped[MAXSTR], shapename90[MAXSTR], shapename180[MAXSTR];

   getstrnwarn("shaped", shaped);
   getstrnwarn("shapename90", shapename90);
   getstrnwarn("shapename180", shapename180);
   settmpgradtype("tmpgradtype");
   hs_gradtype = ((specialGradtype == 'h') || (specialGradtype == 'a'));

   if ((p1==0.0) && ((vtcomplvl>0.5) || (hs_gradtype)))
   {
      p1 = 2.0*pw;
   }
   if ((vtcomplvl==2) && ((hs_gradtype) || (spin>0)))
   {
      vtcomplvl = 1;
      if (ix==1)
      {
         text_message("gmapz: vtcomplvl set to 1\n");
         putCmd("setvalue('vtcomplvl',%.0f)\n",vtcomplvl);
         putCmd("setvalue('vtcomplvl',%.0f,'processed')\n",vtcomplvl);
      }
   }

/* lvlf, gt, gts only used for convection compensation */
   if (gradtype[2]=='l') 
     lvlf=2.5;
   else
     lvlf=3.0;
   if ((hs_gradtype) || (spin>0))
     lvlf=1.0;

   gt = (0.5*at + d2)/lvlf;
   gts=0.18*at/lvlf;
   gts = 0.2*at/lvlf;
   if (vtcomplvl==2)
      gt += gts;
   gt *= 2.0;

   settable(t1,16,ph1);
   settable(t2,2,ph2);
   settable(t3,8,ph3);
   settable(t4,16,ph4);

   sub(ct,ssctr,v12);
   getelem(t1,v12,v1);
   getelem(t2,v12,v2);
   getelem(t3,v12,v3);
   getelem(t4,v12,oph); 

   if (vtcomplvl < 0.5)
   {
      getelem(t4,v12,v1); 
      getelem(t1,v12,v2);
   }

/* --- equilibration period --- */
   status(A);
      delay(d1);

/* --- initial pulse --- */
   status(B);
      if (shaped[A] == 'y') {
	obspower(shapedpwr90);
	shaped_pulse(shapename90,shapedpw90,v1,rof1,rof2);
	obspower(tpwr);
	}
      else
        pulse(pw,v1);
/*    instead of hard pulse, could use shapedpulse("gauss",pw,oph,rof1,rof2);
        or "bir4_90_512" or other shape for selective excitation.
        selective inversion pulses may or may not work as well. */

/* --- shim phase encode, not during PFG recovery --- */
      delay(2e-5+d3);

/* First case: No convection compensation, traditional sequence */
   if (vtcomplvl < 0.5)
   {
      if (p1 > 0) 
      {
         zgradpulse(gzlvl,at/2+d2);
         delay(d2);
         if (shaped[A] == 'y') {
	   obspower(shapedpwr180);
	   shaped_pulse(shapename180,shapedpw180,v2,rof1,rof2);
	   obspower(tpwr);
	   }
         else
           pulse(p1,v2);
         delay(d2);
      }
      else
      {
         zgradpulse(-gzlvl,at/2+d2);
         delay(d2*2);
      }
   }
   else  /* (vtcomplvl > 0.5) */
   {
/* Second case: convection compensation  */

      zgradpulse(gzlvl,at/2+d2);
      delay(d2);
      if (vtcomplvl==2)
      {
         zgradpulse(lvlf*gzlvl,gts);
         delay(d2);
      }
      if (shaped[A] == 'y') {
	obspower(shapedpwr180);
	shaped_pulse(shapename180,shapedpw180,v2,rof1,rof2);
      }
      else
        pulse(p1,v2); 
      delay(d2);
      zgradpulse(lvlf*gzlvl,gt);
      delay(d2);
      if (shaped[A] == 'y') {
	shaped_pulse(shapename180,shapedpw180,v3,rof1,rof2);
	obspower(tpwr);
      }
      else
        pulse(p1,v3);
      delay(d2);
      if (vtcomplvl==2)
      {
         zgradpulse(lvlf*gzlvl,gts); 
         delay(d2);
      }
   }

/* --- acq. of echo during gradient --- */
   rgradient('z',gzlvl);
   delay(d2);
/* gradient switches off at end of acq. */

}