# New Ticket Created by Stuart Jansen
# Please include the string: [perl #49580]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=49580 >
Integers (NUMBRs) can be negative. Since Parrot makes it so easy to add
support for floats (NUMBARs), let's do that too.
---
languages/lolcode/src/parser/actions.pm | 3 +++
languages/lolcode/src/parser/grammar.pg | 9 ++++++---
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/languages/lolcode/src/parser/actions.pm b/languages/lolcode/src/parser/actions.pm
index 48dc0fa..f5ccb76 100644
--- a/languages/lolcode/src/parser/actions.pm
+++ b/languages/lolcode/src/parser/actions.pm
@@ -146,6 +146,9 @@ method integer($/) {
make PAST::Val.new( :value( ~$/ ), :returns('Integer'), :node($/) );
}
+method float($/) {
+ make PAST::Val.new( :value( ~$/ ), :returns('Float'), :node($/) );
+}
method boolean($/) {
if (~$/ eq 'FAIL' ) {
diff --git a/languages/lolcode/src/parser/grammar.pg b/languages/lolcode/src/parser/grammar.pg
index 6e41716..250172b 100644
--- a/languages/lolcode/src/parser/grammar.pg
+++ b/languages/lolcode/src/parser/grammar.pg
@@ -9,13 +9,15 @@ This is the grammar for lolcode written as a sequence of Perl 6 rules.
grammar lolcode::Grammar is PCT::Grammar;
rule TOP {
- 'HAI' <float> <statement_terminator>
+ 'HAI' <version> <statement_terminator>
<block>
'KTHXBYE' <statement_terminator>
[ $ || <panic: Syntax error> ]
{*}
}
+token version { \d+ [ '.' \d+ ]? }
+
rule statement {
| <visible> {*} #= visible
| <declare> {*} #= declare
@@ -93,6 +95,7 @@ rule expression {
}
rule value {
+ | <float> {*} #= float
| <integer> {*} #= integer
| <boolean> {*} #= boolean
| <quote> {*} #= quote
@@ -112,9 +115,9 @@ token keyword {
| 'BIGGR' | 'AN' | 'A' ] >>
}
-rule integer { \d+ {*} }
+rule integer { '-'? \d+ {*} }
-token float { \d+ [ '.' \d+ ]? }
+rule float { '-'? \d+ '.' \d+ {*} }
rule boolean { [ 'WIN' | 'FAIL' ] {*} }