[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: %include and #line

From: Bruce Mardle
Subject: Re: %include and #line
Date: Sun, 30 Sep 2018 15:39:42 +0000 (UTC)

> From: Akim Demaille <address@hidden>
> Sent: Sunday, 30 September 2018, 14:39
> Subject: Re: %include
> > The file (everything.y) which bison processes is made by concatenating 3 
> > file[s]:
> > beginning.y, which I wrote,
> > middle.y, which is written by a C program I wrote, and
> > end.y, which I wrote.
> Could you describe them a bit?  Or maybe it’s public somewhere?
> I’m especially interested in seing their structures.  Are the
> included files only composed of rules?

You should be able to view/fetch it from
I'm perfectly happy for anyone to use it for anything, though I don't think
anyone but me *has* used it, and I wouldn't use it for teaching good bison
Actually, I was lying about the names of the files (for clarity). The real
names are in the Makefile, which is pretty simple. That .zip doesn't actually
include 'middle.y', but, yes, it's just rules, 1 per Z280 instruction.

> That’s weird.  It is supposed to grok the #line in input too.
> Maybe you’ve put some in places we failed to cover?

Oh! I think I assumed that all bison's 'directives' start with '%' and didn't
think to check for "#line"!
So... my problem is solved :-D
Thank you very much, Akim!

> Amusingly, many years ago (almost 20 I think, Gosh!) I discussed
> with its author, Vadim Maslov, to include back-tracking into Bison.
> But all of the sudden, we were offered a full implementation of
> GLR for Bison (by Paul Hilfinger).  That was an amazing gift!

I didn't even know that bison did anything beyond LR(1)! I was sufficiently
impressed with that since, if I remember correctly, the original yacc only
did LALR(1).

> > 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.
> What are the constraints?  Is the included file allowed to declare
> %union members, or precedence, etc.?  Or must it be only rules
> (the middle section, between both %%)?

I don't know. I assume it %include's before the lexical phase.

<ramble>I wrote a compiler for a tiny language of my own in 2006. I originally
intended it to have macros similar to C's but they ended up as a name
associated with a node in the abstract syntax tree (AST). That's less flexible
but does, at least, avoid the pitfall with C macros that one can define 1
that's *not* a node in the AST, e.g.
#define foo -1
... bar foo ... // oops! Meant "bar*foo" but the compiler gave no error.
which, of course, is 1 reason to write
#define foo (-1)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]