Calendar - for "REAL" programmers: Difference between revisions

m
→‎{{header|Phix}}: use pygments
imported>Fth
No edit summary
m (→‎{{header|Phix}}: use pygments)
 
Line 2,819:
Although, if we are abusing the backticks and other innocent programs, why not just: <syntaxhighlight lang="perl">$_=$ARGV[0]//1969;`\143\141\154 $_ >&2`</syntaxhighlight>
=={{header|Phix}}==
I'm not going to take this too seriously and instead treat it as a good opportunity to showcase how trivial it is to make some rather fundamental changes to the compiler. So, the first task is to take a copy of [[Calendar#Phix|Calendar]] and make it output uppercase. Change the line in routine centre:
<!--<syntaxhighlight lang="phix">(phixonline)-->
 
--return repeat(' ',left)&s&repeat(' ',right)
So, the first task is to take a copy of [[Calendar#Phix|Calendar]] and make it output uppercase. Change the line
return repeat(' ',left)&upper(s)&repeat(' ',right)
<!--<syntaxhighlight lang="phix">(phixonline)-->
<!--</syntaxhighlight>-->
<span style="color: #008080;">return</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">' '</span><span style="color: #0000FF;">,</span><span style="color: #000000;">left</span><span style="color: #0000FF;">)&</span><span style="color: #000000;">s</span><span style="color: #0000FF;">&</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">' '</span><span style="color: #0000FF;">,</span><span style="color: #000000;">right</span><span style="color: #0000FF;">)</span>
(That's that done.) Now, Phix is case-sensitive, and many of the keywords and builtins are in lower case, which presents a bit of a challenge - but we can cope. It is too tedious and not particularly helpful to present a completed solution, instead I shall outline the (relatively simple) steps this would require. I have limited my tests to INCLUDE and INTEGER. In psym.e you can find the line
<!--</syntaxhighlight>-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
in routine centre to:
initialSymEntry("integer", S_Type,"TI",opInt, E_none) -- #01 / 0b0001 integer
<!--<syntaxhighlight lang="phix">(phixonline)-->
<!--</syntaxhighlight>-->
<span style="color: #008080;">return</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">' '</span><span style="color: #0000FF;">,</span><span style="color: #000000;">left</span><span style="color: #0000FF;">)&</span><span style="color: #7060A8;">upper</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)&</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">' '</span><span style="color: #0000FF;">,</span><span style="color: #000000;">right</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
(That's that done.) Now, Phix is case-sensitive, and many of the keywords and builtins are in lower case, which presents a bit of a challenge - but we can cope.<br>
It is too tedious and not particularly helpful to present a completed solution, instead I shall outline the (relatively simple) steps this would require. I have limited my tests to INCLUDE and INTEGER.
 
In psym.e you can find the line
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000000;">initialSymEntry</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"integer"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">S_Type</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TI"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">opInt</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">E_none</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- #01 / 0b0001 integer</span>
<!--</syntaxhighlight>-->
Immediately after that (it should now be there commented out) add:
<!--<syntaxhighlight lang="phix">(phixonline)-->
Alias("INTEGER",symlimit)
<span style="color: #000000;">Alias</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"INTEGER"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">symlimit</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
Add similar lines for length, floor, repeat, upper, day_of_week, sequence, string, sprintf, append, printf, join, at the appropriate places. Keywords are handled slightly differently: In pttree.e we need a new alias routine (you should find this one commented out, from when I was testing all this):
 
<!--<syntaxhighlight lang="phix">(phixonline)-->
Add similar lines for length, floor, repeat, upper, day_of_week, sequence, string, sprintf, append, printf, join, at the appropriate places.
procedure tt_stringA(sequence text, integer alias)
 
tt_string(text,-2)
Keywords are handled slightly differently: In pttree.e we need a new alias routine (you should find this one commented out, from when I was testing all this):
tt[pcurr] = alias
<!--<syntaxhighlight lang="phix">(phixonline)-->
end procedure
<span style="color: #008080;">procedure</span> <span style="color: #000000;">tt_stringA</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">text</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">alias</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
<span style="color: #000000;">tt_string</span><span style="color: #0000FF;">(</span><span style="color: #000000;">text</span><span style="color: #0000FF;">,-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">tt</span><span style="color: #0000FF;">[</span><span style="color: #000000;">pcurr</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">alias</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<!--</syntaxhighlight>-->
and you can find the line
<!--<syntaxhighlight lang="phix">(phixonline)-->
global constant T_include = 596 tt_stringF("include",T_include)
<span style="color: #008080;">global</span> <span style="color: #008080;">constant</span> <span style="color: #000000;">T_include</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">596</span> <span style="color: #000000;">tt_stringF</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"include"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">T_include</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
Sometime after that, in fact after the very last use of tt_stringF, add (likewise you should find this one commented out):
<!--<syntaxhighlight lang="phix">(phixonline)-->
tt_stringA("INCLUDE",T_include)
<span style="color: #000000;">tt_stringA</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"INCLUDE"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">T_include</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
 
Add similar lines for function, end, iff, for, to, do, if, or, then, else, return, procedure, but this time all some ways away from the originals. Quickly run "p p" and make sure you get a normal prompt, without any "T_include should be 624(not 596)" or suchlike (which would happen <i>alot</i> if you put the aliases anywhere other than last).
Line 2,863 ⟶ 2,852:
Currently ptok.e recognises <code>\n</code> but not <code>\N</code>. Search for all references to <code>escchar</code> (there should be one definition and two references) and make sure the character being
checked is mapped to lower case, ie change (twice)
<!--<syntaxhighlight lang="phix">(phixonline)-->
--Ch = find(Ch,escchar)
<span style="color: #000000;">Ch</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">Ch</span><span style="color: #0000FF;">,</span><span style="color: #000000;">escchar</span><span style="color: #0000FF;">)</span>
Ch = find(lower(Ch),escchar)
<!--</syntaxhighlight>-->
<!--</syntaxhighlight>-->
to
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000000;">Ch</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">lower</span><span style="color: #0000FF;">(</span><span style="color: #000000;">Ch</span><span style="color: #0000FF;">),</span><span style="color: #000000;">escchar</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
 
Lastly, the calendar example includes builtins\timedate.e, which contains some lower-case definitions. So copy it to (say) TIMEDATEUPPER.E and change adjust_timedate, timedelta, days (the 2nd param to timedelta), and format_timedate to their uppercase equivalents, and of course change that include to <code>INCLUDE BUILTINS\TIMEDATEUPPER.E</code>.
 
There are probably even simpler changes to ptok.e/pttree.e that would make everything case insensitive, but locating those is left as an exercise for the reader.<br> Likewise the changes that would be needed to pwa/p2js have been left as an exercise for the reader, but are assumed similarly trivial.
Likewise the changes that would be needed to pwa/p2js have been left as an exercise for the reader, but are assumed similarly trivial.
 
You don't actually have to repackage (p -c p) to test this, just run p p test.exw - technically slower by a second or so but only really noticeable long-term.
 
Finally, you can take that copy of [[Calendar#Phix|Calendar]] and make it all uppercase. In Edita (shipped with Phix) that is just <Ctrl A><Alt U>.
 
=={{header|PHP}}==
While PHP functions are case-sensitive (aside of <code>_()</code>), this isn't the case for language constructs.
7,796

edits