Bison YACC compiler generator question
by schmitta from LinuxQuestions.org on (#5QPAM)
I have a grammar BOOK -> PAGES -> page -> lines -> line ->tokens. the book page can have any number of lines (set by user) and the line can have as many tokens as can fit the Line Length which is set by the user. I can't use ; to end a line as this is text. a token is added to the line with a space until the line length is reached then it is UNPUT. I do not know how to tell yacc that I can't fit any more tokens on a line and so to terminate the production and go back up the tree (un load the grammar stack ) This is probably my problem as my grammar is probably suppose to solve this but I do not know how. If a call or a bit could be set in yacc to tell it the line has been made and now reduce the grammar stack it would be useful to me. the input to yacc is a bunch of tokens with some commands
The input is just to feed tokens but the line being built determines when it is finished and is time to reduce.
one way to do this would be, upon a line full condition, unput the input a certain number of times and then insert a crazy string such as (}{) and have a bnf rule <data> ::=tokens token (}{) and then ask lex for the next token and it would get (}{) which would terminate the rule. Is this possible?
The input is just to feed tokens but the line being built determines when it is finished and is time to reduce.
one way to do this would be, upon a line full condition, unput the input a certain number of times and then insert a crazy string such as (}{) and have a bnf rule <data> ::=tokens token (}{) and then ask lex for the next token and it would get (}{) which would terminate the rule. Is this possible?