The main intention was to just save the whole useful data from file into linked list (t_line struct). But I needed to decide what exactly I would do next with data to know how and what I need to read and save. I had a few ideas about on-the-go parsing, but that seem to turn into way too complicated code. So I decided to save lines (segments for binary file -- this will be the next task) before doing any parsing or translation.
The tricky part would be to determine whether the last code line ends with \nor not if that line is actually the last one in the file.
In both cases codeline\nEOF (valid) and codelineEOF (not valid) get_next_line() would return 1 and the next time 0, and write into buffer codeline\0. I will use lseek() to 1 byte on the parsing stage to find out if \n was present.
And there is a case then the last line in file is a comment or just spaces. As I'm skipping such lines for non-last lines, I'm still saving the last one no matter if it is code or not. So later I could see that the last line is code (so I need lseek()) or not (so no further checks needed, the last code line obviously ended with \n).
Also I added structs to save parsed data, but that is more of a draft to guide the next steps. So some fields may be added/removed later.
t_error_data: to save detailed parsing error information to show user nice compiler-like error-message.
t_label: linked list of all labels met in file. Label part is also tricky as two or more labels could point to one operation.
Added asm-file reading and saving
The main intention was to just save the whole useful data from file into linked list (
t_line
struct). But I needed to decide what exactly I would do next with data to know how and what I need to read and save. I had a few ideas about on-the-go parsing, but that seem to turn into way too complicated code. So I decided to save lines (segments for binary file -- this will be the next task) before doing any parsing or translation.The tricky part would be to determine whether the last code line ends with
\n
or not if that line is actually the last one in the file. In both casescodeline\nEOF
(valid) andcodelineEOF
(not valid)get_next_line()
would return 1 and the next time 0, and write into buffercodeline\0
. I will uselseek()
to 1 byte on the parsing stage to find out if\n
was present. And there is a case then the last line in file is a comment or just spaces. As I'm skipping such lines for non-last lines, I'm still saving the last one no matter if it is code or not. So later I could see that the last line is code (so I needlseek()
) or not (so no further checks needed, the last code line obviously ended with\n
).Also I added structs to save parsed data, but that is more of a draft to guide the next steps. So some fields may be added/removed later.
t_error_data
: to save detailed parsing error information to show user nice compiler-like error-message.t_label
: linked list of all labels met in file. Label part is also tricky as two or more labels could point to one operation.