#!/usr/bin/perl

#undef $/;
#$/='';

%tnt = qw{
1  P
2  P
3  P
Act voz
C   modo
Fut T
FutP T
G modo
Gvo modo
Imp T
Ind modo
Inf modo
Ipr T
MQP T
Part modo
Pass voz
Perf T
Pres T
Sup modo
ab C
ac C
comp grau 
dat C
dep tran
t tran
x tran
f G
gen C
m G
n G
nom C
p N
pos grau
s N
spl grau
voc C
pr SUBCAT
};


while(<>){
  chomp;
  if(m!(\w+),(\w+),(\w+)(\+.*)!){ print p1($1,$2,$3,$4) }
  elsif(m!(\w+),(\w+)(\+.*)!){ print p2($1,$2,$3) }
  elsif(m!(\w+),(\w+)!){ print p2($1,$2,"") }
  else { print STDERR "$_\n" }
  print "\n";

}


sub p2{
 my ($p,$c,$t) = @_;
 my $para="";
 if($t =~ s/\+FLX=(\w+)//){ $para=$1 }
 $t =~  s![+](\w+)!,$tnt{$1}=$1!g;
 "$p/CAT=$c$t/$para/"
}

sub p1{
 my ($p,$p2,$c,$t) = @_;
 my $para="";
 if($t =~ s/\+FLX=(\w+)//){ $para=$1 }
 $t =~  s![+](\w+)!,$tnt{$1}=$1!g;
 "$p/\$$p2\$CAT=$c$t/$para/"
}