# New Ticket Created by Stephen Weeks # Please include the string: [perl #49358] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=49358 >
Add math support to lolcode. math ops are in src/builtins/math.pir
Index: MANIFEST =================================================================== --- MANIFEST (revision 24517) +++ MANIFEST (working copy) @@ -1542,6 +1542,7 @@ languages/lolcode/config/makefiles/root.in [lolcode] languages/lolcode/lolcode.pir [lolcode] languages/lolcode/src/builtins/say.pir [lolcode] +languages/lolcode/src/builtins/math.pir [lolcode] languages/lolcode/src/builtins/var_or_function.pir [lolcode] languages/lolcode/src/parser/actions.pm [lolcode] languages/lolcode/src/parser/grammar.pg [lolcode] Index: languages/lolcode/config/makefiles/root.in =================================================================== --- languages/lolcode/config/makefiles/root.in (revision 24523) +++ languages/lolcode/config/makefiles/root.in (working copy) @@ -39,6 +39,7 @@ BUILTINS_PIR = \ src/builtins/say.pir \ + src/builtins/math.pir \ src/builtins/var_or_function.pir # PMCS = lolcode Index: languages/lolcode/src/builtins/math.pir =================================================================== --- languages/lolcode/src/builtins/math.pir (revision 0) +++ languages/lolcode/src/builtins/math.pir (revision 0) @@ -0,0 +1,61 @@ + +.sub 'SUM' + .param pmc x + .param pmc y + $P0 = n_add x, y + .return ($P0) +.end + +.sub 'DIFF' + .param pmc x + .param pmc y + $P0 = n_sub x, y + .return ($P0) +.end + +.sub 'PRODUKT' + .param pmc x + .param pmc y + $P0 = n_mul x, y + .return ($P0) +.end + +.sub 'QUOSHUNT' + .param pmc x + .param pmc y + $P0 = n_div x, y + .return ($P0) +.end + +.sub 'MOD' + .param num x + .param num y + $N0 = mod x, y + .return ($N0) +.end + +.sub 'BIGGR' + .param pmc x + .param pmc y + $I0 = islt x, y + if $I0 goto y_biggr + .return (x) + y_biggr: + .return (y) +.end + +.sub 'SMALLR' + .param pmc x + .param pmc y + $I0 = isgt x, y + if $I0 goto y_smallr + .return (x) + y_smallr: + .return (y) +.end + +# Local Variables: +# mode: pir +# fill-column: 100 +# End: +# vim: expandtab shiftwidth=4: Index: languages/lolcode/src/parser/actions.pm =================================================================== --- languages/lolcode/src/parser/actions.pm (revision 24523) +++ languages/lolcode/src/parser/actions.pm (working copy) @@ -124,6 +124,12 @@ make PAST::Val.new( :value( $($<string_literal>) ), :node($/) ); } +method math($/) { + my $past := PAST::Op.new( :name(~$<op>), :node($/) ); + $past.push( $($<x>) ); + $past.push( $($<y>) ); + make $past; +} method identifier($/) { make PAST::Val.new( :value( ~$/ ), :node($/) ); Index: languages/lolcode/src/parser/grammar.pg =================================================================== --- languages/lolcode/src/parser/grammar.pg (revision 24523) +++ languages/lolcode/src/parser/grammar.pg (working copy) @@ -61,6 +61,7 @@ } rule value { + | <math> {*} #= math | <integer> {*} #= integer | <quote> {*} #= quote } @@ -70,7 +71,7 @@ token identifier { <!keyword> $<name>=( <[a..zA..Z]> \w* ) {*} } token keyword { - 'HOW' | 'I' | 'SAY' | 'SO' | 'U' | 'YR' | 'R' | 'AN' | 'IF' | 'KTHXBYE' + 'HOW' | 'I' | 'SAY' | 'SO' | 'U' | 'YR' | 'R' | 'AN' | 'IF' | 'KTHXBYE' | 'OF' | 'AN' | <math_word> } rule integer { \d+ {*} } @@ -82,6 +83,14 @@ {*} } +rule math { + $<op>=<math_word> OF $<x>=<expression> AN $<y>=<expression> {*} +} + +token math_word { + SUM | DIFF | PRODUKT | QUOSHUNT | MOD | BIGGR | SMALLR +} + token ws { <!ww> [ | ^^ \h* BTW \h \N* \n+ | ^^ \h* OBTW .*? ^^ \h* TLDR \n+