Ticket #1424 (new bug)

Opened 12 years ago

Last modified 11 years ago

Parrot will not parse PIR missing newline at EOF

Reported by: Austin_Hastings Owned by: plobsing
Priority: normal Milestone:
Component: imcc Version: 2.0.0
Severity: medium Keywords:
Cc: Language:
Patch status: Platform:

Description

This script:

perl -e 'print ".sub foo\n\tsay \"Hello, world\"\n.end\n# Last line"' > x.pir 

produces a .pir file with no newline at the end. (Vim really WANTS to add a trailing newline, so beware how you look at it.)

You can check with

od -tx1z x.pir

which outputs something like:

0000000 2e 73 75 62 20 66 6f 6f 0a 09 73 61 79 20 22 48  >.sub foo..say "H<
0000020 65 6c 6c 6f 2c 20 77 6f 72 6c 64 22 0a 2e 65 6e  >ello, world"..en<
0000040 64 0a 23 20 4c 61 73 74 20 6c 69 6e 65           >d.# Last line<
0000055

At any rate, feeding that input to parrot (v2.0) produces:

austin@andLinux:~/kakapo$ parrot --output x.pbc x.pir
error:imcc:syntax error, unexpected $undefined, expecting $end (' ')
	in file 'x.pir' line 4

Appending a newline satisfies the parser.

Change History

Changed 12 years ago by kjs

My guess is this: Perhaps this has something to do with the comment on the last line? The lexer will match the # and everything up to and including the newline character, but it encounters EOF before it can read the NL.

Changed 12 years ago by whiteknight

The test t/compilers/imcc/syn/pasm.t actually tests that Parrot will fail if there is no trailing newline. If we "fix" that behavior, we need to update or delete that test.

Changed 12 years ago by Austin_Hastings

If that is the case, then the error message should be made more explicit: "missing newline at eof" or some such.

Changed 12 years ago by kurahaupo

Unlike Windows, Unix/Linux/POSIX considers that a file without a trailing newline is not a "text" file. In a "text file", every line includes its trailing newline, even (especially) the last one.

This has two implications:

  • the lines of two text files can be concatenated simply by concatenating their byte streams; and
  • it makes clear the distinction between a file containing one (empty) line, and a file containing zero lines.

So I concur that the error message should be made more explicit.

Changed 12 years ago by coke

  • owner set to plobsing
  • component changed from none to imcc

reassigning ticket to our new IMCC hacker.

Changed 11 years ago by Felipe

A simple fix for this issue:

diff --git a/compilers/imcc/imcc.l b/compilers/imcc/imcc.l
index 7b01b74..e2088ed 100644
--- a/compilers/imcc/imcc.l
+++ b/compilers/imcc/imcc.l
@@ -251,7 +251,7 @@ SP              [ ]
         yy_push_state(cmt5, yyscanner);
     }
 
-<cmt5>.*{EOL} {
+<cmt5>.*({EOL})? {
         if (imcc->expect_pasm == 2)
             BEGIN(INITIAL);
         else

Applying such fix will require to change t/op/basic.t test, which currently expects failure, because it has no newline in the end of file.

Changed 11 years ago by jkeenan

I applied the patch, rebuilt, and then tried the command AustinHastings recommended -- with no better results:

./parrot --output tt1424.pbc tt1424.pir
error:imcc:syntax error, unexpected $undefined, expecting $end (' ')
        in file 'tt1424.pir' line 2
error:imcc:syntax error ... somewhere
        in file 'tt1424.pir' line 2
syntax error ... somewhere

Changed 11 years ago by Felipe

It works fine for me.

felipe:~/dev/parrot$ perl -e 'print ".sub foo\n\tsay \"Hello, world\"\n.end\n# Last line"' > x.pir
felipe:~/dev/parrot$ ./parrot --output x.pbc x.pir
felipe:~/dev/parrot$ ./parrot x.pir 
Hello, world

Have Bison been detected when you ran Configure.pl? (--maintainer)

Note: See TracTickets for help on using tickets.