#!/Utils/bin/perl
#/*
# * The Termprocessor Kimwitu
# *
# * Copyright (c) 1991-1996 University of Twente, Dept TIOS.
# * All rights reserved.
# *
# */
#/*
# * $Id: errmsg.pl,v 1.1 1996/12/09 08:58:20 belinfan Rel $
# */
#*****************************************************************************
#
#   *** Copyright (c) Humboldt University of Berlin, Germany,
#   *** Department of Computer Science.
#   *** All rights reserved.
#
#    File    : errmsg.pl
#    Author  : Matthias Schwalbe
#    e-mail  : schwalbe@informatik.hu-berlin.de
#    Project : SDL'92-Compiler 2.x, Incrementel Parser 
#    Date    : Mon Nov 21 20:15:35 GMT-0100 1994
#    Remark  : may not work on other bison versions
#    History : 
#
#******************************************************************************/ 

while(<>){
    if(/^state 0/){
	last;
    }
}

print <<EOF;
#include "errmsg.h"

char *error_message[][3] = {
EOF

$nonterm="";
$term="";
$rules="\\n";

while(<>){
    $foo = $_;
    if($foo =~ /^state [0-9]+/){
	$term =~ s/\"/\\\"/g;
	$rules =~ s/\"/\\\"/g;
	$rules =~ s/\\n\\t$//g;
	print "{\n\"$nonterm\",\n\"$term\",\n\"$rules\"\n},\n";
	$term = "";
	$nonterm = "";
	$rules = "\\n\\t";
    }
    elsif($foo =~ /^\s*(\S*)\s*go to state/){
	if(! $nonterm == ""){
	    $nonterm .= " ";
	}
	$nonterm .= $1;
    }
    elsif($foo =~ /^\s*(\S*)\s*shift, and go to state/){
	if(! $term == ""){
	    $term .= " ";
	}
	$term .= $1;
    }
    elsif($foo =~ /^\s*(\S*)\s*\[?reduce using rule/){
    }
    elsif($foo =~ /^\s*(\S*\s*->.*)\(rule [0-9]+\)/){
	$bar = $1;
	$bar =~ s/\s*$//;
	$bar =~ s/  ->  / -> /;
    if($bar !~ /\serror/){ 
	$rules .= $bar;
	$rules .= "\\n\\t";
    }
    }
    elsif($foo =~ /^\s*\S*\s*error/){
    }
    elsif($foo =~ /^\s*\$default\s*accept/){
    }
    elsif($foo =~ /\S/){
	print "reminder :  $foo";
    }
}

print <<EOF;
{0,0,0}};
EOF
