www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - __stdin.d(2): Error: found End of File when expecting }

reply Andre Pany <andre s-e-a-p.de> writes:
Hi,

this scripts throws 2 times this error:
__stdin.d(2): Error: found End of File when expecting } following 
compound statement
__stdin.d(2): Error: found End of File when expecting } following 
compound statement

```


text="
import std;

void main()
{
     while(true)
     {
         string enemy1 = readln().strip;
         int dist1 = to!int(readln().strip);

         string enemy2 = readln().strip;
         int dist2 = to!int(readln().strip);

         // Write an action using writeln()
         writeln(dist1 > dist2 ? enemy2 : enemy1);
         // Enter the code here
     }
}"

curl -fsS https://dlang.org/install.sh | bash -s dmd-2.087.0
source ~/dlang/dmd-2.087.0/activate
echo $text | dmd -
```

what is here wrong?
( I execute it using on Ubuntu 18.04 LTS using WSL)

Kind regards
André
Jul 17 2019
next sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Wed, Jul 17, 2019 at 07:05:20PM +0000, Andre Pany via Digitalmars-d-learn
wrote:
 Hi,
 
 this scripts throws 2 times this error:
 __stdin.d(2): Error: found End of File when expecting } following compound
 statement
 __stdin.d(2): Error: found End of File when expecting } following compound
 statement
My first suspicion is that the shell is interpreting metacharacters in your string and thereby mangling it. [...]
 ```

 
 text="
 import std;
 
 void main()
 {
     while(true)
     {
         string enemy1 = readln().strip;
         int dist1 = to!int(readln().strip);
 
         string enemy2 = readln().strip;
         int dist2 = to!int(readln().strip);
 
         // Write an action using writeln()
         writeln(dist1 > dist2 ? enemy2 : enemy1);
         // Enter the code here
     }
 }"
 
 curl -fsS https://dlang.org/install.sh | bash -s dmd-2.087.0
 source ~/dlang/dmd-2.087.0/activate
 echo $text | dmd -
 ```
 
 what is here wrong?
 ( I execute it using on Ubuntu 18.04 LTS using WSL)
 
 Kind regards
 André
-- IBM = I'll Buy Microsoft!
Jul 17 2019
prev sibling parent reply ag0aep6g <anonymous example.com> writes:
On 17.07.19 21:05, Andre Pany wrote:

 ```

 
 text="
 import std;
 
 void main()
 {
      while(true)
      {
          string enemy1 = readln().strip;
          int dist1 = to!int(readln().strip);
 
          string enemy2 = readln().strip;
          int dist2 = to!int(readln().strip);
 
          // Write an action using writeln()
          writeln(dist1 > dist2 ? enemy2 : enemy1);
          // Enter the code here
      }
 }"
 
 curl -fsS https://dlang.org/install.sh | bash -s dmd-2.087.0
 source ~/dlang/dmd-2.087.0/activate
 echo $text | dmd -
 ```
 
 what is here wrong?
Check out what `echo $text` prints: ---- import std; void main() { while(true) { string enemy1 = readln().strip; int dist1 = to!int(readln().strip); string enemy2 = readln().strip; int dist2 = to!int(readln().strip); // Write an action using writeln() writeln(dist1 > dist2 ? enemy2 : enemy1); // Enter the code here } } ---- Note that it's all on one line. And remember that a "//"-style comment spans the rest of the line. That's right. Everything after the first "//" is now part of the comment, all the way to the last closing brace. Obviously, that's not valid code anymore. Try using double quotes around $text: echo "$text" | dmd -
Jul 17 2019
parent Andre Pany <andre s-e-a-p.de> writes:
On Wednesday, 17 July 2019 at 20:02:51 UTC, ag0aep6g wrote:
 On 17.07.19 21:05, Andre Pany wrote:

 [...]
Check out what `echo $text` prints: ---- import std; void main() { while(true) { string enemy1 = readln().strip; int dist1 = to!int(readln().strip); string enemy2 = readln().strip; int dist2 = to!int(readln().strip); // Write an action using writeln() writeln(dist1 > dist2 ? enemy2 : enemy1); // Enter the code here } } ---- Note that it's all on one line. And remember that a "//"-style comment spans the rest of the line. That's right. Everything after the first "//" is now part of the comment, all the way to the last closing brace. Obviously, that's not valid code anymore. Try using double quotes around $text: echo "$text" | dmd -
Thanks a lot, that solved the issue. Kind regards Andre
Jul 17 2019