guyz i need to pass an integer array from lex to yacc.i know v can pass an integer using union of yylval but how to pass an array ...pls help me
You can pass a pointer to the array, or, if the dimensions of the array are not known at compile time, create a struct with the array and the dimensions of the array, and pass a pointer to the struct.
There is nothing wrong with doing extensive work in the scanner and passing higher level constructs up to the parser. Just keep them organized with some sort of collection, and then pass back whatever indexes the collection.
If it's just something you malloc()
, you can pass a pointer, but it might seem better to pass some sort of unique magic cookie that can identify anything returned by the scanner. You can make any sort of map you want in the scanner that will tie the results to the scanner's data structures.
As one kind of oversimplified example, you could simply return a single increasing integer from the scanner, and have a map and some logic that would take that integer and figure out what the complete answer would have been.