Greetings! I am fairly new at using Bison and Flex. I've googled this a bit and read most of the Bison manual. Here's my problem:
test.l returns these tokens: WORD - series of alphanumeric characters WHITE - series of [:blank:] characters NL - newline character EF - end-of-file character '*' - an asterisk, for bolds and lists I am trying to make a simple markup language, that will take a text file and change it into an HTML file (eventually, thiss will be part of a Wiki i'm writing, but for now, it's just outputting to stdout). test.y contains: /////////////////////////////////////////////// %{ #include "./scan.yy.h" %} /* because defining YYSTYPE to char * gave me compiler errors; didn't want to fix that right now */ %union { char *str } /* %token <str> X for the tokens that flex returns; skipped for brevity */ %type <str> PAGE LINE SENTENCE BOLD %% /* note that I've done some memory allocation and concatenation that I've shorthanded in actions here; * the problem isn't memory allocation; i've not gotten that far yet. */ PAGE: LINE {$$=$1;} | PAGE LINE {$$=$1+$2;} /* as I said, I shorthanded concatenation and memory management */ | PAGE EF {$$=$1+$2; YYACCEPT; } ; LINE: SENTENCE NL {$$=$1;} ; SENTENCE: WORD {$$=$1;} | SENTENCE WORD {$$=$1+$2;} | SENTENCE SPACE {$$=$1+$2;} | BOLD {$$=$1;} | SENTENCE BOLD {$$=$1+$2;} ; BOLD: '*' SENTENCE '*' {$$=""+$2+"";} ; /////////////////////////////////////// Now, when I try to run this through bison, it complains because there is an ambiguity: *WORD WHITE WORD * * WORD WHITE WORD* WHITE * WHITE right smack in the middle, there are 2 *'s, the second of which may mean an embedded BOLD, or it may mean the end of one BOLD and the start of another. (a shift/reduce conflict) My intention is to make this be 2 bolds, one after the other, interpreted in that way. Also, the final * (surrounded entirely by whitespaces) should simply be output. But that is contextual, as far as I can tell, and I can't figure out how to represent that in YACC. I'm stuck trying to get the 2 '*'s to be attached to the stuff in between them, and interpreted as though nesting were not allowed. I'm also stuck trying to get white-surrounded '*'s to be interpreted as simple asterisks. Could anyone help? -- View this message in context: http://www.nabble.com/Some-seeming-context-sensitivity%2C-and-shift-reduce-errors-tf4958973.html#a14202401 Sent from the Gnu - Bison - Help mailing list archive at Nabble.com. _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison