[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: %include
From: |
Bruce Mardle |
Subject: |
Re: %include |
Date: |
Sun, 30 Sep 2018 10:32:15 +0000 (UTC) |
> From: Akim Demaille <address@hidden>
> Sent: Sunday, 30 September 2018, 8:02
> > Le 29 sept. 2018 à 18:47, Bruce Mardle <address@hidden> a écrit :
> >
> > Hi, Akim (or anyone!). Since you’re on a bison-altering binge,
>
> Learning English every day :)
Glad to be of help :-)
> > would it be possible to implement a ‘%include' directive?
> > It would make my most recent bison-using project less confusing.
>
> It’s been on my todo list for years… Yes, it would be good
> to have something like that. However, as a C/C++ programmer,
> I have learnt to hate the concept of include, waiting eagerly
> for import.
Perhaps it'd help if I briefly describe my project (a Z280 assembler).
The file (everything.y) which bison processes is made by concatenating 3 file:
beginning.y, which I wrote,
middle.y, which is written by a C program I wrote, and
end.y, which I wrote.
So when bison finds an error, it reports the line number in terms of
everything.y, not 1 of the other 3 .y's.
It'd be nice if I could have a .y file containing all the bison code I wrote
with
%include "middle.y"
in the middle.
Alternatively, bison could have a %line direction, like C's #line. (Yes, I know
bison *outputs* #line directives, but it doesn't seem to allow them in .y
files.)
> For instance I would be happier if we had some form of scoping.
> For instance, maybe not all the nonterminals should be exposed
> from the imported grammar file to the importing one. Maybe
> too we should try to see if we can keep the precedence/associativity
> directives local to each subgrammar (currently there’s a single
> ’scale’ of precedences and precedences of the subgrammars would
> have ’naturally’ more precedence than that of the including
> grammar).
I think I'll have to ponder that some more before I understand it!
> > Other 'yaccs' have it.
>
> It would be interesting to see how others have done this: what
> tools are you thinking about?
Ermm, now I come to look again, the only variant I can find which supports
%include is btyacc:
https://www.siber.com/btyacc/
A hasty read of the source shows that the relevant code is in the function
get_line in file reader.c . I think it only accepts 1 level of
inclusion.
Ironically, my assembler allows included files nested 10 deep (or until it runs
out of file handles). My yylex has code something like:
if (start of line) {
while (current line of file on top of stack starts with "#include") {
open include file and stack it;
}
}
For some reason, I find that code amusing!
> PS/ I do not intend to work on this right now.
That's fine. My desire is not at all urgent.
- %include, Bruce Mardle, 2018/09/29
- Re: %include, Akim Demaille, 2018/09/30
- Re: %include,
Bruce Mardle <=