conv-tab_gramm-chg.pl 772 B

1234567891011121314151617181920212223242526272829303132333435
  1. #Change the grammar notation by introducing a conversion table file in place.
  2. open(FH,'<', 'BisonifyConversionTable');
  3. %NEWEXP = map { / *(.*?) +\|\|\|\| +(.*)/; "$1"=>"$2"; } (<FH>);
  4. open(FH, '<', 'newjava7.y');
  5. open(OFH, '>', 'newjava72.y');
  6. @LIST = (<FH>);
  7. foreach (@LIST) {
  8. @LIST2 = ($_);
  9. $lcurr = $_;
  10. foreach $K (keys %NEWEXP) {
  11. $k = $K;
  12. $k =~ s/([]{}.|[])/\\\1/g;
  13. while($lcurr =~ /$k/g) {
  14. $length = @LIST2;
  15. for ($i=0; $i<$length*2; $i+=2) {
  16. @LIST2 = (@LIST2[0..$i], @LIST2[$i..@LIST2-1]);
  17. $LIST2[$i] =~ s/$k//;
  18. $LIST2[$i+1] =~ s/$k/$NEWEXP{$K}/;
  19. }
  20. }
  21. }
  22. print OFH (@LIST2);
  23. }
  24. foreach $k (keys %NEWEXP){
  25. print OFH "\n";
  26. print OFH $NEWEXP{$k} . ":\n";
  27. $s = $k;
  28. $s =~ s/\{ *//;
  29. $s =~ s/ *\}$//;
  30. print OFH " $s\n";
  31. print OFH " | $NEWEXP{$k} $s\n";
  32. print OFH " ;\n";
  33. }