eof

bison end of file

大兔子大兔子 提交于 2019-11-29 04:03:38
If I forget to put an empty line at the end of any of my files my program gets a syntax error. The problem is my grammar expects a newline to end the current line. Since a newline doesn't exist bison generates a syntax error because it does not finish the rule. How do I solve this? I tried making <<EOF>> return MY_EOF BUT when I do that lex crashes a horrible death. I guess there's code in its default EOF that I am not calling. I have no idea what functions they may be. Using EOF create the error symbol EOF is used, but is not defined as a token and has no rules You could use a flex EOF rule

fseek on a position beyond EOF does not trigger EOF using feof, how come?

怎甘沉沦 提交于 2019-11-29 04:01:31
I'm reading data from a file to memory that is opened with: FILE *f = fopen(path, "rb"); Before I start copying bytes from the file I seek to a start position using: /** * Goes to the given position of the given file. * * - Returns 0 on success * - Returns -1 on EOF * - Returns -2 if an error occured, see errno for error code * - Returns -3 if none of the above applies. This should never happen! */ static int8_t goto_pos(FILE *f, uint64_t pos) { int err = fseek(f, pos, SEEK_SET); if (err != 0) { if (feof(f) != 0) return -1; if (ferror(f) != 0) return -2; return -3; } return 0; } The problem is

Python EOF for multi byte requests of file.read()

删除回忆录丶 提交于 2019-11-29 03:58:54
The Python docs on file.read() state that An empty string is returned when EOF is encountered immediately. The documentation further states: Note that this method may call the underlying C function fread() more than once in an effort to acquire as close to size bytes as possible. Also note that when in non-blocking mode, less data than was requested may be returned, even if no size parameter was given. I believe Guido has made his view on not adding f.eof() PERFECTLY CLEAR so need to use the Python way! What is not clear to ME, however, is if it is a definitive test that you have reached EOF

How to prevent InputStream.readObject() from throwing EOFException?

孤人 提交于 2019-11-29 03:54:40
I serialize an object and save it as a file on my HDD. When I'm reading it, in only some occasions it throws EOFException . After couple of hours debugging I am not able to find a problem. Here is my code: public void serialize(MyClass myClass,String path) { FileOutputStream foStream = null; ObjectOutputStream ooStream = null; try { File file = new File(path); if (!file.exists()) { file.createNewFile(); } foStream = new FileOutputStream(file); ooStream = new ObjectOutputStream(foStream); ooStream.writeObject(myClass); } catch (Throwable t) { log.error(t); } finally { if (ooStream != null) {

How to read user input until EOF?

允我心安 提交于 2019-11-29 02:10:01
问题 My current code reads user input until line-break. But I am trying to change that to a format, where the user can write input until strg+d to end his input. I currently do it like this: input = raw_input ("Input: ") But how can I change that to an EOF-Ready version? 回答1: Use file.read: input_str = sys.stdin.read() According to the documentation: file.read([size]) Read at most size bytes from the file (less if the read hits EOF before obtaining size bytes). If the size argument is negative or

Vim show newline at the end of file

二次信任 提交于 2019-11-28 19:09:21
Using the set eol option Vim automatically adds a newline to the end of the file when it's saved. I have this option on but I would like to be able to see this newline in Vim, so I know that it's actually there. For example with a file in Vim: And the same file in TextMate: This always tricks me and I end up adding a second new line and end up realizing later. This exact same question was posted here but the answer that was accepted didn't answer this portion of the question. Using set list : I can see there is a $ character denoting a new line after the last line but this also litters the

PyCharm. /usr/bin/python^M: bad interpreter [duplicate]

寵の児 提交于 2019-11-28 18:33:07
This question already has an answer here: ./configure : /bin/sh^M : bad interpreter [duplicate] 15 answers Cannot figure out, where to change EOF in PyCharm. My scripts, started with: #!/usr/bin/python # -*- coding: utf-8 -*- Outputs something like this, when I try to run it like executable (chmode +x): -bash: ./main.py: /usr/bin/python^M: bad interpreter: No such file or directory What to do and how to be? Set line separator to Unix : The issue is not EOF but EOL. The shell sees a ^M as well as the end of line and thus tries to find /usr/bin/python^M . The usual way of getting into this state

Spring Rest Template usage causes EOFException

[亡魂溺海] 提交于 2019-11-28 15:19:19
问题 I'm receiving java.io.EOFException 's when using Spring REST template on Android. The stacktrace cause reads like this: Caused by: java.io.EOFException at libcore.io.Streams.readAsciiLine(Streams.java:203) at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:560) at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:813) at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274) at libcore.net.http.HttpURLConnectionImpl.getResponseCode

Match from pattern to end of file in bash

寵の児 提交于 2019-11-28 13:54:56
I have been trying to figure out how to use grep in a bash script to match from a pattern to the end of the file. The file is not always the same number of lines each time and is not always [A-Za-z0-9] . I'm trying to migrate from a flat-file based catalog to a database. File excerpt: First, Last: Doe, John ID: xxxxxxxx ... Case Notes: This "person" does not exist! Please do not add him. Thanks. I need to grab everything from Case Notes: to the end of file. I can't seem to find anything to help out there as there isn't an actual EOF character. Ideas? ajk An awk script might be easier: awk '/

Problem with EOF when determine stream end

送分小仙女□ 提交于 2019-11-28 13:06:16
When I try to determine end of file with function feof(FILE *) , I find it does not work as I expected: an extra read is required even if the stream does end. e.g. feof(FILE*) will not tell true if invoked on a file with 10 bytes data just after reading 10 bytes out. I need an extra read operation which of course return 0, then feof(FILE *) will say "OK, now you reach the end." My question is why does one more read required and how to determine end of file or how to know how many bytes left in a file stream if I don't want the feof -style? Thanks and Best Regards. Do not use feof() or any