<commit_before>/*
    Copyright (C) 2015 <NAME>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

    Contact: <NAME> <<EMAIL>>,
    Heidelberg Institute for Theoretical Studies,
    Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
*/
%{
#include "pll.h"

extern int pll_utree_lex();
extern FILE * pll_utree_in;
extern void pll_utree_lex_destroy();

static int tip_cnt = 0;

static void dealloc_tree_recursive(pll_utree_t * node)
{
  if (!node->next)
  {
    free(node->label);
    free(node);
    return;
  }

  dealloc_tree_recursive(node->next->back);
  dealloc_tree_recursive(node->next->next->back);

  free(node->next->next);
  free(node->next);
  free(node->label);
  free(node);
}

void pll_destroy_utree(pll_utree_t * root)
{
  if (!root) return;
  if (!(root->next))
  {
    free(root->label);
    free(root);
    return;
  }

  if (root->next)
    dealloc_tree_recursive(root->next->back);
  if (root->next->next)
    dealloc_tree_recursive(root->next->next->back);
  if (root->back)
    dealloc_tree_recursive(root->back);

  free(root->label);
  free(root->next->next);
  free(root->next);
  free(root);
}

static void pll_utree_error(pll_utree_t * tree, const char * s) 
{
  fprintf(stderr, "%s.\n", s);
}

%}

%union
{
  char * s;
  char * d;
  struct pll_utree * tree;
}

%error-verbose
%parse-param {struct pll_utree * tree}
%destructor { pll_destroy_utree($$); } subtree

%token OPAR
%token CPAR
%token COMMA
%token COLON SEMICOLON 
%token<s> STRING
%token<d> NUMBER
%type<s> label optional_label
%type<d> number optional_length
%type<tree> subtree
%start input
%%

input: OPAR subtree COMMA subtree COMMA subtree CPAR optional_label optional_length SEMICOLON
{
  tree->next               = (pll_utree_t *)calloc(1, sizeof(pll_utree_t));

  tree->next->next         = (pll_utree_t *)calloc(1, sizeof(pll_utree_t));


  tree->back               = $2;
  tree->next->back         = $4;
  tree->next->next->back   = $6;

  tree->label              = $8;
  tree->next->label        = $8;
  tree->next->next->label  = $8;

  tree->length             = $2->length;
  tree->next->length       = $4->length;
  tree->next->next->length = $6->length;
  free($9);
};

subtree: OPAR subtree COMMA subtree CPAR optional_label optional_length
{
  $$                     = (pll_utree_t *)calloc(1, sizeof(pll_utree_t));

  $$->next               = (pll_utree_t *)calloc(1, sizeof(pll_utree_t));

  $$->next->next         = (pll_utree_t *)calloc(1, sizeof(pll_utree_t));


  $$->next->back         = $2;
  $$->next->next->back   = $4;

  $$->label              = $6;<commit_msg>fixed back pointers in utree parsing<commit_after>/*
    Copyright (C) 2015 <NAME>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

    Contact: <NAME> <<EMAIL>>,
    Heidelberg Institute for Theoretical Studies,
    Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
*/
%{
#include "pll.h"

extern int pll_utree_lex();
extern FILE * pll_utree_in;
extern void pll_utree_lex_destroy();

static int tip_cnt = 0;

static void dealloc_tree_recursive(pll_utree_t * node)
{
  if (!node->next)
  {
    free(node->label);
    free(node);
    return;
  }

  dealloc_tree_recursive(node->next->back);
  dealloc_tree_recursive(node->next->next->back);

  free(node->next->next);
  free(node->next);
  free(node->label);
  free(node);
}

void pll_destroy_utree(pll_utree_t * root)
{
  if (!root) return;
  if (!(root->next))
  {
    free(root->label);
    free(root);
    return;
  }

  if (root->next)
    dealloc_tree_recursive(root->next->back);
  if (root->next->next)
    dealloc_tree_recursive(root->next->next->back);
  if (root->back)
    dealloc_tree_recursive(root->back);

  free(root->label);
  free(root->next->next);
  free(root->next);
  free(root);
}

static void pll_utree_error(pll_utree_t * tree, const char * s) 
{
  fprintf(stderr, "%s.\n", s);
}

%}

%union
{
  char * s;
  char * d;
  struct pll_utree * tree;
}

%error-verbose
%parse-param {struct pll_utree * tree}
%destructor { pll_destroy_utree($$); } subtree

%token OPAR
%token CPAR
%token COMMA
%token COLON SEMICOLON 
%token<s> STRING
%token<d> NUMBER
%type<s> label optional_label
%type<d> number optional_length
%type<tree> subtree
%start input
%%

input: OPAR subtree COMMA subtree COMMA subtree CPAR optional_label optional_length SEMICOLON
{
  tree->next               = (pll_utree_t *)calloc(1, sizeof(pll_utree_t));

  tree->next->next         = (pll_utree_t *)calloc(1, sizeof(pll_utree_t));


  tree->back               = $2;
  tree->next->back         = $4;
  tree->next->next->back   = $6;

  $2->back                 = tree;
  $4->back                 = tree->next;
  $6->back                 = tree->next->next;

  tree->label              = $8;
  tree->next->label        = $8;
  tree->next->next->label  = $8;

  tree->length             = $2->length;
  tree->next->length       = $4->length;
  tree->next->next->length = $6->length;
  free($9);
};

subtree: OPAR subtree COMMA subtree CPAR optional_label optional_length
{
  $$                     = (pll_utree_t *)calloc(1, sizeof(pll_utree_t));

  $$->next               = (pll_utree_t *)calloc(1, sizeof(pll_utree_t));

  $$->next->next         = (pll_utree_t *)calloc(1, sizeof(pll_utree_t));


  $$->next->back         = $2;
  $$->next->next->back   = $4;

  $2->back               = $$->next;
  $4->back               = $$->next->next;

  $$->label              = $6;
{'fraction_non_alphanumeric': 0.138796992481203, 'fraction_numerical': 0.010075187969924812, 'mean_word_length': 2.987410071942446, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 154, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5405413', 'n_tokens_mistral': 2427, 'n_tokens_neox': 2303, 'n_words': 586}