On 2022-09-06 13:54, Arthur Schwarz wrote: > Hi Akim; > > After a while I decided, why not. I might just as well answer you. Thanks for > your response. This will be a summary and not a point-to-point answer. It is > clear that Bison does not want to, and will not, proceed forwards, and so, > take this as me just grumbling in my cave. > > I do think the effort is moderately difficult. I do not believe it is as hard > as you have indicated. The languages you generate Bison for is modest, and > the semantics are similar (a caveat here since I don't know D). If you don't > want to develop you're own parser, then you can always fiddle with the gcc > (https://gcc.gnu.org/) front end to get a desired result.
Hi Arthur, The problem is that there is no C, D, Java or anything complete to parse until *after* Bison has done its job. Only then do you have a complete file that you can feed to some front-end to analyze for dependencies or what have you. I thought that the whole point of this proposed exercise is to determine how to put the program together from fragments in the first place. The way Bison works is that it needs to generate the correct, buildable output in a single pass. Speaking of passes, one thing you could theoretically do is treat this as a search problem. There are a finite number of pieces going into the grammar file, and they can be permuted in a finite number of ways, which could be searched for a permutation that results in something that compiles. There is the problem that during development, the code may be wrong, so that no permutation of that code combined into a parser source file will compile. Our permutation search loop is then sent on a time-consuming fool's errand that comes up with nothing. This is an important point: Bison can generate an output file even when the C, D, Java, ... snippets have errors in them. Those are then compile- or run-time errors for the language downstream. Under this search idea, integration with the build would be a sticking point, because how the code is compiled varies with the application's build environment. Bison output for ostensibly the same language, like C, can be built with different compilers in different environments. That could be addressed with some sort of hooks for build integration, which will likely be clunky to use. When you think about it, a tool like Yacc should have a simple specification: most of the code snippets in the second language should appear in the output in the same order as they appear in the grammar file. Except for situations when the order is unspecified (in which case the programmer is advised not to depend on it). On top of that there can be some mechanism to influence the order, like the named sections. That's it. > > "... fragile magic ..." Ahem. I suspect Akim may have been referring to what had been actually tried, in reference to named code blocks being developed to "depart from a model where Bison 'guessed' where to issue the user's code based on some heuristics".