Пример #1
0
// Build a list of rule references with the given node
static void bnf_rule_set(bnf_t* bnf, const char** rules)
{
  assert(bnf != NULL);

  for(int i = 0; rules[i] != NULL; i++)
  {
    bnf_t* p = bnf_add(bnf_create(BNF_RULE), bnf);
    assert(p != NULL);
    p->name = rules[i];
  }
}
Пример #2
0
// Build a list of token references with the given node
static void bnf_token_set(bnf_t* bnf, token_id* tokens, bool clean)
{
  pony_assert(bnf != NULL);

  for(int i = 0; tokens[i] != TK_NONE; i++)
  {
    bnf_t* p = bnf_add(bnf_create(BNF_TOKEN), bnf);
    pony_assert(p != NULL);

    //token_id next = tokens[i + 1];

    switch(tokens[i])
    {
      // Special case tokens
      case TK_EOF: p->name = ""; break;
      case TK_STRING: p->name = "STRING"; break;
      case TK_INT: p->name = "INT"; break;
      case TK_FLOAT: p->name = "FLOAT"; break;
      case TK_ID: p->name = "ID"; break;
      case TK_LPAREN_NEW: p->name = "LPAREN_NEW"; break;
      case TK_LSQUARE_NEW: p->name = "LSQUARE_NEW"; break;
      case TK_MINUS_NEW: p->name = "MINUS_NEW"; break;
      case TK_MINUS_TILDE_NEW: p->name = "MINUS_TILDE_NEW"; break;

      default:
        // Fixed text tokens: keywords, symbols, etc
        p->name = lexer_print(tokens[i]);
        p->id = BNF_QUOTED_TOKEN;

        pony_assert(p->name != NULL);

        if((clean && p->name[0] == '$') || tokens[i] == TK_NEWLINE)
        {
          // Remove unclean symbol
          p->id = BNF_NEVER;
        }

        break;
    }
  }
}