%{ use strict; use Text::TabDB; my $_tmpaux=0; my %set=(style => 1); %} %token Ids Cond T %left '*' %left '[' %left '{' %% C : C Exp '\n' { tshow($_[2]); } | C Exp '?' '\n' { tedit($_[2]); } | C T ':' T '\n' { $set{$_[2]} = $_[4]; } | C '\n' { } | C error '\n' { $_[0]->YYErrok; } | ; Exp : T { $_[1]; } | '.' { "_aux$_tmpaux"; } | Exp '[' Ids ']' { tproj($_[3], $_[1]); } | '(' Exp ')' { $_[2]; } | Exp '*' Exp { tjoin($_[1],$_[3]); } | Exp '{' Cond '}' { tselect($_[3], $_[1]); } | T '=' Exp { cp($_[3],$_[1]); } ; %% sub tedit { system "vi '$_[0]'" } sub tshow { if( $set{style}==1 ){ system "cat '$_[0]'" } if( $set{style}==2 ){ Text::TabDB::tabconv({format=>"term"},$_[0]) } if( $set{style}==3 ){ Text::TabDB::tabconv({format=>"thesaurus"},$_[0]) } } sub cp { system "cp '$_[0]' '$_[1]'"; $_[1] } sub tproj { my $t=tmp(); Text::TabDB::tabproj({o=>$t},$_[0],$_[1]); $t} sub tselect{ my $t=tmp(); Text::TabDB::tabselect({o=>$t},$_[0],$_[1]); $t} sub tjoin { my $t=tmp(); Text::TabDB::tabjoin({err=>"##",all=>1,o=>$t},$_[0],$_[1]); $t} sub tmp { "_aux". ++$_tmpaux } package main; use Data::Dumper; use Term::ReadLine; my $term = new Term::ReadLine ; #my $attrs = $term->Attribs; #$attrs->{completion_entry_function} = $attrs->{list_completion_function}; #$attrs->{completion_word} = [ @words ]; $term->ornaments(0); my $yyst = 0; my $File = ""; my $t = parseFile(); #gera(); sub parseFile { my $p = new tabsh(); $p->YYParse( yylex => \&lex, yyerror => \&yyerror); } # sub gera{ # my $s = init_skel(); # ## $s =~ s/####(\w+)####/$tab{$1}/g ; # print $s;} # # sub init_skel{ # my $skel = <<'ENDSKEL'; # my $tree=####TTTT#### # ENDSKEL # } sub yyerror { if ($_[0]->YYCurtok) { printf STDERR ('Error: a "%s" (%s) was found where %s was expected'."\n", $_[0]->YYCurtok, $_[0]->YYCurval, $_[0]->YYExpect) } else { print STDERR "Expecting one of ",join(", ",$_[0]->YYExpect),"\n"; } } sub yygetmore{ ## for interpreters : readline $File = $term->readline("?- "); if(defined $File){ $term->addhistory($File) if $File =~ /\S/; $File .= "\n"} else { $File = "__EOF__";} } sub _2_yygetmore{ ## for interpreters (one line at the time) local $/; $/ = "\n"; $File = <> || "__EOF__"; } sub _3_yygetmore{ ## for compilers local $/; undef $/; $File = <> . "__EOF__"; } sub lex{ ## %x Indices=1 Condiçao=2 --> $yyst for($File){ s!^[ \t]+!!; ## avançar brancos if($_ eq "") { yygetmore();return(lex()) } if( s!^__EOF__!!) { return("","") } if($yyst==0 and s!^(\w+)!! ) { return("T",$1); } if($yyst==0 and s!^([?=.:*\(\)}\]\n])!!){ return($1,$1); } if($yyst==0 and s!^([\[])!!) { $yyst = 1 ; return($1,$1); } if($yyst==0 and s!^([\{])!!) { $yyst = 2 ; return($1,$1); } if($yyst==1 and s!^([^\]]+)!!) { $yyst = 0 ; return("Ids",$1); } if($yyst==2 and s!^([^\}]+)!!) { $yyst = 0 ; return("Cond",$1);} if(s!(.)!!) { print STDERR "Simbolos desconhecidos '$File'\n" ; return lex(); } } }