#!/usr/bin/perl6
# nnnnnnnnnnnnnnnn
my $origRwcode= ''; my $lastRwcode= ''; my $lastRwcodeDef= '';
$origRwcode=
'
stepThru3
( @@1(term [^^4[11][22][33][44][myMapping]] [say(concat[hello][,][%][World])]) )
( say(^^4[11][22][33][44][myMapping]) )
[ say(concat[hello][ ][World]) ]
';
$origRwcode=
'
goTo0
[ TelService ]
[1__CODES
(@@8
( proc :TelService :0 {::: @@1 :CallSession :::} )
( proc :CallSession :4
: {:::
: stepThru1
: ( cTerm2 :~2 :~3 [PerEvntActnList] )
: [
: : goTo0
: : [ TelService ]
: : [ ~1 ]
: : ( cTerm2 :~2 :~3 [NxtStateMap] )
: ]
: :::}
)
( term [cTerm2 :onhook [dialDigit:4] [PerEvntActnList]] [say(concat:hello[,][ ]:World)] )
( term [cTerm2 :offhook :dialDigit6 [PerEvntActnList]] [say(concat:lets[ ]:talk)] )
( term [cTerm2 :talking [dialDigit:8] [PerEvntActnList]] [say(concat:seeya[,][ ]:bye)] )
( term [cTerm2 :onhook [dialDigit:4] [NxtStateMap]] :offhook )
( term [cTerm2 :offhook :dialDigit6 [NxtStateMap]] :talking )
( term [cTerm2 :talking [dialDigit:8] [NxtStateMap]] :disconnect )
) ]
[2__CURSTATE :onhook ]
[3__EVENT [dialDigit:4] ]
:dialDigit6
[dialDigit:8]
';
my $setup= 1;
my $stopredOP= ''; my $stopredWhileMin= 0; my $stopredWhileMax= 0; my @stopredWFEcompArgList= Nil;
my %*TERMS{Any}; my %*VARS{Any}; my %*VAR{Any}; my %*PROCS{Any}; my %*PROCSparmNum{Any};
my %*stateROM; my %*actionsROM; my %*AssocListArg0; my %*AssocListArg1;
my %*GOTOARGNAMES{Any};
my @savedsr2WFEcompArgList= Nil;my @savedsr2tempLeftBrace= Nil;
my @savedsr2tempRightBrace= Nil;my $savedsr2rewriteArgListElems= 0;
my @tempWFEcompArgList= Nil;my @WFEcompArgListSav= Nil;my @tempLeftBraceSav= Nil;
my @tempRightBraceSav= Nil;my $compareMax= 0;my $rewriteArgListElemsSav= 0;
my $input= ''; my $tp0= ''; my $tp1= ''; my $tp2= ''; my $symbType= ''; my $output= 1; my $saySuccess= 0;
my $addMultSuccess= 0; my @tempStmt= Nil; my $noSkips= 1; my $wrongArgTypes= 0; my @OPstr= Nil; my $OPsav= Nil; my $OPsav2= Nil;
my @OPvariety= Nil; my @entryTempoeName= Nil; my $tempInt= 9999; my $srMax= -1; my @AssocComp0= Nil;
my @AssocComp1= Nil; my @ARGLISTrankForGivenLevelAlreadyInitialized= Nil; my @ARGLISTrankInGivenARGLISTlevel= Nil;
my $BIStemp2= 0; my $BIStemp22= 0; my @BISelemsTotalOfListOfWFErewritesForGivenARGLISTruleRun= Nil;
my @BISlistOfWFErewritesForGivenARGLISTruleRun= Nil; my @BISlistOfWFEbraceTypesForGivenARGLISTruleRun= Nil;
my $BIStempCurWFEbrace= ''; my @curWFEbraceForGivenActnum= Nil; my @isBaseBISlistOfWFEbraceTypesForGivenARGLISTruleRun= Nil;
my $entryWFE= ''; my $entryWFE2= ''; my $entryWFE4= ''; my $entryWFE6= ''; my $entryWFE66= ''; my $entryWFE7= ''; my $actualTemplate= ''; my $tmplateStr= ''; my $tmplateOP= 0;
my $debug= 0; my $debug2= 1; my $debug4= 0;
my $englobingNoRWdegree= 0; my $curBrace= ''; my @listOfCurBraces= Nil;
my @BraceTypeOfComponentWFEatGivenIndexInWFElistOfARGLISTatGivenSrLevel= Nil;
my @currentARGLISTlistOfBraceTypesOfComponentWFEs= Nil;
my @currentARGLISTlistOflistOfOPvarietyOfComponentWFEs= Nil;
my $tempLeftBrace= ''; my $tempRightBrace= ''; my @tempLeftBrace= Nil; my @tempRightBrace= Nil;
my @curbraceL= Nil; my @curbraceIdx= Nil; my $ttp= ''; my $tmplateNumOfParms= 0;
my $b12 = ' '; my $i= '|'; my $l= ':'; my $temp1= 'blank'; my $temp2= 0; my $temp4= 0; my $temp6= 0; my $rewriteWFE= '';
my @curWFEbrace= Nil; my @curWFEopVariety= Nil; my $curIdx= 999; my $curIdx2= 999; my $curIdx4= 999; my $sr= 0; my $srw= -1;
my $rewriteArgListElems= 0; my @tempArgList= Nil; my $rewriteArgList= ''; my @WFEcompArgList= Nil; my @WFEcompArgListTemp= Nil;
my @methodStepOfCallingARGLISTrun= Nil; my @WFEcompArgListTemp2= Nil;
my @elemsTotalOfListOfWFErewritesForGivenARGLISTruleRun= Nil; my @listOfWFErewritesForGivenARGLISTruleRun= Nil;
my @listOfWFEbraceTypesForGivenARGLISTruleRun= Nil; my @listOfOPvarietyForGivenARGLISTruleRun= Nil;
my @rewriteArgList= Nil; my $stopreduction= 0; my $needNewDescend= 0; my $rwcode= ''; my $match2= ''; my $lastRunNum= -1;
my $runNum= 0; my $continue= 0; my @tmplateList= Nil; my $parmSubstnResult= ''; my @parm= Nil;
sub fillRestOfArgsV1($startCurIdx) {
my $curLocal= $startCurIdx;
$stopredOP= $rewriteWFE; $stopredWhileMin= $curLocal; $stopredWhileMax= $rewriteArgListElems;
while $curLocal < $rewriteArgListElems {
@stopredWFEcompArgList[$curLocal]= @WFEcompArgList[$curLocal];
$rewriteWFE= $rewriteWFE ~ '[' ~ @WFEcompArgList[$curLocal] ~ ']';
$curLocal= 1 + $curLocal;
};
};
sub trimBrackets(Str $x) {
my $local= $x;
$local= $local.subst( :g , / '@@1(' (.+?) ')[equals]' / , -> $/ { '{' ~ $0 ~ '}[equals]' } );
$local= $local.subst( :g , /^'['([<[a..zA..Z0..9]> | '_' ]+ | \d+)']' / , -> $/ { 'QWWw:' ~ $0 } );
$local= $local.subst( :g , / '['([<[a..zA..Z0..9]> | '_' ]+ | \d+)']' / , -> $/ { ' :' ~ $0 } );
$local= $local.subst( :g , /^('QWWw:') / , -> $/ { ':' } );
$local= $local.subst( :g , / '[@@2 :'([<[a..zA..Z0..9]> | '_' ]+ | \d+)' :'([<[a..zA..Z0..9]> | '_' ]+ | \d+)']' / , -> $/ { '< :' ~ $0 ~ ' :' ~ $1 ~ ' >' } );
$local= $local.subst( :g , / '[~'(\d+)']' / , -> $/ { ' :~' ~ $0 } );
$local= $local.subst( :g , / '[@@2 :'([<[a..zA..Z0..9]> | '_' ]+ | \d+)' :~'(\d+)']' / , -> $/ { '< :' ~ $0 ~ ' :~' ~ $1 ~ ' >' } );
$local= $local.subst( :g , / '[@@2 :~'(\d+)' :'([<[a..zA..Z0..9]> | '_' ]+ | \d+)']' / , -> $/ { '< :~' ~ $0 ~ ' :' ~ $1 ~ ' >' } );
$local= $local.subst( :g , / '[@@2~'(\d+)' :~'(\d+)']' / , -> $/ { '< ~' ~ $0 ~ ' :~' ~ $1 ~ ' >' } );
$local= $local.subst( :g , / '['(\%+)']' / , -> $/ { { '[' ~ "{' ' x$0.chars}" ~ ']' } } );
$local= $local.subst( :g , /^(\%+)$/ , -> $/ { { "{' ' x$0.chars}" } } );
$local= $local.subst( :g , / (''\d+) ('__') (<[A..Z]>[<[A..Z0..9]> | '_' ]*) '[' / , -> $/ { $0 ~ $1 ~ $2 ~ ' [' } );
$local= $local.subst( :g , / (''\d+) ('__') (<[A..Z]>[<[A..Z0..9]> | '_' ]*) '(' / , -> $/ { $0 ~ $1 ~ $2 ~ ' (' } );
$local= $local.subst( :g , / (''\d+) ('__') (<[A..Z]>[<[A..Z0..9]> | '_' ]*) '<' / , -> $/ { $0 ~ $1 ~ $2 ~ ' <' } );
$local= $local.subst( :g , / '< :'(\d+)' :'([<[a..zA..Z0..9]> | '_' ]+ | \d+)' >' / , -> $/ { '<:' ~ $0 ~ ':' ~ $1 ~ '>' } );
$local= $local.subst( :g , / ('subItem[') / , -> $/ { 'subItem [' } );
$local= $local.subst( :g , / ('subItem(') / , -> $/ { 'subItem (' } );
$local= $local.subst( :g , / ('subItem<') / , -> $/ { 'subItem <' } );
$local= $local.subst( :g , / ('subItem:') / , -> $/ { 'subItem :' } );
$local= $local.subst( :g , / ('subVar[') / , -> $/ { 'subVar [' } );
$local= $local.subst( :g , / ('subVar(') / , -> $/ { 'subVar (' } );
$local= $local.subst( :g , / ('subVar<') / , -> $/ { 'subVar <' } );
$local= $local.subst( :g , / ('subVar:') / , -> $/ { 'subVar :' } );
$local= $local.subst( :g , / ('proc[') / , -> $/ { 'proc [' } );
$local= $local.subst( :g , / ('proc(') / , -> $/ { 'proc (' } );
$local= $local.subst( :g , / ('proc<') / , -> $/ { 'proc <' } );
$local= $local.subst( :g , / ('proc:') / , -> $/ { 'proc :' } );
$local= $local.subst( :g , / ('term[') / , -> $/ { 'term [' } );
$local= $local.subst( :g , / ('term(') / , -> $/ { 'term (' } );
$local= $local.subst( :g , / ('term<') / , -> $/ { 'term <' } );
$local= $local.subst( :g , / ('term:') / , -> $/ { 'term :' } );
$local= $local.subst( :g , / 'stepThru'(\d+)'[' / , -> $/ { 'stepThru' ~ $0 ~ ' [' } );
$local= $local.subst( :g , / 'stepThru'(\d+)'(' / , -> $/ { 'stepThru' ~ $0 ~ ' (' } );
$local= $local.subst( :g , / 'stepThru'(\d+)'<' / , -> $/ { 'stepThru' ~ $0 ~ ' <' } );
$local= $local.subst( :g , / 'stepThru'(\d+)':' / , -> $/ { 'stepThru' ~ $0 ~ ' :' } );
$local= $local.subst( :g , / ('(@@')(\d+) / , -> $/ { '( @@' ~ $1 } );
$local= $local.subst( :g , / ('[@@')(\d+) / , -> $/ { '[ @@' ~ $1 } );
$local= $local.subst( :g , / ('[<:::') / , -> $/ { ' {::: ' } );
$local= $local.subst( :g , / (':::>]') / , -> $/ { ' :::}' } );
$local= $local.subst( :g , / ('@@')(\d+)('(') / , -> $/ { $0 ~ $1 ~ ' (' } );
$local= $local.subst( :g , / ('@@')(\d+)('[') / , -> $/ { $0 ~ $1 ~ ' [' } );
$local= $local.subst( :g , / ('@@')(\d+)('<') / , -> $/ { $0 ~ $1 ~ ' <' } );
$local= $local.subst( :g , / (':equals') / , -> $/ { '==' } );
$local= $local.subst( :g , / '@@1 (' (.+?) ') ==' / , -> $/ { '{' ~ $0 ~ '} ==' } );
## $local= $local.subst( :g , / '@@1 (' ('~'\d+) ') ==' / , -> $/ { '{' ~ $0 ~ '} ==' } );
};
sub normalizeOrigCodes(Str $x) {
my $local= $x;
$local= $local.subst( :g , / ('==') / , -> $/ { ':equals' } );
$local= $local.subst( :g , / ('{:::') / , -> $/ { '[<:::' } );
$local= $local.subst( :g , / (':::}') / , -> $/ { ':::>]' } );
$local= $local.subst( :g , / (' : ') / , -> $/ { ' ' } );
$local= $local.subst( :g , / 'Run' / , -> $/ { 'goTo0' } );
$local= $local.subst( :g , / '('<[A..Z]>[<[A..Z0..9]> | '_' ]*','\s* / , -> $/ { '( ' } );
$local= $local.subst( :g , / '['<[A..Z]>[<[A..Z0..9]> | '_' ]*','\s* / , -> $/ { '[ ' } );
$local= $local.subst( :g , / '[' (\s+) ']' / , -> $/ { '[' ~ "{'%' x$0.chars}" ~ ']' } );
$local= $local.subst( :g , / '(' \s* [<[a..zA..Z]>]+ '## ' \s* / , -> $/ { '(' } );
$local= $local.subst( :g , / '[' \s* [<[a..zA..Z]>]+ '## ' \s* / , -> $/ { '[' } );
$local= $local.subst( :g , / '[' ([[<[a..z0..9;,]>]+]+)(\s*) ']' / , -> $/ { '[' ~ $0 ~ "{'#' x$1.chars}" ~ ']' } );
$local= $local.subst( :g , / (\s+) / , -> $/ { '' } );
$local= $local.subst( :g , / ([<[#]>]+) / , -> $/ { "{' ' x$0.chars}" } );
$local= $local.subst( :g , / ('<:::') / , -> $/ { '&&x&&' } );
$local= $local.subst( :g , / (':::>') / , -> $/ { '&&y&&' } );
$local= $local.subst( :g , / (':~')(\d+) ('__') (<[A..Z]>[<[A..Z0..9]> | '_' ]*) / , -> $/ { '[' ~ '~' ~ $1 ~ ']' } );
$local= $local.subst( :g , / (':~')(\d+) / , -> $/ { '[' ~ '~' ~ $1 ~ ']' } );
$local= $local.subst( :g , / ('<') / , -> $/ { '[@@2' } );
$local= $local.subst( :g , / ('>') / , -> $/ { ']' } );
$local= $local.subst( :g , / ('&&x&&') / , -> $/ { '<:::' } );
$local= $local.subst( :g , / ('&&y&&') / , -> $/ { ':::>' } );
$local= $local.subst( :g , / (':::') / , -> $/ { '&&&&' } );
$local= $local.subst( :g , / ':' (\d+) / , -> $/ { '-' ~ $0 } );
$local= $local.subst( :g , / ':' ([<[a..zA..Z0..9]> | '_' ]+ | \d+) / , -> $/ { '-' ~ $0 } );
$local= $local.subst( :g , / ('&&&&') / , -> $/ { ':::' } );
$local= $local.subst( :g , / '-' (\d+) / , -> $/ { '[' ~ $0 ~ ']' } );
$local= $local.subst( :g , / '-' ([<[a..zA..Z0..9]> | '_' ]+ | \d+) / , -> $/ { '[' ~ $0 ~ ']' } );
$local= $local.subst( :g , / ('proc[') ([<[a..zA..Z0..9]> | '_' ]+ | \d+) ('][') (\d+) (']{:::') (.+?) (':::}') / , -> $/ { $0 ~ $1 ~ $2 ~ $3 ~ '][<:::' ~ $5 ~ ':::>]' } );
$local= $local.subst( :g , / ('proc[') ([<[a..zA..Z0..9]> | '_' ]+ | \d+) ('][') (\d+) (']{') (.+?) ('}') / , -> $/ { $0 ~ $1 ~ $2 ~ $3 ~ '][<:::' ~ $5 ~ ':::>]' } );
$local= $local.subst( :g , / '{' (.+?) '}' / , -> $/ { '@@1(' ~ $0 ~ ')' } );
## $local= $local.subst( :g , / '{' ('~'\d+) '}' / , -> $/ { '@@1(' ~ $0 ~ ')' } );
};
$lastRwcodeDef=
'
stepThru1
';
$lastRwcode= normalizeOrigCodes($lastRwcodeDef);
say "\n\n\n\nOriginal Codes: ";
say "---------------\n\n$origRwcode ";
say "\n\n\nNormalized Codes: ";
say "-----------------\n\n{normalizeOrigCodes($origRwcode)} \n\n";
$rwcode= '';
grammar Rewrite4
{
rule TOP {
{
if $sr > $srMax {
$srMax= $sr;
};
$englobingNoRWdegree= 0;
$sr++;
}
<WFE>
{$sr--;}
};
rule WFE {
{
$srw++;
if $sr > $srMax {
$srMax= $sr;
};
if $sr == 1 {
@BISelemsTotalOfListOfWFErewritesForGivenARGLISTruleRun[$sr + 3]= -1;
}
else {
if @BISelemsTotalOfListOfWFErewritesForGivenARGLISTruleRun[$sr + 1] == -1 {
@BISelemsTotalOfListOfWFErewritesForGivenARGLISTruleRun[$sr + 3]= -1;
};
$BIStemp2= @BISelemsTotalOfListOfWFErewritesForGivenARGLISTruleRun[$sr + 1] + 1;
$BIStemp22= @BISelemsTotalOfListOfWFErewritesForGivenARGLISTruleRun[$sr + 1] + 1;
@BISelemsTotalOfListOfWFErewritesForGivenARGLISTruleRun[$sr + 1]= $BIStemp2;
};
if $sr > 2 {
if $runNum > 0 {
if @curWFEbrace[$sr - 1] === '[' {
if $englobingNoRWdegree == 0 {
$englobingNoRWdegree= 1;
@isBaseBISlistOfWFEbraceTypesForGivenARGLISTruleRun[$sr + 1][$BIStemp2]= 1;
}
else {
@isBaseBISlistOfWFEbraceTypesForGivenARGLISTruleRun[$sr + 1][$BIStemp2]= 0;
$englobingNoRWdegree++;
};
}
else {
@isBaseBISlistOfWFEbraceTypesForGivenARGLISTruleRun[$sr + 1][$BIStemp2]= 0;
};
};
};
@OPvariety[$sr]= 'na';
$sr++;
$tmplateOP= 0;
}
<OP> <ARGLIST>
{$sr--;}
};
rule ARGLIST {
{
if $sr > $srMax {
$srMax= $sr;
};
@curbraceIdx[$sr]= 0;
$sr++;
}
[<ARG>]*
{$sr--;}
};
rule ARG {
[(['('|'[']){@curWFEbrace[$sr - 1]= $0.Str;}<.eol>* <WFE>[')'|']']]
};
proto token OP {*}
token OP:sym<NUM> { <NUM> }
token NUM {
\d+
};
token OP:sym<OP3> { <OP3> }
token OP3 {
<:alpha>\w*
# <[a..zA..Z]>[<[a..z0..9]>]*
};
token OP:sym<OP5> { <OP5> }
token OP5 {
'id'|'term'|'proc'|'subItem'|'subVar'|'maps'|'isVector'|'isSubstnTemplate'|'isPointy'|'concat'|'string'|'selfRepeat'|'cTerm'\d+|'@@'\d+|'add'|'sub'|'mult'|'IF'|\w+'::='\d+'='|'goTo'\d+|'say'|'dcl'|'stepThru'\d+
};
token OP:sym<OP2> { <OP2> }
token OP2 {
[[[<[a..zA..Z0..9]> | '_' ]+]]|'defTerm'|'defProc'|'ERROR'|'nil'|'hellotwelve'|'two'|'four'|'six'|'offhook'|'('|')'|'['|']'|'$'|'; '|': '|':'|'<<'|'>>'|'vector'|'~'|'+'|'-'|'='|'&'|'!'|'*'|'"'|'/'|"\\"|"\'"|[\%+]|[\.+]|[\,+]|[\;+]
};
token OP:sym<PROC2> { <PROC2> }
token PROC2 {
'%'\d+ [<ARG>]+
};
token OP:sym<PROC> { <PROC> }
token PROC {
['<' \s* [<OP><ARGLIST>] \s* [[';'] \s* [<OP><ARGLIST>] \s*]* '>']
};
token OP:sym<OP6> { <OP6> }
token OP6 {
'<:::' \s* ['.'|'@@'|'__'|'@'|'('|'='|','|'['|')'|']'|'~'|\d|\w|\n|\s]+ \s* ':::>'
};
token eol { [ <[#;]> \N* ]? \n };
};
class RewriteAction4 {
method TOP($/) {
$/.make($rewriteWFE);
$stopreduction= 0;
$needNewDescend= 0;
};
method WFE($/) {
$stopredOP= ''; $stopredWhileMin= 0; $stopredWhileMax= 0;
$wrongArgTypes= 0;
$saySuccess= 0;
$addMultSuccess= 0;
@OPstr[$sr]= $<OP>.Str;
if $runNum > 0 {
if $lastRunNum < $runNum {
$lastRunNum= $runNum;
say " " if $debug; say " " if $debug; say " " if $debug;
if $runNum == 1 {$entryWFE2= normalizeOrigCodes($origRwcode);} else {$entryWFE2= $rwcode;};
say "\n\n\n " if (($debug4 == 1) and (not($debug2 == 1)));
say "\n\n" if (($debug4 == 1) and ($debug2 == 1));
say "\n\n\n\n==========================================================================>" if (($debug2 == 1) and ($debug4 == 0));
say "\( TREE DESCEND #{$runNum}: \)" if (($debug2 == 1) and ($debug4 == 0));
say ". . . . . . " if (($debug2 == 1) and ($debug4 == 0));
if $runNum == 1 {
say '"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""' if $debug4;
say "\( STARTING TREE DESCEED #1: \)\n\n {trimBrackets($entryWFE2)}\n" if ($debug4 == 1) and ($debug2 == 0);
say "\( STARTING TREE DESCNND #1: \)\n" if ($debug4 == 1) and ($debug2 == 1);
}
else {
say "\n==========================================================================>" if $debug4;
say "\( TREE DESCEND #{$runNum}: \)\n\n {trimBrackets($entryWFE2)}\n" if ($debug4 == 1) and ($debug2 == 0);
say "\( TREE DESCEND #{$runNum}: \)\n" if ($debug4 == 1) and ($debug2 == 1);
};
};
if $rewriteArgListElems == 0 { $temp1= $<OP>.Str; }
else { $temp1= "{ if $sr == 1 {"\n "}}" ~ $<OP>.Str ~ @rewriteArgList[$sr + 1]; };
if $englobingNoRWdegree > 0 { $noSkips= 0; } else { $noSkips= 1; };
say " " if $debug;
};
if $stopreduction == 1 {}
elsif $englobingNoRWdegree > 0 {
say " " if $debug;
if $sr > 1 {
if $rewriteArgListElems == 0 {
say ".{'m' x$sr}.LEVEL$sr \(type @OPvariety[$sr] w $rewriteArgListElems args\) 0SKIP\.$englobingNoRWdegree: {trimBrackets($temp1)}" if (($englobingNoRWdegree == 1) and ($needNewDescend == 0) and ($debug4 == 1) and (not($debug2 == 1)));
};
}
else {
say ".{'m' x$sr}.LEVEL$sr \(type @OPvariety[$sr] w $rewriteArgListElems args\) 1SKIPnestg$englobingNoRWdegree:" if (($englobingNoRWdegree == 1) and ($needNewDescend == 0) and ($debug4 == 1) and (not($debug2 == 1)));
};
};
if $sr > 2 {
$BIStemp2= @BISelemsTotalOfListOfWFErewritesForGivenARGLISTruleRun[$sr + 1];
};
if $rewriteArgListElems == 0 {
$rewriteWFE= $<OP>.Str;
if ($runNum > 0) and ($stopreduction == 0) and ($englobingNoRWdegree == 0) {
};
$entryWFE= $<OP>.Str;
if $sr > 2 {
@listOfCurBraces[$sr-1][@curbraceIdx[$sr-1]]= @curWFEbrace[$sr - 1];
if @curbraceIdx[$sr-1] == 0 {
$curBrace= @curWFEbrace[$sr - 1];
}
else {
if @curWFEbrace[$sr - 1] === '[' { $curBrace= '['; } else { $curBrace= '('; };
};
};
if $runNum > 0 { if $stopreduction == 1 { $wrongArgTypes= 1; }; };
}
else {
$rewriteWFE= $<OP>.Str ~ @rewriteArgList[$sr + 1];
$entryWFE= $rewriteWFE;
if $sr > 2 {
@listOfCurBraces[$sr-1][@curbraceIdx[$sr-1]]= @curWFEbrace[$sr - 1];
if @curbraceIdx[$sr-1] == 0 { $curBrace= @curWFEbrace[$sr - 1]; }
else {
if @curWFEbrace[$sr - 1] === '[' { $curBrace= '['; }
else { $curBrace= '('; };
};
};
if $runNum == 0 {}
elsif $englobingNoRWdegree > 0 {
$curIdx= 0;
$stopredOP= $<OP>.Str; $stopredWhileMin= $curIdx; $stopredWhileMax= $rewriteArgListElems;
while $curIdx < $rewriteArgListElems {
if @currentARGLISTlistOfBraceTypesOfComponentWFEs[$curIdx] === '['
{ $tempLeftBrace= '['; $tempRightBrace= ']'; }
else { $tempLeftBrace= '('; $tempRightBrace= ')'; };
@stopredWFEcompArgList[$curIdx]= $tempLeftBrace ~ @WFEcompArgList[$curIdx] ~ $tempRightBrace;
$curIdx++;
};
# say ".{'m' x$sr}.LEVEL$sr \(type @OPvariety[$sr] w $rewriteArgListElems args\) 22SKIP\.$englobingNoRWdegree: {trimBrackets($entryWFE)}" if (($englobingNoRWdegree == 1) and ($needNewDescend == 0) and ($debug4 == 1) and (not($debug2 == 1)));
say ".{'m' x$sr}.LEVEL$sr \(type @OPvariety[$sr] w $rewriteArgListElems args\) 2SKIP\.$englobingNoRWdegree: " if (($englobingNoRWdegree == 1) and ($needNewDescend == 0) and ($debug4 == 1) and (not($debug2 == 1)));
say " {'|' x$sr} {trimBrackets($stopredOP)}" if (($englobingNoRWdegree == 1) and ($needNewDescend == 0) and ($debug4 == 1) and (not($debug2 == 1)));
# say " {'|' x$sr} $stopredOP" if (($englobingNoRWdegree == 1) and ($needNewDescend == 0) and ($debug4 == 1) and (not($debug2 == 1)));
$curIdx= $stopredWhileMin;
while $curIdx < $stopredWhileMax {
$entryWFE2= "{@stopredWFEcompArgList[$curIdx]}";
say " {'|' x$sr} {trimBrackets($entryWFE2)}" if (($englobingNoRWdegree == 1) and ($needNewDescend == 0) and ($debug4 == 1) and (not($debug2 == 1)));
# say " {'|' x$sr} $entryWFE2" if (($englobingNoRWdegree == 1) and ($needNewDescend == 0) and ($debug4 == 1) and (not($debug2 == 1)));
$curIdx= $curIdx + 1;
};
}
else {
$rewriteWFE= $<OP>.Str ~ @rewriteArgList[$sr + 1];
if $stopreduction == 1 {} else {
if @OPvariety[$sr] === 'NUM' { $rewriteWFE= $<OP>.Str; }
elsif @OPvariety[$sr] === 'PROC' { $stopreduction= 1; }
elsif @OPvariety[$sr] === 'OP5' {
if ($<OP>.Str === 'IF') and ($rewriteArgListElems > 2) {
if @WFEcompArgList[0] === '0' {$rewriteWFE= @WFEcompArgList[1]; }
else {$rewriteWFE= @WFEcompArgList[2]; };
fillRestOfArgsV1(3); $stopreduction= 1; }
elsif ($<OP>.Str === 'id') and ($rewriteArgListElems > 0) {
$rewriteWFE= @WFEcompArgList[0];
fillRestOfArgsV1(1); $stopreduction= 1; }
elsif ($<OP>.Str === 'say') and ($runNum > 0) {
say " " if (($debug2 == 0) and ($debug4 == 1));
say " {' ' x$sr} {'( ****** LEVEL'}$sr {'ACTION '}\#$output\: {'say '}\) {@WFEcompArgList[0]}";
say " " if (($debug2 == 1) and ($debug4 == 0));
$rewriteWFE= 'nil';
$output++;
$saySuccess= 1;
}
elsif (($<OP>.Str === 'concat') or ($<OP>.Str === 'string')) and ($rewriteArgListElems > 0) {
$rewriteWFE= '';
$curIdx= 0;
while $curIdx < $rewriteArgListElems {
$input= @WFEcompArgList[$curIdx];
@tempStmt[0]= '';
$input= $input.subst( :g , /^(\%+)$/ ,
-> $/ { @tempStmt[0]= 'ok'; "{' ' x$0.chars}" } );
if @tempStmt[0] ~~ 'ok' {$rewriteWFE= $rewriteWFE ~ $input;}
else {$rewriteWFE= $rewriteWFE ~ @WFEcompArgList[$curIdx];};
$curIdx= $curIdx + 1;
};
if $<OP>.Str === 'string' { $stopreduction= 1;
$stopredOP= $rewriteWFE; $stopredWhileMin= 0; $stopredWhileMax= 0; }; }
elsif $runNum > 0 {
$input= $<OP>.Str;
@tempStmt[0]= ''; @tempStmt[1]= ''; @tempStmt[2]= ''; @tempStmt[3]= '';
$tp1= $input.subst( :g , /(\w+)(['::='])(\d+)(['='])/ ,
-> $/ { @tempStmt[0]= $0; @tempStmt[1]= $1;
@tempStmt[2]= $2; @tempStmt[3]= $3 } );
if (@tempStmt[1] ~~ '::=') and (@tempStmt[3] ~~ '=') {
if %*PROCS{"{@tempStmt[0]}"} === Any {
%*PROCS{"{@tempStmt[0]}"}= @WFEcompArgList[0];
%*PROCSparmNum{"{@tempStmt[0]}"}= @tempStmt[2];
$rewriteWFE= 'nil';
} else {die "duplicated shorthand"; }; };
$input= $<OP>.Str;
@tempStmt[0]= ''; @tempStmt[1]= '';
$tp1= $input.subst( :g , /^(['stepThru'])(\d+)/ ,
-> $/ { @tempStmt[0]= $0; @tempStmt[1]= $1; } );
if (@tempStmt[0] ~~ 'stepThru') and ($rewriteArgListElems > @tempStmt[1].Int) {
$rewriteWFE= @WFEcompArgList[@tempStmt[1].Int];
fillRestOfArgsV1(@tempStmt[1].Int + 1); $stopreduction= 1;
};
$input= $<OP>.Str;
@tempStmt[0]= ''; @tempStmt[1]= '';
$tp1= $input.subst( :g , /^(['goTo'])(\d+)/ ,
-> $/ { @tempStmt[0]= $0; @tempStmt[1]= $1; } );
if @tempStmt[0] ~~ 'goTo' {
$temp2= @tempStmt[1];
if $rewriteArgListElems > 0 {
if %*PROCS{"{@WFEcompArgList[0]}"} === Any {}
elsif %*PROCSparmNum{"{@WFEcompArgList[0]}"} == 0 {
$input= %*PROCS{"{@WFEcompArgList[0]}"};
@tempStmt[0]= ''; @tempStmt[1]= '';
$tp1= $input.subst( :g , /(['@@'])(\d+)/ , -> $/ { @tempStmt[0]= $0; @tempStmt[1]= $1 } );
if (@tempStmt[0] ~~ '@@') and (@tempStmt[1].Int > $temp2) {
$temp4= @tempStmt[1].Int;
$curIdx= 0;
$tp1= $input.subst( :g , /['('|'['](\w+)[')'|']']/ , -> $/ { @tempStmt[$curIdx]= $0; $curIdx++ } );
if $curIdx !== $temp4 {}
elsif %*PROCSparmNum{"{@tempStmt[$temp2].Str}"} === Any {}
else {
$input= @tempStmt[$temp2].Str;
$temp6= %*PROCSparmNum{"{$input}"};
if %*PROCSparmNum{"{$input}"} !=== Any {
$temp6= %*PROCSparmNum{"{$input}"};
if $rewriteArgListElems > ($temp6 - 1) {
$rewriteWFE= @tempStmt[$temp2].Str;
$curIdx= 0;
while $curIdx < $temp6 {
$input= @WFEcompArgList[0] ~ '--' ~ "{$curIdx}";
if %*GOTOARGNAMES{"{$input}"} === Any {
$tp1= @WFEcompArgList[$curIdx];
@tempStmt[0]= 'com'; @tempStmt[1]= 'rew';@tempStmt[2]= 'com2'; @tempStmt[3]= 'rew2';
$tp1= $tp1.subst( :g ,
/ ^(''\d+) ('__') (<[A..Z]>[<[A..Z0..9]> | '_' ]*) ['('|'['] (.+) [')'|']']$/ ,
-> $/ { @tempStmt[0]= $0; @tempStmt[1]= $1; @tempStmt[2]= $2; @tempStmt[3]= $3; } );
if (@tempStmt[1] ~~ '__') {
%*GOTOARGNAMES{"{$input}"}= @tempStmt[0] ~ @tempStmt[1] ~ @tempStmt[2];
};
};
$curIdx++;
};
$curIdx2= 0;
while $curIdx2 < $temp6 {
@WFEcompArgListTemp2[$curIdx2]= @WFEcompArgList[$curIdx2];
$curIdx2= $curIdx2 + 1;
};
$curIdx2= 0;
while $curIdx2 < $temp6 {
$input= @WFEcompArgListTemp2[$curIdx2];
@tempStmt[0]= 'com'; @tempStmt[1]= 'rew';@tempStmt[2]= 'com2'; @tempStmt[3]= 'rew2';
$tp1= $input.subst( :g ,
/ ^(''\d+) ('__') (<[A..Z]>[<[A..Z0..9]> | '_' ]*) ['('|'['] (.+) [')'|']']$/ ,
-> $/ { @tempStmt[0]= $0; @tempStmt[1]= $1; @tempStmt[2]= $2; @tempStmt[3]= $3; } );
if (@tempStmt[1] ~~ '__') {
@WFEcompArgListTemp2[$curIdx2]= @tempStmt[3];
};
$curIdx2= $curIdx2 + 1;
};
$curIdx= 0;
while $curIdx < $temp6 {
$input= @WFEcompArgList[0] ~ '--' ~ "{$curIdx}";
if %*GOTOARGNAMES{"{$input}"} !=== Any {
@WFEcompArgListTemp[$curIdx]=
%*GOTOARGNAMES{"{$input}"}
~ '[' ~ @WFEcompArgListTemp2[$curIdx] ~ ']';
}
else {@WFEcompArgListTemp[$curIdx]= @WFEcompArgListTemp2[$curIdx];
};
$curIdx++;
};
## fillRestOfArgsV1(0);
$stopredOP= $rewriteWFE; $stopredWhileMin= 0; $stopredWhileMax= $rewriteArgListElems;
$curIdx= 0;
while $curIdx < $temp6 {
@stopredWFEcompArgList[$curIdx]= @WFEcompArgListTemp[$curIdx];
$rewriteWFE= $rewriteWFE ~ '[' ~ @WFEcompArgListTemp[$curIdx] ~ ']';
$curIdx++;
};
$curIdx= $temp6;
while $curIdx < $rewriteArgListElems {
@stopredWFEcompArgList[$curIdx]= @WFEcompArgList[$curIdx];
$rewriteWFE= $rewriteWFE ~ '[' ~ @WFEcompArgList[$curIdx] ~ ']';
$curIdx++;
};
$stopreduction= 1; }; }; }; }; }; }; };
$input= $<OP>.Str;
$tp1= ''; @tempStmt[0]= ''; @tempStmt[1]= '';
$tp1= $input.subst( :g , /^(['cTerm'])(\d+)/ ,
-> $/ { @tempStmt[0]= $0; @tempStmt[1]= $1 } );
if (@tempStmt[0] ~~ 'cTerm') and (@tempStmt[1] > 0) {
if $rewriteArgListElems == @tempStmt[1] {}
elsif $rewriteArgListElems < @tempStmt[1] {$rewriteWFE= 'ERROR too short'; die; }
elsif $rewriteArgListElems > @tempStmt[1] {
$tp2= $<OP>.Str;
$curIdx= 0; while $curIdx < (@tempStmt[1] + 1) { $tp2= $tp2 ~ '[' ~ @WFEcompArgList[$curIdx] ~ ']'; $curIdx= $curIdx + 1; };
if %*TERMS{"{$tp2}"} === Any {} else {
$rewriteWFE= %*TERMS{"{$tp2}"};
fillRestOfArgsV1(@tempStmt[1] + 1);
$stopreduction= 1; }; }; };
$input= $<OP>.Str;
$tp1= '';
@tempStmt[0]= ''; @tempStmt[1]= '';
$tp1= $input.subst( :g , /^(['@@'])(\d+)/ ,
-> $/ { @tempStmt[0]= $0; @tempStmt[1]= $1 } );
if (@tempStmt[0] ~~ '@@')
and ((@tempStmt[1] > 0) or (@tempStmt[1] == 0)) {
$tp0= @tempStmt[0];
if $rewriteArgListElems == @tempStmt[1] {}
elsif $rewriteArgListElems < @tempStmt[1] {$rewriteWFE= 'ERROR';}
elsif $rewriteArgListElems > @tempStmt[1] {
if (@WFEcompArgList[@tempStmt[1]] ~~ 'setSubVar')
and ((@tempStmt[1] > 0) or (@tempStmt[1] == 0)) {
if @tempStmt[1] == 0 {
# $rewriteWFE= 'assocList1[subVar[' ~ @WFEcompArgList[1] ~ '][' ~ @WFEcompArgList[2] ~ ']]';
if $rewriteArgListElems > 2 {
$rewriteWFE= $tp0 ~ '1[subVar[' ~ @WFEcompArgList[1] ~ '][' ~ @WFEcompArgList[2] ~ ']]';
if $rewriteArgListElems > 3 {
fillRestOfArgsV1(3);
$stopreduction= 1; }; }; }
else {
if ( $rewriteArgListElems > (@tempStmt[1] + 2) ) {
@WFEcompArgListTemp[@tempStmt[1] + 1]
= 'subVar[' ~ @WFEcompArgList[@tempStmt[1] + 1] ~ ']';
$rewriteWFE= '';
$input= @WFEcompArgListTemp[@tempStmt[1] + 1]
~ '[' ~ @WFEcompArgList[@tempStmt[1] + 2] ~ ']';
$tp1= '';
$curIdx= 0;
while $curIdx < @tempStmt[1] {
if ( 'subVar[' ~ %*AssocListArg0{"{@WFEcompArgList[$curIdx]}Arg0"} ~ ']' ~~ @WFEcompArgListTemp[@tempStmt[1] + 1] ) {
if ( ('subVar[' ~ %*AssocListArg0{"{@WFEcompArgList[$curIdx]}Arg0"} ~ ']'
~ '[' ~ %*AssocListArg1{"{@WFEcompArgList[$curIdx]}Arg1"} ~ ']' )
~~ @WFEcompArgList[$curIdx] ) {
$rewriteWFE= $rewriteWFE ~ '[' ~ $input ~ ']';
$tp1= 'SUCCESS'; }
else {$rewriteWFE= 'ERRORvvvvvvvvvvvvvvvvvvvvvvvv'; $stopreduction= 1;}; }
else {
$rewriteWFE= $rewriteWFE ~ '[' ~ @WFEcompArgList[$curIdx] ~ ']';
};
$curIdx= $curIdx + 1;
if $curIdx == @tempStmt[1] {
if $tp1 ~~ 'SUCCESS' {$rewriteWFE= $tp0 ~ "{@tempStmt[1]}" ~ $rewriteWFE;}
else {
$rewriteWFE= $tp0 ~ "{@tempStmt[1] + 1}" ~ $rewriteWFE ~ '[' ~ $input ~ ']'; }; }; };
if $rewriteArgListElems > (@tempStmt[1] + 3) {
fillRestOfArgsV1(@tempStmt[1] + 3);
$stopreduction= 1; }; }; }; }
elsif ((@WFEcompArgList[@tempStmt[1]] ~~ 'getSubVar')
or (@WFEcompArgList[@tempStmt[1]] ~~ 'getSubItem'))
and ((@tempStmt[1] > 0) or (@tempStmt[1] == 0)) {
if ( $rewriteArgListElems < (@tempStmt[1] + 2) ) {}
else {
$rewriteWFE= 'nil';
$curIdx= 0;
while $curIdx < @tempStmt[1] {
if ( %*AssocListArg0{"{@WFEcompArgList[$curIdx]}Arg0"} ~~ @WFEcompArgList[@tempStmt[1] + 1] ) {
$rewriteWFE= %*AssocListArg1{"{@WFEcompArgList[$curIdx]}Arg1"};
if @WFEcompArgList[@tempStmt[1]] ~~ 'getSubVar' {
if ( ('subVar[' ~ @WFEcompArgList[@tempStmt[1] + 1] ~ '][' ~ $rewriteWFE ~ ']') ~~ @WFEcompArgList[$curIdx] ) {}
else {$rewriteWFE= 'ERROR'; die "subVar hash problem"; };
}
else {
if ( ('subItem[' ~ @WFEcompArgList[@tempStmt[1] + 1] ~ '][' ~ $rewriteWFE ~ ']') ~~ @WFEcompArgList[$curIdx] ) {}
else {$rewriteWFE= 'ERROR'; die "subItem hash problem"; };
};
$curIdx= @tempStmt[1];
}
else {$curIdx= $curIdx + 1; };
};
if ( $rewriteWFE ~~ 'nil' ) {}
else {fillRestOfArgsV1(@tempStmt[1] + 2); $stopreduction= 1; }; }; }
elsif ((@WFEcompArgList[@tempStmt[1]] ~~ 'x0') or
(@WFEcompArgList[@tempStmt[1]] ~~ 'x1') or
(@WFEcompArgList[@tempStmt[1]] ~~ 'x2'))
and (@tempStmt[1] > 0) {
$input= @WFEcompArgList[@tempStmt[1]];
@tempStmt[2]= '';
$tp2= $input.subst( :g , /^['x'](\d+)/ ,
-> $/ { @tempStmt[2]= $0; } );
if @tempStmt[2] < @tempStmt[1] {
$rewriteWFE= @WFEcompArgList[@tempStmt[2]];
fillRestOfArgsV1(@tempStmt[1] + 1); $stopreduction= 1; }; }
elsif @WFEcompArgList[@tempStmt[1]] ~~ 'append' {
if $rewriteArgListElems > (@tempStmt[1] + 1) {
$rewriteWFE= "{$rewriteArgListElems - 1}";
$rewriteWFE= '^' ~ $rewriteWFE;
$curIdx= 0;
while $curIdx < $rewriteArgListElems {
if $curIdx == @tempStmt[1] {}
else { $rewriteWFE= $rewriteWFE ~ '[' ~ @WFEcompArgList[$curIdx] ~ ']' };
$curIdx= $curIdx + 1; }; }; }
elsif @WFEcompArgList[@tempStmt[1]] ~~ 'equals' {
if $rewriteArgListElems > (@tempStmt[1] + @tempStmt[1]) {
$rewriteWFE= '0';
$curIdx= 0;
while $curIdx < @tempStmt[1] {
if @WFEcompArgList[$curIdx] ~~ @WFEcompArgList[$curIdx + @tempStmt[1] + 1] {}
else { $rewriteWFE= '1'; $curIdx= @tempStmt[1]; };
$curIdx= $curIdx + 1;
};
$stopredOP= $rewriteWFE; $stopredWhileMin= 0; $stopredWhileMax= 0; }; }
else {
$rewriteWFE= @WFEcompArgList[@tempStmt[1]];
$curIdx= 0;
while $curIdx < $rewriteArgListElems {
if $curIdx !== @tempStmt[1] {$rewriteWFE= $rewriteWFE ~ '[' ~ @WFEcompArgList[$curIdx] ~ ']'; };
$curIdx= $curIdx + 1;
};
$stopreduction= 1;
$stopredOP= $rewriteWFE; $stopredWhileMin= 0; $stopredWhileMax= 0; }; }
else {};
};
}
else { die "cccc"; };
}
elsif (@OPvariety[$sr] === 'OP2') or (@OPvariety[$sr] === 'OP3') {
$input= %*PROCS{"{$<OP>.Str}"};
if $input === Any {
$input= %*TERMS{"{$<OP>.Str ~ '[' ~ @WFEcompArgList[0] ~ ']'}"};
if $input === Any {}
else {
$rewriteWFE= $input;
fillRestOfArgsV1(1);
$wrongArgTypes= 1;
$stopreduction= 1;
};
}
else {
$curIdx2= 0;
while $curIdx2 < $rewriteArgListElems {
@WFEcompArgListTemp[$curIdx2]= @WFEcompArgList[$curIdx2];
$curIdx2= $curIdx2 + 1;
};
$curIdx2= 0;
while $curIdx2 < $rewriteArgListElems {
$input= @WFEcompArgListTemp[$curIdx2];
@tempStmt[0]= 'com'; @tempStmt[1]= 'rew';@tempStmt[2]= 'com2'; @tempStmt[3]= 'rew2';
$tp1= $input.subst( :g ,
/ ^(''\d+) ('__') (<[A..Z]>[<[A..Z0..9]> | '_' ]*) ['('|'['] (.+) [')'|']']$/ ,
-> $/ { @tempStmt[0]= $0; @tempStmt[1]= $1; @tempStmt[2]= $2; @tempStmt[3]= $3; } );
if (@tempStmt[1] ~~ '__') {
@WFEcompArgListTemp[$curIdx2]= @tempStmt[3];
};
$curIdx2= $curIdx2 + 1;
};
if %*PROCSparmNum{"{$<OP>.Str}"} == 0 {
$input= %*PROCS{"{$<OP>.Str}"};
$input= $input.subst( :g , / '<:::' / , -> $/ { '' } );
$input= $input.subst( :g , / ':::>' / , -> $/ { '' } );
$rewriteWFE= $input;
fillRestOfArgsV1(0); $stopreduction= 1;
}
else {
$tmplateOP= 1;
$actualTemplate= $<OP>.Str;
$tmplateNumOfParms= %*PROCSparmNum{"{$<OP>.Str}"};
if $rewriteArgListElems < $tmplateNumOfParms {
$parmSubstnResult= $actualTemplate;
$curIdx= 0;
while $curIdx < $rewriteArgListElems {
$parmSubstnResult= $parmSubstnResult ~ '[' ~ @WFEcompArgList[$curIdx] ~ ']';
$curIdx= $curIdx + 1;
};
$wrongArgTypes= 1;
}
else {
$input= %*PROCS{"{$<OP>.Str}"};
$tp2= $input;
$tmplateStr= $input;
$input= $input.subst( :g , / '<:::' / , -> $/ { '' } );
$input= $input.subst( :g , / ':::>' / , -> $/ { '' } );
if $input === $tp2 {$parmSubstnResult= $tp2; }
else {
$input= $input.subst( :g , / ('~')(\d+) ('__') (<[A..Z]>[<[A..Z0..9]> | '_' ]*) / , -> $/ { $0 ~ $1 } );
$tp1= $input.subst( :g , / '~'(\d+) / ,
-> $/ { @WFEcompArgListTemp[$0];
} );
$parmSubstnResult= $tp1;
$wrongArgTypes= 1;
$stopreduction= 1; }; };
$rewriteWFE= $parmSubstnResult;
if $parmSubstnResult ~~ $tp2 {fillRestOfArgsV1(0); }
else {fillRestOfArgsV1($tmplateNumOfParms); }; }; }; }
else { die "wrong OP"; }; }; }; };
$/.make($rewriteWFE);
# as initialized below at call of method OP:
# @elemsTotalOfListOfWFErewritesForGivenARGLISTruleRun[$sr]= 0;
if $sr > 2 {
$temp2= @elemsTotalOfListOfWFErewritesForGivenARGLISTruleRun[$sr - 1];
@listOfWFErewritesForGivenARGLISTruleRun[$sr - 1][$temp2]= $rewriteWFE;
if $runNum == 0 { @listOfWFEbraceTypesForGivenARGLISTruleRun[$sr - 1][$temp2]= @curWFEbrace[$sr - 1]; }
else {
if $englobingNoRWdegree > 0 { $wrongArgTypes= 1; };
if $stopreduction == 1 { $wrongArgTypes= 1; };
if ($stopreduction == 1) and ($saySuccess == 1) { $wrongArgTypes= 0; };
if $wrongArgTypes == 1 { @listOfWFEbraceTypesForGivenARGLISTruleRun[$sr - 1][$temp2]= @curWFEbrace[$sr - 1]; }
else { @listOfWFEbraceTypesForGivenARGLISTruleRun[$sr - 1][$temp2]= '['; };
};
@listOfOPvarietyForGivenARGLISTruleRun[$sr - 1][$temp2]= @curWFEopVariety[$sr + 1];
if $addMultSuccess == 1 { @listOfOPvarietyForGivenARGLISTruleRun[$sr - 1][$temp2]= 'NUM'; };
@elemsTotalOfListOfWFErewritesForGivenARGLISTruleRun[$sr - 1]= $temp2 + 1;
if $runNum == 0 {
@BISlistOfWFEbraceTypesForGivenARGLISTruleRun[$sr + 1][$BIStemp2]= $curBrace;
@BISlistOfWFErewritesForGivenARGLISTruleRun[$sr + 1][$BIStemp2]= $rewriteWFE;
};
@curbraceIdx[$sr-1]= @curbraceIdx[$sr-1] + 1;
if $curBrace === '[' {
$englobingNoRWdegree--;
if $englobingNoRWdegree == 1 {
$BIStemp2= @BISelemsTotalOfListOfWFErewritesForGivenARGLISTruleRun[$sr + 1];
$BIStemp22= @BISelemsTotalOfListOfWFErewritesForGivenARGLISTruleRun[$sr + 1];
if $sr > 2 {
if @isBaseBISlistOfWFEbraceTypesForGivenARGLISTruleRun[$sr + 1][$BIStemp2] == 1 {
$englobingNoRWdegree= 0; }; }; }; }; };
if $noSkips == 1 {
if (($sr == 1) and ($debug2 == 1) and ($debug4 == 1)) {}
else {
if $runNum > 0 {
$entryWFE2= $entryWFE;
$entryWFE4= $/.made;
if $entryWFE !=== $/.made {
say " " if $debug;
if $stopreduction == 0 {
say "\n.{'m' x$sr}.LEVEL$sr \(type @OPvariety[$sr] w $rewriteArgListElems args\) RW SUCCESS:" if $debug4; }
else {
say "\n.{'m' x$sr}.LEVEL$sr \(type @OPvariety[$sr] w $rewriteArgListElems args\) EXPANDING RW - NEED NEW DESCEND NOW:" if $debug4;
$needNewDescend= 1;
};
say " {'|' x$sr} {trimBrackets($<OP>.Str)}" if $debug4;
$curIdx= 0;
while $curIdx < $rewriteArgListElems {
$entryWFE2= '[' ~ "{@WFEcompArgList[$curIdx]}" ~ ']';
say " {'|' x$sr} {trimBrackets($entryWFE2)}" if $debug4;
$curIdx++;
};
if $stopreduction == 0 {
say " {'|' x$sr} " if $debug4;
say " {'|' x$sr} ====> {trimBrackets($entryWFE4)}" if $debug4;
}
else {
say " {'|' x$sr} " if $debug4;
say " {'|' x$sr} =============>" if $debug4;
say " {'|' x$sr} {trimBrackets($stopredOP)}" if $debug4;
if $stopredWhileMin < $stopredWhileMax {say " {'|' x$sr} " if $debug4;};
$curIdx= $stopredWhileMin;
while $curIdx < $stopredWhileMax {
$entryWFE2= '[' ~ "{@stopredWFEcompArgList[$curIdx]}" ~ ']';
say " {'|' x$sr} {trimBrackets($entryWFE2)}" if $debug4;
$curIdx= $curIdx + 1;
};
};
say " " if (($debug2 == 1) or ($debug4 == 1)) and (($debug2 == 0) or ($debug4 == 1));
say " " if $debug;
}
else {
$input= $entryWFE;
$tp1= '';
@tempStmt[0]= ''; @tempStmt[1]= '';
$tp1= $input.subst( :g , /^(['$'])(\w+)/ ,
-> $/ { @tempStmt[0]= $0; @tempStmt[1]= $1 } );
if $stopreduction == 0 {
say " " if $debug;
if $rewriteArgListElems == 0 {
say "\n.{'m' x$sr}.LEVEL$sr \(type @OPvariety[$sr] w $rewriteArgListElems args\) NOT REWRITABLE: {trimBrackets($entryWFE2)}" if $debug4;
}
else {
say "\n.{'m' x$sr}.LEVEL$sr \(type @OPvariety[$sr] w $rewriteArgListElems args\) NOT REWRITABLE:" if $debug4;
say " {'|' x$sr} {trimBrackets($<OP>.Str)}" if $debug4;
$curIdx= 0;
while $curIdx < $rewriteArgListElems {
$entryWFE2= '[' ~ "{@WFEcompArgList[$curIdx]}" ~ ']';
say " {'|' x$sr} {trimBrackets($entryWFE2)}" if $debug4;
$curIdx++; }; };
say " " if $debug4; }; }; }; }; }; $srw--; };
method OP5($/) {
$/.make($/.Str);
@elemsTotalOfListOfWFErewritesForGivenARGLISTruleRun[$sr]= 0;
@curWFEbrace[$sr]= ''; @OPstr[$sr - 1]= $/.made; @OPvariety[$sr - 1]= 'OP5'; @curWFEopVariety[$sr]= 'OP5'; };
method NUM($/) {
$/.make($/.Str);
@elemsTotalOfListOfWFErewritesForGivenARGLISTruleRun[$sr]= 0;
@curWFEbrace[$sr]= ''; @OPstr[$sr - 1]= $/.made; @OPvariety[$sr - 1]= 'NUM'; @curWFEopVariety[$sr]= 'NUM'; };
method PROC($/) {
$/.make($/.Str);
@elemsTotalOfListOfWFErewritesForGivenARGLISTruleRun[$sr]= 0;
@curWFEbrace[$sr]= ''; @OPstr[$sr - 1]= $/.made; @OPvariety[$sr - 1]= 'PROC'; @curWFEopVariety[$sr]= 'PROC';
@entryTempoeName[$sr - 1]= $/.Str; };
method OP6($/) {
$/.make($/.Str);
@elemsTotalOfListOfWFErewritesForGivenARGLISTruleRun[$sr]= 0;
@curWFEbrace[$sr]= ''; @OPstr[$sr - 1]= $/.made; @OPvariety[$sr - 1]= 'OP6'; @curWFEopVariety[$sr]= 'OP6'; };
method OP3($/) {
$/.make($/.Str);
@elemsTotalOfListOfWFErewritesForGivenARGLISTruleRun[$sr]= 0;
@curWFEbrace[$sr]= ''; @OPstr[$sr - 1]= $/.made; @OPvariety[$sr - 1]= 'OP3'; @curWFEopVariety[$sr]= 'OP3'; };
method OP2($/) {
$/.make($/.Str);
@elemsTotalOfListOfWFErewritesForGivenARGLISTruleRun[$sr]= 0;
@curWFEbrace[$sr]= ''; @OPstr[$sr - 1]= $/.made; @OPvariety[$sr - 1]= 'OP2'; @curWFEopVariety[$sr]= 'OP2'; };
method OP($/) {
$/.make($/.Str);
@elemsTotalOfListOfWFErewritesForGivenARGLISTruleRun[$sr]= 0;
@curWFEbrace[$sr]= ''; };
method ARGLIST($/) {
$rewriteArgListElems= $<ARG>.list.elems;
if $sr == 2 {
$savedsr2rewriteArgListElems= $rewriteArgListElems;
};
if $rewriteArgListElems == 0 {}
else {
@rewriteArgList[$sr]= '';
if $rewriteArgListElems == 0 {} else {
$curIdx= 0;
for $<ARG>.list -> $curItem {
@WFEcompArgList[$curIdx]= @listOfWFErewritesForGivenARGLISTruleRun[$sr][$curIdx];
@currentARGLISTlistOfBraceTypesOfComponentWFEs[$curIdx]=
@listOfWFEbraceTypesForGivenARGLISTruleRun[$sr][$curIdx];
@currentARGLISTlistOflistOfOPvarietyOfComponentWFEs[$curIdx]=
@listOfOPvarietyForGivenARGLISTruleRun[$sr - 1][$curIdx];
if $sr == 2 {
@savedsr2WFEcompArgList[$curIdx]= @WFEcompArgList[$curIdx];
};
$curIdx++;
};
$curIdx= 0;
for $<ARG>.list -> $curItem {
if $curIdx > 0 {
if @currentARGLISTlistOfBraceTypesOfComponentWFEs[$rewriteArgListElems - $curIdx] ~~ '['
{ @currentARGLISTlistOfBraceTypesOfComponentWFEs[$rewriteArgListElems - $curIdx]= '['; }
else { @currentARGLISTlistOfBraceTypesOfComponentWFEs[$rewriteArgListElems - $curIdx]= '('; };
};
$curIdx++;
};
$curIdx= 0;
for $<ARG>.list -> $curItem {
@BraceTypeOfComponentWFEatGivenIndexInWFElistOfARGLISTatGivenSrLevel[$sr][$curIdx]=
@currentARGLISTlistOfBraceTypesOfComponentWFEs[$curIdx];
$curIdx++;
};
$curIdx= 0;
for $<ARG>.list -> $curItem {
if @currentARGLISTlistOfBraceTypesOfComponentWFEs[$curIdx] ~~ '['
{
$tempLeftBrace= '['; $tempRightBrace= ']';
@tempLeftBrace[$curIdx]= '['; @tempRightBrace[$curIdx]= ']';
}
else {
$tempLeftBrace= '('; $tempRightBrace= ')';
@tempLeftBrace[$curIdx]= '('; @tempRightBrace[$curIdx]= ')';
};
@rewriteArgList[$sr]= @rewriteArgList[$sr] ~ $tempLeftBrace ~ @WFEcompArgList[$curIdx] ~ $tempRightBrace;
if $sr == 2 {
@savedsr2tempLeftBrace[$curIdx]= @tempLeftBrace[$curIdx];
@savedsr2tempRightBrace[$curIdx]= @tempRightBrace[$curIdx];
};
$curIdx++;
};
};
if ($runNum > 0) and ($setup == 0) and (@OPstr[$sr - 1] ~~ 'subItem') and ($rewriteArgListElems == 2) {
%*AssocListArg0{"{'subItem' ~ @rewriteArgList[$sr] ~ 'Arg0'}"}= @WFEcompArgList[0];
%*AssocListArg1{"{'subItem' ~ @rewriteArgList[$sr] ~ 'Arg1'}"}= @WFEcompArgList[1];
};
if ($runNum > 0) and ($setup == 0) and (@OPstr[$sr - 1] ~~ 'subVar') and ($rewriteArgListElems == 2) {
%*AssocListArg0{"{'subVar' ~ @rewriteArgList[$sr] ~ 'Arg0'}"}= @WFEcompArgList[0];
%*AssocListArg1{"{'subVar' ~ @rewriteArgList[$sr] ~ 'Arg1'}"}= @WFEcompArgList[1];
};
if ($runNum > 0) and ($setup == 0) and (@OPstr[$sr - 1] ~~ 'proc') and ($rewriteArgListElems == 3) {
$input= @WFEcompArgList[0];
@tempStmt[0]= 'errorNOTtemplate';
$input= $input.subst( :g , /^(\w+)/ , -> $/ { @tempStmt[0]= $0; } );
if @tempStmt[0] === 'errorNOTtemplate' {die "errorNOTtemplate";}
else {
$input= @WFEcompArgList[1];
@tempStmt[1]= 'errorNOTaNUM';
## $input= $input.subst( :g , /^'@@2[' (\d+) ']' '[' (\s* ['.'|'vector'|'@'|'('|'='|','|'['|')'|']'|\d|\w|\n|\s]+ \s* | '<:::' \s* ['.'|'@@'|'@'|'('|'='|','|'['|')'|']'|'~'|\d|\w|\n|\s]+ \s* ':::>') ']'/ , -> $/ { @tempStmt[2]= $0; @tempStmt[3]= $1; } );
$input= $input.subst( :g , /^(\d+)/ , -> $/ { @tempStmt[1]= $0; } );
if @tempStmt[1] === 'errorNOTaNUM' {die "errorNOTaNUM";}
else {
$input= @WFEcompArgList[2];
@tempStmt[2]= 'errorNOTaTEMPLATE';
$input= $input.subst( :g , /^('<:::' \s* ['.'|'updateArgsTotaling'|'assocList'|'@@'|'@'|'('|'='|','|'['|')'|']'|'~'|\d|\w|\n|\s]+ \s* ':::>')/ , -> $/ { @tempStmt[2]= $0; } );
if @tempStmt[2] === 'errorNOTaTEMPLATE' {die "errorNOTaTEMPLATE";}
else {
if %*PROCS{"{@WFEcompArgList[0]}"} === Any {
%*AssocListArg0{"{'proc' ~ @rewriteArgList[$sr] ~ 'Arg0'}"}= @WFEcompArgList[0];
%*PROCSparmNum{"{@WFEcompArgList[0]}"}= @WFEcompArgList[1];
%*PROCS{"{@WFEcompArgList[0]}"}= @WFEcompArgList[2];
}
elsif %*PROCS{"{@WFEcompArgList[0]}"} === @WFEcompArgList[2] {}
else {die "errorIsNAMEalreadyUsedForDifferentTemplate";};
};
};
};
};
if ($runNum > 0) and ($setup == 0) and (@OPstr[$sr - 1] ~~ 'term') and ($rewriteArgListElems == 2) {
$input= @WFEcompArgList[0];
@tempStmt[0]= 'errorNOTmapping';
$input= $input.subst( :g , /^(\w+)/ , -> $/ { @tempStmt[0]= $0; } );
# $input= $input.subst( :g , /^('^^'\d+)/ , -> $/ { @tempStmt[0]= $0; } );
if @tempStmt[0] === 'errorNOTmapping' {die "errorNOTmapping";}
else {
if %*TERMS{"{@WFEcompArgList[0]}"} === Any {
# %*AssocListArg0{"{'term' ~ @rewriteArgList[$sr] ~ 'Arg0'}"}= @WFEcompArgList[0];
# %*AssocListArg1{"{'term' ~ @rewriteArgList[$sr] ~ 'Arg1'}"}= @WFEcompArgList[1];
%*TERMS{"{@WFEcompArgList[0]}"}= @WFEcompArgList[1];
}
elsif %*TERMS{"{@WFEcompArgList[0]}"} === @WFEcompArgList[1] {}
else {die "errorIsNAMEalreadyUsedForDifferentTERMSmapping";};
};
};
$/.make(@rewriteArgList[$sr]);
@curWFEbrace[$sr]= '';
};
};
};
if $debug {}
else {
$debug= 0;
$debug2= 0;
$debug4= 0;
$lastRunNum= -1;
$runNum= 0;
$continue= 1;
while $continue > 0 {
$rwcode= $lastRwcode;
$match2= Rewrite4.parse( $rwcode, actions => RewriteAction4.new, );
$lastRwcode= $match2.made;
$lastRunNum= $runNum; $runNum++; $continue++;
if $lastRwcode ~~ $rwcode { if $runNum > 1 { $continue= 0; }; };
};
$debug= 0;
$debug2= 1;
$debug4= 0;
$lastRwcode= normalizeOrigCodes($origRwcode);
$continue= 1;
$setup= 0;
$lastRunNum= -1;
$runNum= 0;
say "\n\n\n\nCODES EXECUTION:" if $debug4;
say "\n\n\n\nHIGH LEVEL DESCEND-BY-DESCEND VIEW OF RW PROGRESS:" if $debug2;
say "\(RECURSIVE LEFTMOST-INNERMOST APPLICATIVE REWRITE, TILL CODES NOT REWRITABLE\)\n\n" if $debug4;
say "\n\n\nRW PROCESS STARTING:" if (($debug2 == 1) and (not($debug4 == 1)));
## say " {trimBrackets($lastRwcode)}" if ($debug4 == 1);
while $continue > 0 {
$rwcode= $lastRwcode;
$match2= Rewrite4.parse( $rwcode, actions => RewriteAction4.new, );
$lastRwcode= $match2.made;
if $runNum == 0 {} else {
say " " if (($debug2 == 1) and ($debug4 == 1));
say ".m.LEVEL1 AT ENTRY OF OUTERMOST RW ATTEMPT IN CURRENT DESCEND #$runNum:" if $debug2;
say ' | """""""""""""""""""""""""""""""""""""""""""""""""""""""' if $debug2;
if $runNum < 1 {}
else {
if $runNum == 1 { say " | OP: {trimBrackets(@OPstr[1])} " if $debug2;}
else {
if @OPstr[1] ~~ $OPsav {
say " | OP: <--------SAME AS IN ABOVE DESCEND: {trimBrackets($OPsav)}" if $debug2;
} else {
say " | OP: {trimBrackets(@OPstr[1])}" if $debug2;
};
};
$OPsav2= $OPsav;
$OPsav= @OPstr[1];
};
if $runNum < 1 {}
else {
$input= @OPstr[1];
@tempStmt[0]= 'com';
$tp1= $input.subst( :g , /^('goTo')\d+$/ ,
-> $/ { @tempStmt[0]= $0; } );
if @tempStmt[0] ~~ 'goTo' {
$curIdx2= 0;
while $curIdx2 < $temp6 {
@WFEcompArgListTemp2[$curIdx2]= @WFEcompArgList[$curIdx2];
$curIdx2= $curIdx2 + 1;
};
$curIdx2= 0;
while $curIdx2 < $temp6 {
$input= @WFEcompArgListTemp2[$curIdx2];
@tempStmt[0]= 'com'; @tempStmt[1]= 'rew';@tempStmt[2]= 'com2'; @tempStmt[3]= 'rew2';
$tp1= $input.subst( :g ,
/ ^(''\d+) ('__') (<[A..Z]>[<[A..Z0..9]> | '_' ]*) ['('|'['] (.+) [')'|']']$/ ,
-> $/ { @tempStmt[0]= $0; @tempStmt[1]= $1; @tempStmt[2]= $2; @tempStmt[3]= $3; } );
if (@tempStmt[1] ~~ '__') {
@WFEcompArgListTemp2[$curIdx2]= @tempStmt[3];
};
$curIdx2= $curIdx2 + 1;
};
$tp2= @WFEcompArgList[0];
$curIdx= 0;
while $curIdx < $temp6 {
$input= $tp2 ~ '--' ~ "{$curIdx}";
if %*GOTOARGNAMES{"{$input}"} === Any {
@WFEcompArgList[$curIdx]= @WFEcompArgListTemp2[$curIdx];}
else {
@WFEcompArgList[$curIdx]=
%*GOTOARGNAMES{"{$input}"}
~ '[' ~ @WFEcompArgListTemp2[$curIdx] ~ ']';
};
$curIdx++;
};
if $runNum > 1 {
if $rewriteArgListElemsSav > $rewriteArgListElems { $compareMax= $rewriteArgListElems; }
else { $compareMax= $rewriteArgListElemsSav; };
};
$curIdx= 0;
while $curIdx < $rewriteArgListElems {
$entryWFE2= "{@tempLeftBrace[$curIdx]} {@WFEcompArgList[$curIdx]} {@tempRightBrace[$curIdx]}";
if $runNum == 1 { say " | ARG$curIdx: {trimBrackets($entryWFE2)}" if $debug2; }
else {
if $curIdx < $compareMax {
$entryWFE4= "{@tempLeftBraceSav[$curIdx]} {@WFEcompArgListSav[$curIdx]} {@tempRightBraceSav[$curIdx]}";
if $entryWFE2 ~~ $entryWFE4 {
## say " | ARG$curIdx: .........NO UPDATES: {trimBrackets($entryWFE4)}" if $debug2;
say " | ARG$curIdx: .........NO UPDATES." if $debug2;
} else {
say " | ARG$curIdx: {trimBrackets($entryWFE2)}" if $debug2;
$input= $OPsav2;
@tempStmt[0]= 'com';
$tp1= $input.subst( :g , /^('goTo')\d+$/ ,
-> $/ { @tempStmt[0]= $0; } );
if @tempStmt[0] ~~ 'goTo' {
say " | " if $debug2;
say " | {'mmmmmmmmmmmmmmmmmmmmmmmmmm'} UPDATED ! {'mmmmmmmmmmmmmmm'} WAS:" if $debug2;
say " | {trimBrackets($entryWFE4)}" if $debug2;
say " | " if $debug2;
};
};
} else { say " | ARG$curIdx: {trimBrackets($entryWFE2)}" if $debug2; };
};
$curIdx= 1 + $curIdx;
};
$curIdx2= 0;
while $curIdx2 < $rewriteArgListElems {
@tempLeftBraceSav[$curIdx2]= @tempLeftBrace[$curIdx2];
@tempRightBraceSav[$curIdx2]= @tempRightBrace[$curIdx2];
@WFEcompArgListSav[$curIdx2]= @WFEcompArgList[$curIdx2];
$curIdx2= 1 + $curIdx2;
};
$rewriteArgListElemsSav= $rewriteArgListElems;
}
else {
if $runNum > 1 {
if $rewriteArgListElemsSav > $rewriteArgListElems { $compareMax= $rewriteArgListElems; }
else { $compareMax= $rewriteArgListElemsSav; };
};
$curIdx= 0;
while $curIdx < $rewriteArgListElems {
$entryWFE2= "{@tempLeftBrace[$curIdx]} {@WFEcompArgList[$curIdx]} {@tempRightBrace[$curIdx]}";
if $runNum == 1 { say " | ARG$curIdx: {trimBrackets($entryWFE2)}" if $debug2; }
else {
if $curIdx < $compareMax {
$entryWFE4= "{@tempLeftBraceSav[$curIdx]} {@WFEcompArgListSav[$curIdx]} {@tempRightBraceSav[$curIdx]}";
if $entryWFE2 ~~ $entryWFE4 {
say " | ARG$curIdx: <--------SAME AS IN ABOVE DESCEND. " if $debug2;
} else {
say " | ARG$curIdx: {trimBrackets($entryWFE2)}" if $debug2;
};
} else { say " | ARG$curIdx: {trimBrackets($entryWFE2)}" if $debug2; };
};
$curIdx= 1 + $curIdx;
};
$curIdx2= 0;
while $curIdx2 < $rewriteArgListElems {
@tempLeftBraceSav[$curIdx2]= @tempLeftBrace[$curIdx2];
@tempRightBraceSav[$curIdx2]= @tempRightBrace[$curIdx2];
@WFEcompArgListSav[$curIdx2]= @WFEcompArgList[$curIdx2];
$curIdx2= 1 + $curIdx2;
};
$rewriteArgListElemsSav= $rewriteArgListElems;
};
};
say " " if $debug4;
};
$lastRunNum= $runNum; $runNum++; $continue++;
if $lastRwcode ~~ $rwcode { if $runNum > 1 { $continue= 0; }; };
};
say "\n\n";
say 'CODES NOW NOT REWRITABLE !';
say "END OF CODES EXECUTION";
};