%{ use strict; use utf8; use Parse::DSLUtils qw(:all); use Data::Dumper; ###GRAM:state our %sem=(outputdir => "OUT", name=> "exercises"); my @semq=(); ###GRAM %} %token DIR VAL LB TEX Q BEG END ID CB INT %% A : dirs LB exs EOF {$sem{q}=[@semq];return "Ok";} ; dirs : dirs DIR VAL { $sem{$_[2]}=$_[3];} | dirs DIR CB { $sem{$_[2]}=$_[3];} | ; exs : exs Q BEG args END { push(@semq,["q",$_[4]]); } | exs P BEG args END { push(@semq,["t",$_[4]]); } | exs Q INT BEG args END { push(@semq,["q*",$_[3],$_[5]]); } | exs TEX { push(@semq,["tex",$_[2]]);} | ; args : IDs { ['choice', @{$_[1]}] } | ID CB CB CB { [$_[1],$_[2],$_[3],$_[4]] } ; IDs : IDs ',' ID { [@{$_[1]},$_[3]] } | ID { [$_[1]] } ; %% #sub myperleval{ # my ($b)=@_; # my $v=eval("$b") // $b; # _err(" in eval($b): $@ in Perl calculation") if $@; # if(ref($v) eq "ARRAY"){ return (vals => $v ) } # else { return (exp => $v ) } #} #sub myeval{ my $exp=shift; # my $v=eval("$exp") // $exp; # _err(" in eval($exp): $@ in Perl calculation") if $@; # $v #} sub _err { print STDERR "Error: $_[0]\n";$_[0]} sub _err_die{ print STDERR "Error: $_[0]\n";die();} #our ($debug,$lexdebug); my $yylineno = 0; my $n; our $yyFile ; ###LEX %dislex Parse.dislex ###--------------------------------------------------------------------- ### COMMON #sub lexdebug { yylexdebug(\&lex,$_[0]); } sub parseFile { @semq=(); %sem=(outputdir => "OUT", name=> "exercises"); yyinitfromfile($_[0]); parsecom(); } sub parseStr { @semq=(); %sem=(outputdir => "OUT", name=> "exercises"); yyinitfromstr($_[0]) ; parsecom(); } sub parsecom { ## my $p = new Exercise::Proc::Parse(); my $p = new (__PACKAGE__ ); $yyFile = _ppincludes($yyFile); ## from DSLUtils $p->YYParse( yylex => \&lex, yyerror => \&_yyerror); ## from DSLUtils } ###COMMON:input-slurp ##sub _A_yygetmore{ ## for compilers slurp utf8 mode ## use ----> yyinitfromfile($_[0]); ##} ###SEM:functions #sub slurptab{ # my %opt =(fs=>"::", comm=>1 , Dom => "Dom:" ); # if(ref($_[0]) eq "HASH") {%opt = (%opt , %{shift(@_)}) } ; # my @r; # my @extra=(); # open(F1,"<:utf8",$_[0]) or warn("###cant open $_[0]\n");; # my $aa; # while($aa=){ chomp($aa); # $aa=~ s/#.*// if $opt{comm}; # if($aa=~ s/^\+\+\s*(?:\w+\s*=\s*)?(.*)//) { # my $aux = $1; # if($aux =~ /\S/){ @extra = split(/\s*$opt{fs}\s*/,$aux)} # else { @extra = ();}} # next unless $aa=~ /\S/; # push(@r,[split(/\s*$opt{fs}\s*/,$aa),@extra])} # close F1; # print "#", Dumper(\@r) if $lexdebug; # \@r; #} 1; __END__ ## * texblocks id v type * ts id v (atom| [(FUN|CBB|BB|EXP),args}]) type card? rv (calculado a partir de v ou de equi(v)) atom | atom* (sem3) choice (int or int*) (sem4:rand) fv (v or v*) (sem5:repl) * order id* * equi id: l: sym* v sym = s1: at_id * type | s2: at_id * card * type | s3: