view tests/agcl/bugs/wraperror.syn @ 24:a4899cdfc2d6 default tip

Obfuscate the regexps to strip off the IBM compiler's copyright banners. I don't want bots scanning github to think they're real copyright notices because that could cause real problems.
author David A. Holland
date Mon, 13 Jun 2022 00:40:23 -0400
parents 13d2b8934445
children
line wrap: on
line source

{
/*
 * AnaGram, A System for Syntax Directed Programming
 * Copyright 2006 David A. Holland. All Rights Reserved.
 * See the file COPYING for license and usage terms.
 *
 * wraperror: test for wrappers and error token together
 */

#include <stdio.h>


struct thingy {
  const char *name;
  int val;

  void g(const char *n, int v) { name = n; val = v; }
  void g(const thingy &t) { name = t.name; val = t.val; }

  void m(const char *msg) {
    printf("%s %s: %p, %d\n", msg, name, this, val);
  }

  thingy(const char *n, int v)      { g(n,v); m("Constructed new"); }
  thingy(const thingy &t)           { g(t);   m("Copied"); }
  void operator = (const thingy &t) { g(t);   m("Assigned"); }
  ~thingy()                         {         m("Destroyed"); }
};

struct foo : public thingy {
  foo(int v) : thingy("foo", v) {}
  foo(const foo &f) : thingy(f) {}
  void operator = (const foo &f) { thingy::operator = (f); }
  ~foo() {}
};

struct bar : public thingy {
  bar(int v) : thingy("bar", v) {}
  bar(const bar &f) : thingy(f) {}
  void operator = (const bar &f) { thingy::operator = (f); }
  ~bar() {}
};

void do_foo(foo &f) {
  f.m("do_foo");
}

void do_bar(bar &b) {
  b.m("do_bar");
}

}

[
  parser file name = "#.cpp"
  wrapper { foo }
]

file $
  -> declarations, eof

declarations
  -> declaration...

declaration
  -> foo decl:f, '\n' = do_foo(f);
  -> bar decl:b, '\n' = do_bar(b);
  -> '\n'
  -> error

(foo) foo decl
  -> 'f', 'o', 'o' = foo(1);

(bar) bar decl
  -> 'b', 'a', 'r' = bar(2);

eof = 0

{

int main() {
   wraperror();
   return 0;
}

}