aboutsummaryrefslogtreecommitdiffstats
path: root/utils/Burg/pattern.c
blob: 2ff72e7c410a869870ebf3e3effea3bb246d70d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
char rcsid_pattern[] = "$Id$";

#include <stdio.h>
#include "b.h"

Pattern
newPattern(op) Operator op;
{
  Pattern p;

  p = (Pattern) zalloc(sizeof(struct pattern));
  p->op = op;
  return p;
}

void
dumpPattern(p) Pattern p;
{
  int i;

  if (!p) {
    printf("[no-pattern]");
    return;
  }

  if (p->op) {
    printf("%s", p->op->name);
    if (p->op->arity > 0) {
      printf("(");
      for (i = 0; i < p->op->arity; i++) {
        printf("%s ", p->children[i]->name);
      }
      printf(")");
    }
  } else {
    printf("%s", p->children[0]->name);
  }
}