When using the function compile_process_next_char or compile_process_peek_char...

Arthur Answered 3 answers
Question by Arthur 3 years ago

Question

When using the function compile_process_next_char or compile_process_peek_char you acess the compile_process struct inside the lex_struct to get the struct pos. why? the lex_struct already have this property, i m a little bit confused.

Answers

Answered by Daniel McCarthy

Instructor

Hi
Please define your question better as its too broad for me to understand your concern. Please list what your confused about in as much detail as possible so i can clarify. Please also only ask questions on dragonzap

Follow-up by Arthur

Question author

for example: char compile_process_next_char(struct lex_process* lex_process) { struct compile_process* compiler = lex_process->compiler; compiler->pos.col += 1; char c = getc(compiler->cfile.fp); if (c == '\n') { compiler->pos.line +=1 ; compiler->pos.col = 1; } return c; } this function access the struct 'pos' from the struct 'compile_process' even though the struct 'pos' is present inside the struct 'lex_process'. why not acess it directly instead of going for the field inside 'compile_process'? why did you declared the same property on two different structs? that's my question.

Answered by Daniel McCarthy

Instructor

I see you made duplicate question i deleted it. Please note that sending me emails, or creating new questions will not make me answer faster. I try to answer all questions within 24 hours but I also have commitments in my life. When you ask a question I will always respond please be patient I will always help you and my students. Regarding your question its much more clear now to me. From the top of my head I don't remember the reason I did it but it was likely to do with keeping abstraction. The position might be different for the compiler than the lexer if we later decided to provide other means of reading the file. You could just use the lexer position but I suppose I wanted to be more exact. I don't remember my reasoning but I am sure I had a good reason to do this. You'll probably find out as you continue the course. I can't remember the reason for everything I do because I have so many courses and they take many hours to develop but it was most likely to keep them abstracted from eachother for a compatability reason where the values could differ in the future.