Closed p6rt closed 15 years ago
Hi,
playing with pugs and parrot compiled perl6 i found this bug:
1st script :
#!/usr/local/bin/pugs -w
loop (my $i=0;$i\<2;$i++) { say $i; }
works well.
2nd script :
#!/usr/local/bin/pugs -w
my $n=7; if ($n > 2) { say "$n is bigger than 2";}
works well.
3rd script (is the concatenation of both 1st and 2nd):
#!/usr/local/bin/pugs -w
loop (my $i=0;$i\<2;$i++) { say $i; }
my $n=7; if ($n > 2) { say "$n is bigger than 2";}
crashes with this error: pugs t3.pl *** Unexpected "2" expecting operator or ";" at ./t3.pl line 9, column 10
Here's my pugs version : Version: 6.2.13.11 according pugs -v.
and per6 parrot compiled (THIS VERSION): This is Rakudo Perl 6, revision 30402 built on parrot 0.7.0-devel 11:57 \< pim> for i486-linux-gnu-thread-multi. complains like this: Statement not terminated properly at line 9, near "2) { say \""
current instr.: 'parrot;PGE::Util;die' pc 119 (runtime/parrot/library/PGE/Util.pir:82) called from Sub 'parrot;Perl6::Grammar;eat_terminator' pc 23817 (src/gen_grammar.pir:2840) called from Sub 'parrot;Perl6::Grammar;statementlist' pc 22866 (src/gen_grammar.pir:2473) called from Sub 'parrot;Perl6::Grammar;circumfix' pc 77039 (src/gen_grammar.pir:23163) called from Sub 'parrot;Perl6::Grammar;noun' pc 64913 (src/gen_grammar.pir:18584) called from Sub 'parrot;Perl6::Grammar;expect_term' pc 60176 (src/gen_grammar.pir:16796) called from Sub 'parrot;PGE::OPTable;parse' pc 1959 (compilers/pge/PGE/OPTable.pir:554)called from Sub 'parrot;Perl6::Grammar;arglist' pc 92058 (src/gen_grammar.pir:29009) called from Sub 'parrot;Perl6::Grammar;term' pc 67012 (src/gen_grammar.pir:19356) called from Sub 'parrot;Perl6::Grammar;noun' pc 65511 (src/gen_grammar.pir:18786) called from Sub 'parrot;Perl6::Grammar;expect_term' pc 60176 (src/gen_grammar.pir:16796) called from Sub 'parrot;PGE::OPTable;parse' pc 1959 (compilers/pge/PGE/OPTable.pir:554) called from Sub 'parrot;Perl6::Grammar;statement' pc 24619 (src/gen_grammar.pir:3146) called from Sub 'parrot;Perl6::Grammar;statementlist' pc 22764 (src/gen_grammar.pir:2437) called from Sub 'parrot;Perl6::Grammar;statement_block' pc 20803 (src/gen_grammar.pir:1665)called from Sub 'parrot;Perl6::Grammar;TOP' pc 17136 (src/gen_grammar.pir:225) called from Sub 'parrot;PCT::HLLCompiler;parse' pc 585 (src/PCT/HLLCompiler.pir:371) called from Sub 'parrot;PCT::HLLCompiler;compile' pc 438 (src/PCT/HLLCompiler.pir:303) called from Sub 'parrot;PCT::HLLCompiler;eval' pc 776 (src/PCT/HLLCompiler.pir:473) called from Sub 'parrot;PCT::HLLCompiler;evalfiles' pc 1078 (src/PCT/HLLCompiler.pir:610) called from Sub 'parrot;PCT::HLLCompiler;command_line' pc 1257 (src/PCT/HLLCompiler.pir:699) called from Sub 'parrot;Perl6::Compiler;main' pc 15352 (perl6.pir:172)
Hope this paste is not too long.
Notice : i talked about this error on irc #perl6 and they proposed me to post the bug here.
Kind regards. Jean-Yves.
On Wed, Sep 03, 2008 at 03:38:29AM -0700, Pim wrote:
#!/usr/local/bin/pugs -w
loop (my $i=0;$i\<2;$i++) { say $i; }
my $n=7; if ($n > 2) { say "$n is bigger than 2";} ------------------ crashes with this error: Unexpected "2" expecting operator or ";" at ./t3.pl line 9, column 10 [...] and per6 parrot compiled (THIS VERSION): Statement not terminated properly at line 9, near "2) { say \""
If both pugs and rakudo agree on an error, I'd bet that the problem is in the program and not the compiler(s). :-)
In this case, the problem is the lack of a space before the angle bracket in the loop statement:
loop (my $i=0;$i\<2;$i++) { ... if ($n > 2) { say "$n is bigger than 2";}
Perl 6 sees the angle bracket following the "$i" as being a subscript using the \<...> notation, which ends at the angle bracket in the "if" statement. It then complains about not understanding the "2" that follows the closing angle bracket.
S03:2793 notes this explicitly:
Note: any operator beginning with C\<\< \< >> must have whitespace in front of it, or it will be interpreted as a hash subscript instead.
So, add a whitespace character in front of the opening angle bracket, and all works (at least in rakudo):
$ cat x
#!/usr/local/bin/pugs -w
loop (my $i = 0; $i \< 2; $i++) {
say $i;
}
my $n = 7;
if ($n > 2) { say "$n is bigger than 2";}
$ ./parrot perl6.pbc x
0
1
7 is bigger than 2
Thanks!
Pm
The RT System itself - Status changed from 'new' to 'open'
Patrick (>):
If both pugs and rakudo agree on an error, I'd bet that the problem is in the program and not the compiler(s). :-)
In this case, the problem is the lack of a space before the angle bracket in the loop statement:
loop (my $i=0;$i\<2;$i++) { ... if ($n > 2) { say "$n is bigger than 2";}
Perl 6 sees the angle bracket following the "$i" as being a subscript using the \<...> notation, which ends at the angle bracket in the "if" statement. It then complains about not understanding the "2" that follows the closing angle bracket.
S03:2793 notes this explicitly:
Note: any operator beginning with C\<\< \< >> must have whitespace in front of it, or it will be interpreted as a hash subscript instead.
So, add a whitespace character in front of the opening angle bracket, and all works (at least in rakudo):
$ cat x #!/usr/local/bin/pugs -w
loop (my $i = 0; $i \< 2; $i++) { say $i; }
my $n = 7; if ($n > 2) { say "$n is bigger than 2";}
$ ./parrot perl6.pbc x 0 1 7 is bigger than 2
There's a related problem when using empty parens after the 'loop' keyword, however:
$ cat test.p6 loop () { } my $n
$ ./perl6 test.p6 Statement not terminated properly at line 1, near "{\n}\nmy $n\n" [...]
That can't be related to the \<...> notation. Are empty parens allowed here?
// Carl
On Wed, Sep 03, 2008 at 03:26:03PM +0200, Carl Mäsak wrote:
Patrick (>):
If both pugs and rakudo agree on an error, I'd bet that the problem is in the program and not the compiler(s). :-)
In this case, the problem is the lack of a space before the angle bracket in the loop statement:
There's a related problem when using empty parens after the 'loop' keyword, however:
$ cat test.p6 loop () { } my $n
$ ./perl6 test.p6 Statement not terminated properly at line 1, near "{\n}\nmy $n\n" [...]
That can't be related to the \<...> notation. Are empty parens allowed here?
According to STD.pm, empty parens aren't allowed -- the semicolons are required. One can write an infinite loop as either
loop { ... }
or
loop (;;) { ... }
At present Rakudo understands the first form but not the second (patches welcome -- mainly the grammar just needs to treat the expressions as optional instead of required).
Thanks!
Pm
That can't be related to the \<...> notation. Are empty parens allowed here?
According to STD.pm, empty parens aren't allowed -- the semicolons are required. One can write an infinite loop as either
loop \{ \.\.\. \}
or
loop \(;;\) \{ \.\.\. \}
At present Rakudo understands the first form but not the second (patches welcome -- mainly the grammar just needs to treat the expressions as optional instead of required).
As of index 78b38ad..61c292d, both forms of the infinite loop function as described. According to the grammer, expressions e1, e2, and e3 are all optional, making that second form valid.
I'm closing this ticket since the original source was missing the disambiguating space before C\<\< \< >> and the infinite loops work.
jswitzer@gmail.com - Status changed from 'open' to 'resolved'
Migrated from rt.perl.org#58544 (status was 'resolved')
Searchable as RT58544$