....................................../////.===Shadow-Here===./////................................................ > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < ------------------------------------------------------------------------------------------------------------------- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RIFF¤ WEBPVP8 ˜ ðÑ *ôô>‘HŸK¥¤"§£±¨àð enü¹%½_F‘åè¿2ºQú³íªú`N¿­3ÿƒügµJžaÿ¯ÿ°~¼ÎùnúîÞÖô•òíôÁÉß®Sm¥Ü/ ‡ó˜f£Ùà<˜„xëJ¢Ù€SO3x<ªÔ©4¿+ç¶A`q@Ì“Úñè™ÍÿJÌ´ª-˜ÆtÊÛL]Ïq*‘Ý”ì#ŸÌÏãY]@ê`¿ /ªfkØB4·®£ó z—Üw¥Pxù–ÞLШKÇN¾AkÙTf½è'‰g gÆv›Øuh~ a˜Z— ïj*á¥t d£“uÒ ¨`K˜¹ßþ]b>˜]_ÏÔ6W—è2r4x•íÖ…"ƒÖNîä!¦å Ú}ýxGøÌ —@ ;ÆÚŠ=ɾ1ý8lªË¥ô ^yf®Œ¢u&2©nÙÇ›ñÂñŒ³ aPo['½»øFùà­+4ê“$!lövlüÞ=;N®3ð‚õ›DÉKòÞ>ÄÍ ¥ˆuߤ#ˆ$6ù™¥îЇy’ÍB¼ çxÛ;X"WL£R÷͝*ó-¶Zu}º.s¸sšXqù–DþÿvªhüïwyŸ ¯é³lÀ:KCûÄ£Ëá\…­ ~—ýóî ¼ûûÜTÓüÇy…ŽÆvc»¾×U ñ¸žþоP÷¦ó:Ò¨¨5;Ð#&#ÖúñläÿÁœ GxÉ­/ñ‡áQðìYÉtÒw޼GÔ´zàÒò ð*ëzƒ•4~H]Ø‹f ñÓÈñ`NåWçs'ÆÏW^ø¹!XžµmQ5ÃËoLœÎ: ÞËÍ¥J ù…î èo£ßPÎñ¶ž8.Œ]ʵ~5›ÙË-ù*8ÙÖß±~ ©¹rÓê‚j¶d¸{^Q'˜±Crß ÚH—#¥¥QlÀ×ëã‡DÜ«èî þ&Çæžî;ŽÏºò6ÒLÃXy&ZŒ'j‚¢Ù€IßÚù+–MGi‰*jE€‘JcÜ ÓÌ EÏÚj]o˜ Þr <¾U ûŪæÍ/šÝH¥˜b”¼ ÁñßX GP›ï2›4WŠÏà×£…íÓk†¦H·ÅíMh–*nó÷à]ÁjCº€b7<ب‹¨5車bp2:Á[UªM„QŒçiNMa#<5›áËó¸HýÊ"…×Éw¹¦ì2º–x<›»a±¸3Weü®FÝ⑱ö–î–³|LPÈ~çð~Çå‡|º kD¢µÏàÆAI %1À% ¹Ò – ”ϝS¦‰4&¶£°à Öý”û_Ò Áw°A«Å€?mÇÛgHÉ/8)á¾ÛìáöŽP í¨PŸNÙµº¦‡§Ùš"ÿ«>+ªÕ`Ê÷‡‚ß Õû˜þãÇ-PÍ.¾XV‘€ dÜ"þ4¹ ±Oú‘©t¥¦FªÄÃÄ•b‚znýu½—#cDs˜ÃiÑOˆñ×QO=*IAÊ,¶ŽZƒ;‡wøXè%EÐk:F±Ú” .Ѽ+Áu&Ç`."pÈÉw o&¿dE6‘’EqTuK@Ì¥ã™À(Êk(h‰,H}RÀIXÛš3µ1©_OqÚÒJAñ$ÊÙÜ;D3çŒ[þùœh¬Ã³™ö6ç†NY".Ú‰ï[ªŸŒ '²Ð öø_¨ÂÉ9ué¶³ÒŠõTàîMØ#û¯gN‡bÙ놚X„ö …ÉeüÌ^J ‹€.œ$Æ)βÄeæW#óüßĺŸ€ ÀzwV 9oä»f4V*uB «Ë†¹ì¯žR霓æHXa=&“I4K;¯ç‹h×·"UŠ~<•╪Vêª&ÍSÃÆÅ?ÔqÎ*mTM ˜›µwêd#[C¡©§‘D<©àb†–ÁœøvH/,í:¯( ²£|4-„Æövv„Yͼ™^Á$ˆ„¢Û[6yB.åH*V¨æ?$=˜Ñ€•ñ·­(VlŸ‘ nÀt8W÷´Bûba?q9ú¶Xƒl«ÿ\ù¶’þòUÐj/õ¢Ìµ³g$ƒÎR!¸»|Oߍë’BhîÚÑ¢ñåŒJ„®„£2Ð3•ô02Nt…!£Í]Ïc½Qÿ?ˆ<&ÃA¾Ú,JˆijÌ#5yz„‰Î|ÊŽ5QÏ:‹ÐaóVÔxW—CpeÏzÐïíçôÿÅ_[hãsÐ_/ŽTÝ?BîˆííV$<¿i>²F¬_Eß¿ †bÊŒº­ÿ®Z H“C}”¬,Mp ý/Bá£w>˜YV°aƒúh+cŠ- r/[%|üUMHäQ°X»|û/@|°¥Ð !BÔ Ç¢Ä©š+Õì D«7ìN¶ŽðÔ " ƶ’ÖçtA‰Û×}{tþz­¾GÍ›k¹OEJR$ Â׃ «ëÁ"oÉôž$oUK(Ä)Ãz³Ê-‹êN[Ò3Œñbï8P 4ƒ×q¢bo|?<ÛX¬òÄͰL–±›(™ûG?ýË©ÚÄ–ÂDØÐ_Ç¡ô ¾–ÄÏø ×e8Ë©$ÄF¹Å‹ì[©óìl:F¾f´‹‹Xì²ï®\¬ôùƒ ÿat¥óèÒùHß0äe‚;ü×h:ÆWðHž=Ã8骣"kœ'Y?³}Tûè€>?0l›e1Lòñ„aæKÆw…hÖŠùW…ÈÆÄ0ši·›[pcwËþñiêíY/~-Á5˜!¿†A›™Mÿþ(±“t@â“ö2­´TG5yé]çå僳 .·ÍïçÝ7UÚ±Ð/Nè»,_Ï ùdj7\ï Wì4›„»c¸àešg#ÒÊ⥭áØo5‘?ÌdÝô¯ ¹kzsƒ=´#ëÉK›Ø´±-¥eW?‡çßtòTã…$Ý+qÿ±ƒ÷_3Ô¥í÷:æ–ž<·Ö‡‰Å¢ š‡%Ô—utÌÈìðžgÖÀz²À—ï÷Óîäõ{K'´È÷³yaÏÁjƒô}ž§®æÊydÕÈë5¯èˆõvÕ©ã*çD„ “z„Ó‡^^xÂ3M§A´JG‚öï 3W'ˆ.OvXè¡ÊÕª?5º7†˜(˜Ç¶#çê’¶!ÌdZK§æ 0fãaN]òY³RV ™î$®K2R¨`W!1Ôó\;Ý ýB%qæK•&ÓÈe9È0êI±žeŸß -ú@žQr¦ ö4»M¼Áè¹µmw 9 EÆE_°2ó„ŸXKWÁ×Hóì^´²GѝF©óäR†¦‰ç"V»eØ<3ùd3ÿÚ¤Žú“Gi" —‘_ÙËÎ~Üö¯¥½Î»üŸEÚŽåmÞþí ;ÞólËΦMzA"Âf(´òá;Éï(/7½ûñÌ­cïÕçлþÝz¾-ÍvÑ“pH­–ðÓj$¸Äû¤‚‘ãUBË-n“2åPkS5&‹Â|+g^œ®Ì͆d!OïäîU«c;{Û!ÅŽ«ëZ9Ókóˆ]¯ƒ›né `ÇÒ+tÆš (ØKá¾—=3œ®•vuMñg²\ï Ec€ 05±d™‡×iÇ×›UúvÌ¢£Èþ¡ÕØô¶ßÎA"ß±#Ö²ˆÊŸ¦*Ä~ij|àø.-¼'»Ú¥£h ofº¦‡VsR=N½„Î v˜Z*SÌ{=jÑB‹tê…;’HžH¯8–îDù8ñ¢|Q•bÛçš–‹m³“ê¨ åÏ^m¬Žãþ©ïêO‡½6] µÆ„Ooòü ²x}N¦Ë3ïé¿»€›HA˜m%çÞ/¿í7Fø“‹léUk)É°Œµ8Q8›:ÀŠeT*šõ~ôڝG6 ¢}`ùH­–”¡k ‰P1>š†®9z11!X wKfmÁ¦xÑ,N1Q”–æB¶M…ÒÃv6SMˆhU¬ÊPŽï‘öj=·CŒ¯u¹ƒVIЃsx4’ömÛýcå¡¶7ßŠß 57^\wÒÐÆ k§h,Œý î«q^R½3]J¸ÇðN ‚çU¬ôº^Áì} ³f©Õœ§ˆã:FÄÈ‚é(€™?àýÓüè1Gô£¼éj‚OÅñ  #>×—ßtà 0G¥Åa뀐kßhc™À_ÉñÞ#±)GD" YîäË-ÿÙ̪ ¹™a¯´¢E\ÝÒö‚;™„ë]_ p8‰o¡ñ+^÷ 3‘'dT4œŽ ðVë½° :¬víÑ«£tßÚS-3¶“þ2 †üüʨòrš¹M{É_¤`Û¨0ìjœøJ‡:÷ÃáZ˜†@GP&œÑDGÏs¡þ¦þDGú‘1Yá9Ôþ¼ ûø…§÷8&–ÜÑnÄ_m®^üÆ`;ÉVÁJ£?â€-ßê}suÍ2sõA NÌúA磸‘îÿÚ»ƒìö·á¿±tÑÐ"Tÿü˜[@/äj¬€uüªìù¥Ý˜á8Ý´sõj 8@rˆð äþZÇD®ÿUÏ2ùôõrBzÆÏÞž>Ì™xœ“ wiÎ×7_… ¸ \#€MɁV¶¥üÕÿPÔ9Z‡ø§É8#H:ƒ5ÀÝå9ÍIŒ5åKÙŠ÷qÄ>1AÈøžj"µÂд/ªnÀ qªã}"iŸBå˜ÓÛŽ¦…&ݧ;G@—³b¯“•"´4í¨ôM¨åñC‹ïùÉó¯ÓsSH2Ý@ßáM‡ˆKÀªÛUeø/4\gnm¥‹ŸŒ qÄ b9ÞwÒNÏ_4Ég³ú=܆‚´ •â¥õeíþkjz>éÚyU«Íӝ݃6"8/ø{=Ô¢»G¥ äUw°W«,ô—¿ãㆅү¢³xŠUû™yŒ (øSópÐ 9\åTâ»—*oG$/×ÍT†Y¿1¤Þ¢_‡ ¼ „±ÍçèSaÓ 3ÛMÁBkxs‰’R/¡¤ˆÙçª(*õ„üXÌ´ƒ E§´¬EF"Ù”R/ÐNyÆÂ^°?™6¡œïJ·±$§?º>ÖüœcNÌù¯G ‹ñ2ЁBB„^·úìaz¨k:#¨Æ¨8LÎõލ£^§S&cŒÐU€ü(‡F±Š¼&P>8ÙÁ ‰ p5?0ÊÆƒZl¸aô š¼¡}gÿ¶zÆC²¹¬ÎÖG*HB¡O<º2#ñŒAƒ–¡B˜´É$¥›É:FÀÔx¾u?XÜÏÓvN©RS{2ʈãk9rmP¼Qq̳ è¼ÐFׄ^¡Öì fE“F4A…!ì/…¦Lƒ… … $%´¾yã@CI¬ á—3PþBÏNÿ<ý°4Ü ËÃ#ØÍ~âW«rEñw‹eùMMHß²`¬Öó½íf³:‹k˜¯÷}Z!ã¿<¥,\#öµÀ¯aÒNÆIé,Ћ–lŽ#Àæ9ÀÒS·I’½-Ïp Äz¤Š Â* ­íÄ9­< h>׍3ZkËU¹§˜ŒŠ±f­’¤º³Q ÏB?‹#µíÃ¥®@(Gs«†vI¥Mµ‹Á©e~2ú³ÁP4ìÕi‚²Ê^ö@-DþÓàlÜOÍ]n"µã:žpsŽ¢:! Aõ.ç~ÓBûH÷JCÌ]õVƒd «ú´QÙEA–¯¯Œ!.ˆˆëQ±ù œ·Ì!Õâ )ùL„ÅÀlÚè5@B…o´Æ¸XÓ&Û…O«˜”_#‡ƒ„ûÈt!¤ÁÏ›ÎÝŠ?c9 â\>lÓÁVÄÑ™£eØY]:fÝ–—ù+p{™ðè û³”g±OƒÚSù£áÁÊ„ä,ï7š²G ÕÌBk)~ÑiCµ|h#u¤¶îK¨² #²vݯGãeÖ϶ú…¾múÀ¶þÔñ‚Š9'^($¤§ò “š½{éúp÷J›ušS¹áªCÂubÃH9™D™/ZöØÁ‡¦ÝÙŸ·kð*_”.C‹{áXó€‡c¡c€§/šò/&éš÷,àéJþ‰X›fµ“C¨œ®r¬"kL‰Â_q…Z–.ÉL~O µ›zn‚¹À¦Öª7\àHµšÖ %»ÇníV[¥*Õ;ƒ#½¾HK-ÖIÊdÏEÚ#=o÷Óò³´Š: Ç?{¾+9›–‘OEáU·S€˜j"ÄaÜ ŒÛWt› á–c#a»pÔZÞdŽtWê=9éöÊ¢µ~ ë ;Öe‡Œ®:bî3±ýê¢wà¼îpêñ¹¾4 zc¾ðÖÿzdêŒÑÒŝÀ‰s6¤í³ÎÙB¿OZ”+F¤á‡3@Ñëäg©·Ž ˆèª<ù@É{&S„œÕúÀA)‰h:YÀ5^ÂÓŒ°õäU\ ùËÍû#²?Xe¬tu‰^zÒÔãë¼ÛWtEtû …‚g¶Úüâî*moGè¨7%u!]PhÏd™Ý%Îx: VÒ¦ôÊD3ÀŽKÛËãvÆî…N¯ä>Eró–ð`5 Œ%u5XkñÌ*NU%¶áœÊ:Qÿú»“úzyÏ6å-၇¾ ´ ÒÊ]y žO‘w2Äøæ…H’²f±ÎÇ.ª|¥'gîV•Ü .̘¯€šòü¤U~Ù†*¢!?ò wý,}´°ÔÞnïoKq5µb!áÓ3"vAßH¡³¡·G(ÐÎ0Îò¼MG!/ài®@—¬04*`…«é8ªøøló“ˆÊ”èù¤…ßÊoÿé'ËuÌÖ5×È¡§ˆˆfŽë9}hìâ_!!¯  B&Ëö¶‰ÀAÙNVŸ Wh›¸®XÑJì¨ú“¿÷3uj²˜¨ÍÎìë±aúŠÝå¯ð*Ó¨ôJ“yºØ)m°WýOè68†ŸÏ2—‰Ïüꪫٚ¥‹l1 ø ÏÄFjêµvÌbü¦èÝx:X±¢H=MÐß—,ˆÉÇ´(9ú¾^ÅÚ4¿m‡$âX‘å%(AlZo@½¨UOÌÕ”1ø¸jÎÀÃÃ_ µ‘Ü.œº¦Ut: Æï’!=¯uwû#,“pþÇúŒø(é@?³ü¥‘Mo §—s@Œ#)§ŒùkL}NOÆêA›¸~r½¼ÙA—HJ«eˆÖ´*¡ÓpÌŸö.m<-"³ûÈ$¬_6­åf£ïÚâj1y§ÕJ½@dÞÁr&Í\Z%D£Íñ·AZ Û³øüd/ªAi†/Й~  ‡âĮҮÏh§°b—›Û«mJžòG'[ÈYýŒ¦9psl ýÁ ®±f¦x,‰½tN ‚Xª9 ÙÖH.«Lo0×?͹m¡å†Ѽ+›2ƒF ±Ê8 7Hցϓ²Æ–m9…òŸï]Â1äN†VLâCˆU .ÿ‰Ts +ÅÎx(%¦u]6AF Š ØF鈄‘ |¢¶c±soŒ/t[a¾–û:s·`i햍ê›ËchÈ…8ßÀUÜewŒðNOƒõD%q#éû\9¤x¹&UE×G¥ Í—™$ð E6-‡¼!ýpãÔM˜ Âsìe¯ñµK¢Ç¡ùôléœ4Ö£”À Š®Ðc ^¨À}ÙËŸ§›ºê{ÊuÉC ×Sr€¤’fÉ*j!úÓ’Gsùìoîßîn%ò· àc Wp÷$¨˜)û»H ×8ŽÒ€Zj¤3ÀÙºY'Ql¦py{-6íÔCeiØp‘‡XÊîÆUߢ܂ž£Xé¼Y8þ©ëgñß}é.ÎógÒ„ÃØËø¯»™§Xýy M%@NŠ À(~áÐvu7&•,Ù˜ó€uP‡^^®=_E„jt’ 403WebShell
403Webshell
Server IP : 41.207.40.59  /  Your IP : 216.73.216.58
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux srv-prod 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User : www-data ( 33)
PHP Version : 8.3.26
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/formation/filter/algebra/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/formation/filter/algebra/AlgParser.pm

## Last modification: 8/3/00 by akp
## Originally written by Daniel Martin, Dept of Math, John Hopkins
## Additions and modifications were made by James Martino, Dept of Math, John Hopkins
## Additions and modifications were made by Arnold Pizer, Dept of Math, Univ of Rochester

#use Data::Dumper;

package AlgParser;
use HTML::Entities;

%close = ();

sub new {
  my $package = shift;
  my (%ret);
  $ret{string} = "";
  $ret{posarray} = [];
  $ret{parseerror} = "";
  $ret{parseresult} = [];
  bless \%ret, $package;
  return \%ret;
}

sub inittokenizer {
  my($self, $string) = @_;
  $self->{string} =~ m/\G.*$/g;
  $self->{string} = undef;
  $self->{string} = $string;
  $self->{string} =~ m/\G.*$/g;
  $self->{string} =~ m/^/g;
}

$close{'{'} = '}';
$close{'['} = ']';
$close{'('} = ')';

$binoper3 = '(?:\\^|\\*\\*)';
$binoper2 = '[/*_,]';
$binoper1 = '[-+=><%!#]';
$openparen = '[{(\\[]';
$closeparen = '[})\\]]';
$varname = '[A-Za-z](?:_[0-9]+)?';
$specialvalue = '(?:e|pi|da|db|dc|de|df|dg|dh|di|dj|dk|dl|dm|dn|do|dp|dq|dr|ds|dt|du|dv|dw|dx|dy|dz|infty|alpha|bita|gamma|zita|thita|iota|kappa|lambda|mu|nu|xi|rho|sigma|tau|phi|chi|psi|omega|zepslon|zdelta|xeta|zupslon|zeroplace)';
$numberplain = '(?:\d+(?:\.\d*)?|\.\d+)';
$numberE = '(?:' . $numberplain . 'E[-+]?\d+)';
$number = '(?:' . $numberE . '|' . $numberplain . ')';
#
#  DPVC -- 2003/03/31
#       added missing trig and inverse functions
#
#$trigfname = '(?:cosh|sinh|tanh|cot|(?:a(?:rc)?)?cos|(?:a(?:rc)?)?sin|' .
#    '(?:a(?:rc)?)?tan|sech?)';
$trigfname = '(?:(?:a(?:rc)?)?(?:sin|cos|tan|sec|csc|cot)h?)';
#
#  End DPVC
#
$otherfunc = '(?:exp|abs|logten|log|ln|sqrt|sgn|step|fact|int|lim|fun[a-zA-Z])';
$funcname = '(?:' . $otherfunc . '|' . $trigfname . ')';

$tokenregexp = "(?:($binoper3)|($binoper2)|($binoper1)|($openparen)|" .
    "($closeparen)|($funcname)|($specialvalue)|($varname)|" .
    "($numberE)|($number))";

sub nexttoken {
  my($self) = shift;
  $self->{string} =~ m/\G\s+/gc;
  my($p1) = pos($self->{string}) || 0;
  if(scalar($self->{string} =~ m/\G$tokenregexp/gc)) {
        push @{$self->{posarray}}, [$p1, pos($self->{string})];
        if (defined($1)) {return ['binop3',  $1];}
        if (defined($2)) {return ['binop2',  $2];}
        if (defined($3)) {return ['binop1',  $3];}
        if (defined($4)) {return ['openp',   $4];}
        if (defined($5)) {return ['closep',  $5];}
        if (defined($6)) {return ['func1',   $6];}
        if (defined($7)) {return ['special', $7];}
        if (defined($8)) {return ['varname', $8];}
        if (defined($9)) {return ['numberE', $9];}
        if (defined($10)) {return ['number', $10];}
  }
  else {
    push @{$self->{posarray}}, [$p1, undef];
    return undef;
  }
}

sub parse {
  my $self = shift;
  $self->{parseerror} = "";
  $self->{posarray} = [];
  $self->{parseresult} = ['top', undef];
  my (@backtrace) = (\$self->{parseresult});
  my (@pushback) = ();

  my $currentref = \$self->{parseresult}->[1];
  my $curenttok;

  my $sstring = shift;
  $self->inittokenizer($sstring);
  $currenttok = $self->nexttoken;
  if (!$currenttok) {
    if ($self->{string} =~ m/\G$/g) {
      return $self->error("empty");
    } else {
      my($mark) = pop @{$self->{posarray}};
      my $position = 1+$mark->[0];
      return $self->error("Illegal character at position $position", $mark);
    }
  }
  # so I can assume we got a token
  local $_;
  while ($currenttok) {
    $_ = $currenttok->[0];
    /binop1/ && do {
      # check if we have a binary or unary operation here.
      if (defined(${$currentref})) {
        # binary - walk up the tree until we hit an open paren or the top
        while (${$currentref}->[0] !~ /^(openp|top)/) {
          $currentref = pop @backtrace;
        }
        my $index = ((${$currentref}->[0] eq 'top')?1:3);
        ${$currentref}->[$index] = ['binop1', $currenttok->[1],
                                    ${$currentref}->[$index], undef];
        push @backtrace, $currentref;
        push @backtrace, \${$currentref}->[$index];
        $currentref = \${$currentref}->[$index]->[3];
      } else {
        # unary
        ${$currentref} = ['unop1', $currenttok->[1], undef];
        push @backtrace, $currentref;
        $currentref = \${$currentref}->[2];
      }
    };
    /binop2/ && do {
      if (defined(${$currentref})) {
        # walk up the tree until an open paren, the top, binop1 or unop1
        # I decide arbitrarily that -3*4 should be parsed as -(3*4)
        # instead of as (-3)*4.  Not that it makes a difference.

        while (${$currentref}->[0] !~ /^(openp|top|binop1)/) {
          $currentref = pop @backtrace;
        }
        my $a = ${$currentref}->[0];
        my $index = (($a eq 'top')?1:3);
        ${$currentref}->[$index] = ['binop2', $currenttok->[1],
                                    ${$currentref}->[$index], undef];
        push @backtrace, $currentref;
        push @backtrace, \${$currentref}->[$index];
        $currentref = \${$currentref}->[$index]->[3];
      } else {
        # Error
        my($mark) = pop @{$self->{posarray}};
        my $position =1+$mark->[0];
        return $self->error("Didn't expect " . $currenttok->[1] .
                            " at position $position" , $mark);
      }
    };
    /binop3/ && do {
      if (defined(${$currentref})) {
        # walk up the tree until we need to stop
        # Note that the right-associated nature of ^ means we need to
        # stop walking backwards when we hit a ^ as well.
        while (${$currentref}->[0] !~ /^(openp|top|binop[123]|unop1)/) {
          $currentref = pop @backtrace;
        }
        my $a = ${$currentref}->[0];
        my $index = ($a eq 'top')?1:($a eq 'unop1')?2:3;
        ${$currentref}->[$index] = ['binop3', $currenttok->[1],
                                    ${$currentref}->[$index], undef];
        push @backtrace, $currentref;
        push @backtrace, \${$currentref}->[$index];
        $currentref = \${$currentref}->[$index]->[3];
      } else {
        # Error
        my($mark) = pop @{$self->{posarray}};
        my $position = 1+$mark->[0];
        return $self->error("Didn't expect " . $currenttok->[1] .
                            " at position $position", $mark);
      }
    };
    /openp/ && do {
      if (defined(${$currentref})) {
        # we weren't expecting this - must be implicit
        # multiplication.
        push @pushback, $currenttok;
        $currenttok = ['binop2', 'implicit'];
        next;
      } else {
        my($me) = pop @{$self->{posarray}};
        ${$currentref} = [$currenttok->[0], $currenttok->[1], $me, undef];
        push @backtrace, $currentref;
        $currentref = \${$currentref}->[3];
      }
    };
    /func1/ && do {
      if (defined(${$currentref})) {
        # we weren't expecting this - must be implicit
        # multiplication.
        push @pushback, $currenttok;
        $currenttok = ['binop2', 'implicit'];
        next;
      } else {
        # just like a unary operator
        ${$currentref} = [$currenttok->[0], $currenttok->[1], undef];
        push @backtrace, $currentref;
        $currentref = \${$currentref}->[2];
      }
    };
    /closep/ && do {
      if (defined(${$currentref})) {
        # walk up the tree until we need to stop
        while (${$currentref}->[0] !~ /^(openp|top)/) {
          $currentref = pop @backtrace;
        }
        my $a = ${$currentref}->[0];
        if ($a eq 'top') {
          my($mark) = pop @{$self->{posarray}};
          my $position = 1+$mark->[0];
          return $self->error("Unmatched close " . $currenttok->[1] .
                              " at position $position", $mark);
        } elsif ($close{${$currentref}->[1]} ne $currenttok->[1]) {
          my($mark) = pop @{$self->{posarray}};
          my $position = 1+$mark->[0];
          return $self->error("Mismatched parens at position $position"
                              , ${$currentref}->[2], $mark);
        } else {
          ${$currentref}->[0] = 'closep';
          ${$currentref}->[2] = pop @{${$currentref}};
        }
      } else {
        # Error - something like (3+4*)
        my($mark) = pop @{$self->{posarray}};
        my $position = 1+$mark->[0];
        return $self->error("Premature close " . $currenttok->[1] .
                            " at position $position", $mark);
      }
    };
    /special|varname|numberE?/ && do {
      if (defined(${$currentref})) {
        # we weren't expecting this - must be implicit
        # multiplication.
        push @pushback, $currenttok;
        $currenttok = ['binop2', 'implicit'];
        next;
      } else {
        ${$currentref} = [$currenttok->[0], $currenttok->[1]];
      }
    };
    if (@pushback) {
      $currenttok = pop @pushback;
    } else {
      $currenttok = $self->nexttoken;
    }
  }
  # ok, we stopped parsing.  Now we need to see why.
  if ($self->{parseresult}->[0] eq 'top') {
    $self->{parseresult} = $self->arraytoexpr($self->{parseresult}->[1]);
  } else {
    return $self->error("Internal consistency error; not at top when done");
  }
  if ($self->{string} =~ m/\G\s*$/g) {
    if (!defined(${$currentref})) {
      $self->{string} .= " ";
      return $self->error("I was expecting more at the end of the line",
                        [length($self->{string})-1, length($self->{string})]);
    } else {
      # check that all the parens were closed
      while (@backtrace) {
        $currentref = pop @backtrace;
        if (${$currentref}->[0] eq 'openp') {
          my($mark) = ${$currentref}->[2];
          my $position = 1+$mark->[0];
          return $self->error("Unclosed parentheses beginning at position $position"
                         , $mark);
        }
      }
      # Ok, we must really have parsed something
      return $self->{parseresult};
    }
  } else {
      my($mark) = pop @{$self->{posarray}};
      my $position = 1+$mark->[0];
      return $self->error("Illegal character at position $position",$mark);
  }
}

sub arraytoexpr {
  my ($self) = shift;
  return Expr->fromarray(@_);
}

sub error {
  my($self, $errstr, @markers) = @_;
#  print STDERR Data::Dumper->Dump([\@markers],
#                                  ['$markers']);
  $self->{parseerror} = $errstr;
  my($htmledstring) = '<tt class="parseinput">';
  my($str) = $self->{string};
#  print STDERR Data::Dumper->Dump([$str], ['$str']);
  my($lastpos) = 0;
  $str =~ s/ /\240/g;
  while(@markers) {
    my($ref) = shift @markers;
    my($pos1) = $ref->[0];
    my($pos2) = $ref->[1];
    if (!defined($pos2)) {$pos2 = $pos1+1;}
    $htmledstring .= encode_entities(substr($str,$lastpos,$pos1-$lastpos)) .
           '<b class="parsehilight">' .
           encode_entities(substr($str,$pos1,$pos2-$pos1)) .
           '</b>';
    $lastpos = $pos2;
  }
#  print STDERR Data::Dumper->Dump([$str, $htmledstring, $lastpos],
#                                  ['$str', '$htmledstring', '$lastpos']);
  $htmledstring .= encode_entities(substr($str,$lastpos));
  $htmledstring .= '</tt>';
#  $self->{htmlerror} = '<p class="parseerr">' . "\n" .
#                       '<span class="parsedesc">' .
#                       encode_entities($errstr) . '</span><br>' . "\n" .
#                       $htmledstring . "\n" . '</p>' . "\n";
  $self->{htmlerror} =  $htmledstring ;
  $self->{htmlerror} =  'empty' if $errstr eq 'empty';
  $self->{error_msg} = $errstr;

#  warn $errstr . "\n";
  return undef;
}

sub tostring {
  my ($self) = shift;
  return $self->{parseresult}->tostring(@_);
}

sub tolatex {
  my ($self) = shift;
  return $self->{parseresult}->tolatex(@_);
}

sub tolatexstring { return tolatex(@_);}

sub exprtolatexstr {
  return exprtolatex(@_);
}

sub exprtolatex {
  my($expr) = shift;
  my($exprobj);
  if ((ref $expr) eq 'ARRAY') {
    $exprobj = Expr->new(@$expr);
  } else {
    $exprobj = $expr;
  }
  return $exprobj->tolatex();
}

sub exprtostr {
  my($expr) = shift;
  my($exprobj);
  if ((ref $expr) eq 'ARRAY') {
    $exprobj = Expr->new(@$expr);
  } else {
    $exprobj = $expr;
  }
  return $exprobj->tostring();
}

sub normalize {
  my ($self, $degree) = @_;
  $self->{parseresult} = $self->{parseresult}->normalize($degree);
}

sub normalize_expr {
  my($expr, $degree) = @_;
  my($exprobj);
  if ((ref $expr) eq 'ARRAY') {
    $exprobj = Expr->new(@$expr);
  } else {
    $exprobj = $expr;
  }
  return $exprobj->normalize($degree);
}

package AlgParserWithImplicitExpand;
@ISA=qw(AlgParser);

sub arraytoexpr {
  my ($self) = shift;
  my ($foo) = ExprWithImplicitExpand->fromarray(@_);
# print STDERR Data::Dumper->Dump([$foo],['retval']);
  return $foo;
}

package Expr;

sub new {
  my($class) = shift;
  my(@args) = @_;
  my($ret) = [@args];
  return (bless $ret, $class);
}

sub head {
  my($self) = shift;
  return ($self->[0]);
}


sub normalize {
#print STDERR "normalize\n";
#print STDERR Data::Dumper->Dump([@_]);

  my($self, $degree) = @_;
  my($class) = ref $self;
  $degree = $degree || 0;
  my($type, @args) = @$self;
  local $_;
  $_ = $type;
  my ($ret) = [$type, @args];


  if(/closep/) {
    $ret = $args[1]->normalize($degree);
  } elsif (/unop1/) {
    $ret = $class->new($type, $args[0], $args[1]->normalize($degree));
  } elsif (/binop/) {
    $ret = $class->new($type, $args[0], $args[1]->normalize($degree),
                             $args[2]->normalize($degree));
  } elsif (/func1/) {
    $args[0] =~ s/^arc/a/;
    $ret = $class->new($type, $args[0], $args[1]->normalize($degree));
  }


  if ($degree < 0) {return $ret;}


  ($type, @args) = @$ret;
  $ret = $class->new($type, @args);
  $_ = $type;
  if (/binop1/ && ($args[2]->[0] =~ 'unop1')) {
    my($h1, $h2) = ($args[0], $args[2]->[1]);
    my($s1, $s2) = ($h1 eq '-', $h2 eq '-');
    my($eventual) = ($s1==$s2);
    if ($eventual) {
      $ret = $class->new('binop1', '+', $args[1], $args[2]->[2] );
    } else {
      $ret = $class->new('binop1', '-', $args[1], $args[2]->[2] );
    }
  } elsif (/binop2/ && ($args[1]->[0] =~ 'unop1')) {
    $ret = $class->new('unop1', '-',
                       $class->new($type, $args[0], $args[1]->[2],
                                   $args[2])->normalize($degree) );
  } elsif (/binop[12]/ && ($args[2]->[0] eq $type) &&
                          ($args[0] =~ /[+*]/)) {
# Remove frivolous right-association
# For example, fix 3+(4-5) or 3*(4x)
    $ret = $class->new($type, $args[2]->[1],
                       $class->new($type, $args[0], $args[1],
                                   $args[2]->[2])->normalize($degree),
                       $args[2]->[3]);
  } elsif (/unop1/ && ($args[0] eq '+')) {
    $ret = $args[1];
  } elsif (/unop1/ && ($args[1]->[0] =~ 'unop1')) {
    $ret = $args[1]->[2];
  }
  if ($degree > 0) {
  }
  return $ret;
}

sub tostring {
# print STDERR "Expr::tostring\n";
# print STDERR Data::Dumper->Dump([@_]);
  my($self) = shift;
  my($type, @args) = @$self;
  local $_;
  $_ = $type;
  /binop1/ && do {
    my ($p1, $p2) = ('','');
    if ($args[2]->[0] eq 'binop1') {($p1,$p2)=qw{ ( ) };}
    return ($args[1]->tostring() . $args[0] . $p1 .
            $args[2]->tostring() . $p2);
  };
  /unop1/ && do {
    my ($p1, $p2) = ('','');
    if ($args[1]->[0] =~ /binop1/) {($p1,$p2)=qw{ ( ) };}
    return ($args[0] . $p1 . $args[1]->tostring() . $p2);
  };
  /binop2/ && do {
    my ($p1, $p2, $p3, $p4)=('','','','');
    if ($args[0] =~ /implicit/) {$args[0] = ' ';}
    if ($args[1]->[0] =~ /binop1/) {($p1,$p2)=qw{ ( ) };}
#    if ($args[2]->[0] =~ /binop[12]/) {($p3,$p4)=qw{ ( ) };}
    if ($args[2]->[0] =~ /binop[12]|unop1/) {($p3,$p4)=qw{ ( ) };}
    return ($p1 . $args[1]->tostring() . $p2 . $args[0] . $p3 .
            $args[2]->tostring() . $p4);
  };
  /binop3/ && do {
    my ($p1, $p2, $p3, $p4)=('','','','');
#    if ($args[1]->[0] =~ /binop[123]|numberE/) {($p1,$p2)=qw{ ( ) };}
    if ($args[1]->[0] =~ /binop[123]|unop1|numberE/) {($p1,$p2)=qw{ ( ) };}
#    if ($args[2]->[0] =~ /binop[12]|numberE/) {($p3,$p4)=qw{ ( ) };}
    if ($args[2]->[0] =~ /binop[12]|unop1|numberE/) {($p3,$p4)=qw{ ( ) };}
    return ($p1 . $args[1]->tostring() . $p2 . $args[0] . $p3 .
            $args[2]->tostring() . $p4);
  };
  /func1/ && do {
    return ($args[0] . '(' . $args[1]->tostring() . ')');
  };
  /special|varname|numberE?/ && return $args[0];
  /closep/ && do {
    my(%close) = %AlgParser::close;



    return ($args[0] . $args[1]->tostring() . $close{$args[0]});
  };
}

sub tolatex {
  my($self) = shift;
  my($type, @args) = @$self;
  local $_;
  $_ = $type;
  /binop1/ && do {
    my ($p1, $p2) = ('','');
    if ($args[2]->[0] eq 'binop1') {($p1,$p2)=qw{ \left( \right) };}
    return ($args[1]->tolatex() . $args[0] . $p1 .
            $args[2]->tolatex() . $p2);
  };
  /unop1/ && do {
    my ($p1, $p2) = ('','');
    if ($args[1]->[0] =~ /binop1/) {($p1,$p2)=qw{ \left( \right) };}
    return ($args[0] . $p1 . $args[1]->tolatex() . $p2);
  };
  /binop2/ && do {
    my ($p1, $p2, $p3, $p4) = ('','','','');
    if ($args[0] =~ /implicit/) {
      if ( (($args[1]->head eq qq(number)) &&
            ($args[2]->head eq qq(number))) ||
           (($args[1]->head eq qq(binop2)) &&
            ($args[1]->[2]->head eq qq(number))) ) {
        $args[0] = '\\,';
      } else {
        $args[0] = ' ';
      }
    }
    if ($args[1]->[0] =~ /binop1|numberE/)
      {($p1,$p2)=qw{ \left( \right) };}
 #   if ($args[2]->[0] =~ /binop[12]|numberE/)
        if ($args[2]->[0] =~ /binop[12]|numberE|unop1/)
      {($p3,$p4)=qw{ \left( \right) };}
    if ($args[0] eq '/'){
#   return('\frac{' . $p1 . $args[1]->tolatex() . $p2 . '}'.
#               '{' . $p3 . $args[2]->tolatex() . $p4 . '}' );
        return('\frac{' . $args[1]->tolatex() . '}'.
               '{' . $args[2]->tolatex() . '}' );
    }
    else{
    return ($p1 . $args[1]->tolatex() . $p2 . $args[0] . $p3 .
            $args[2]->tolatex() . $p4);
    }
  };
  /binop3/ && do {
    my ($p1, $p2, $p3, $p4)=('','','','');
#    if ($args[1]->[0] =~ /binop[123]|numberE/) {($p1,$p2)=qw{ \left( \right) };}
  if ($args[1]->[0] =~ /binop[123]|unop1|numberE/) {($p1,$p2)=qw{ \left( \right) };}
# Not necessary in latex
#   if ($args[2]->[0] =~ /binop[12]/) {($p3,$p4)=qw{ \left( \right) };}
    return ($p1 . $args[1]->tolatex() . $p2 . "^{" . $p3 .
            $args[2]->tolatex() . $p4 . "}");
  };
  /func1/ && do {
      my($p1,$p2);
      if($args[0] eq "sqrt"){($p1,$p2)=qw{ \left{ \right} };}
      else {($p1,$p2)=qw{ \left( \right) };}

      #
      #  DPVC -- 2003/03/31
      #       added missing trig functions
      #
      #$specialfunc = '(?:abs|logten|asin|acos|atan|sech|sgn|step|fact)';
      $specialfunc = '(?:abs|logten|a(?:sin|cos|tan|sec|csc|cot)h?|sgn|step|fact)';
      #
      #  End DPVC
      #

      if ($args[0] =~ /$specialfunc/) {
         return ('\mbox{' . $args[0] .'}'. $p1 . $args[1]->tolatex() . $p2);
      }
      else {
        return ('\\' . $args[0] . $p1 . $args[1]->tolatex() . $p2);
      }
  };
  /special/ && do {
    if ($args[0] eq 'pi') {return '\pi';} else {return $args[0];}
  };
  /varname|(:?number$)/ && return $args[0];
  /numberE/ && do {
    $args[0] =~ m/($AlgParser::numberplain)E([-+]?\d+)/;
    return ($1 . '\times 10^{' . $2 . '}');
  };
  /closep/ && do {
    my($backslash) = '';
    my(%close) = %AlgParser::close;
    if ($args[0] eq '{') {$backslash = '\\';}
#This is for editors to match: }
    return ('\left' . $backslash . $args[0] . $args[1]->tolatex() .
            '\right' . $backslash . $close{$args[0]});
  };
}

sub fromarray {
  my($class) = shift;
  my($expr) = shift;
  if ((ref $expr) ne qq{ARRAY}) {
    die "Program error; fromarray not passed an array ref.";
  }
  my($type, @args) = @$expr;
  foreach my $i (@args) {
    if (ref $i) {
      $i = $class->fromarray($i);
    }
  }
  return $class->new($type, @args);
}

package ExprWithImplicitExpand;
@ISA=qw(Expr);


sub tostring {
# print STDERR "ExprWIE::tostring\n";
# print STDERR Data::Dumper->Dump([@_]);
  my ($self) = shift;

  my($type, @args) = @$self;

  if (($type eq qq(binop2)) && ($args[0] eq qq(implicit))) {
    my ($p1, $p2, $p3, $p4)=('','','','');
    if ($args[1]->head =~ /binop1/) {($p1,$p2)=qw{ ( ) };}
#    if ($args[2]->head =~ /binop[12]/) {($p3,$p4)=qw{ ( ) };}
    if ($args[2]->head =~ /binop[12]|unop1/) {($p3,$p4)=qw{ ( ) };}
    return ($p1 . $args[1]->tostring() . $p2 . '*' . $p3 .
            $args[2]->tostring() . $p4);
  } else {
    return $self->SUPER::tostring(@_);
  }
}

Youez - 2016 - github.com/yon3zu
LinuXploit