eof

END OF FILE token with flex and bison (only works without it)

我们两清 提交于 2019-12-02 06:14:25
OK this is kind of an odd question because what I have here works the way I want it to. What I'm doing is writing a parser for a lambda calculus expression. So an expression can be one of four things: variable constant (expression expression) (lambda variable.expression) Now as you can see, the last two expressions have expressions within them. What I was trying to do was determine the overall expression so I can report which type it is. So for example the expression ((lambda x.(f1 x)) 100) is a combination overall. My idea was to return an END token from flex when it reached the end of file.

Write an EOF to a pipe

孤街浪徒 提交于 2019-12-02 04:51:43
I have a parent and a child prozess and want to write an EOF from the parent to the child via a pipe... how does this work? here is my attampt: ---parent code--- if(dup2(parent_pipe[1], STDOUT_FILENO) == -1) { /*stdout gets closed and parent_pipe is duplicated with id of stdout*/ error("Can't duplicate the write-end of the pipe to stdout!"); } if(close(parent_pipe[0]) == -1) { error("Can't close read-end of the pipe!"); } char blub[] = "EOF"; if(write(parent_pipe[1], blub, strlen(blub)) == -1) { error("Failed to write the array"); } ---child code--- if(dup2(parent_pipe[0], STDIN_FILENO) == -1)

getchar() doesn't pass EOF and Ctrl+Z doesn't terminate the program on Cygwin

不想你离开。 提交于 2019-12-02 04:46:06
Here is a simple program, counting strings, symbols and words. Everything is ok with the computation, using Cygwin. But while launching, after input values, the program doesn't print nc , nw , nl and wait for entering further values. Changing EOF to 13 (Enter) doesn't help anyway. ctrl + Z is useful too: the program is stopping, writing [n]+ Stopped , where 'n' is always different number. The code is #include <stdio.h> #define IN 1 #define OUT 0 int main () { char c; int state; int nc, nw, nl; state = OUT; while ((c=getchar()) != EOF) { nc++; if (c == 'n') nw++; if (c == '\n' || c == ' ' || c

C EOF symbolic value and signed character

早过忘川 提交于 2019-12-02 03:32:26
today i just lay on my bed meditating programming stuff when an idea flows into my mind which i can't solve with my own ability.Below is the Question. I read a book that explain why EOF value is -1 and the explanation is as follow : Why -1?Normally getchar() returns a value in the range 0 through 127 , because those are values corresponding to the standard character set , but it might return values from 0 through 255 if the system recognizes an extended character set . In either case , the value -1 does not correspond to any character , so it can be used to signal the end of file. 1.)It is

eof of istream in C++

╄→гoц情女王★ 提交于 2019-12-02 01:28:34
问题 bool ios::eof ( ) const; According to the library, The function returns true if the eofbit stream's error flag has been set by a previous i/o operation. This flag is set by all standard input operations when the End Of File is reached in the sequence associated with the stream. I wrote a program to run some tests: int main(int argc, char *argv[]) { ifstream ifs(argv[1]); float f; ifs >> f; cout << ifs.eof() << endl; //check if eofbit set ifs.close(); } I tested 2 files, testcase1.txt and

How to solve an EOF error when reading a binary file

人走茶凉 提交于 2019-12-01 23:37:33
class CarRecord: # declaring a class without other methods def init (self): # constructor self .VehicleID = "" self.Registration = "" self.DateOfRegistration = None self.EngineSize = 0 self.PurchasePrice = 0.00 import pickle # this library is required to create binary f iles ThisCar = CarRecord() Car = [ThisCar for i in range (100)] CarFile = open ('Cars.DAT', 'wb') # open file for binary write for i in range (100) : # loop for each array element pickle.dump (Car[i], CarFile) # write a whole record to the binary file CarFile.close() # close file CarFile = open( 'Cars.DAT','rb') # open file for

Bash here document produces no output, any idea why?

ε祈祈猫儿з 提交于 2019-12-01 22:35:28
On my Acer 725 with Lubuntu 13.04 this little script: #!/bin/bash echo "======" echo <<xxxxx aaaaaaaaaqqqqqqqqq xxxxx echo "======" produces this output: ====== ====== It should produce this: ====== aaaaaaaaaqqqqqqqqq ====== I've searched all over for a reason but I can't find anything. I have a horrible feeling that I am missing something embarrassingly obvious. Any ideas? I have a horrible feeling that I am missing something embarrassingly obvious. Use cat instead of echo : cat <<xxxxx aaaaaaaaaqqqqqqqqq xxxxx Heredocs send the content to stdin. echo doesn't read from stdin. 来源: https:/

C++ Reading file backwards from the end of the file

一世执手 提交于 2019-12-01 20:30:58
问题 I am trying to write a program with a menu that reads from a text file a few different ways. I'm just working on menu option #2 still (reading backwards from the end of the file), but I can't wrap my head around what I'm doing wrong. I've been at this for a few days now and just can't find any good resources to help on this. Any help would be appreciated. #include <iostream> #include <string> #include <iomanip> #include <istream> #include <math.h> #include <fstream> using namespace std; const

eof of istream in C++

放肆的年华 提交于 2019-12-01 20:20:19
bool ios::eof ( ) const; According to the library, The function returns true if the eofbit stream's error flag has been set by a previous i/o operation. This flag is set by all standard input operations when the End Of File is reached in the sequence associated with the stream. I wrote a program to run some tests: int main(int argc, char *argv[]) { ifstream ifs(argv[1]); float f; ifs >> f; cout << ifs.eof() << endl; //check if eofbit set ifs.close(); } I tested 2 files, testcase1.txt and testcase2.txt. testcase1.txt was generated in the terminal with cat , [Ctrl-D] was used to end input: [~/C+

How to Handle EOFError for raw_input() in python in Mac OS X

此生再无相见时 提交于 2019-12-01 19:39:37
问题 My python program has two calls to raw_input() The first raw_input() is to take multiline input from the user. The user can issue Ctrl+D (Ctrl+Z in windows) for the end of input. Second raw_input() should take another input from user with (y/n) type prompt. Unfortunately (in Mac OS X only?), second raw_input() raises EOFError when the stdin is terminated (with Ctrl+D) at first raw_input() prompt. Please see my example code below for more explanation - mailBody = '' signature = 'Later!' print