[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bison-like source locations in LALR-parser
From: |
Ludovic Courtès |
Subject: |
Re: Bison-like source locations in LALR-parser |
Date: |
Wed, 13 Aug 2014 23:01:47 +0200 |
User-agent: |
Gnus/5.130011 (Ma Gnus v0.11) Emacs/24.3 (gnu/linux) |
Hi,
Jan Nieuwenhuizen <address@hidden> skribis:
> Ludovic Courtès writes:
>
>> I don’t think this is needed. Lexers are expected to use
>> ‘make-lexical-token’ and ‘make-source-location’ from (system base lalr)
>> to preserve source location information.
>
> I hope you're right...and that's what I tried, but I didn't get it
> working. Possibly I need to cook-up a small example.
>
> What I found was that, yes the LEXER has all it needs, but once you
> get to construction rules in the parser; say
>
> (interface-spec
> (interface Identifier lbrace type-list event-list optional-behaviour
> rbrace) : `(,$1 ,$2 ,$4 ,$5 ,$6))
>
> all it sees is the values, i.e. strings of the tokens that the lexer
> sees. The lexer cannot hand tokens to the parser, AFAICS.
Here’s an example:
http://git.savannah.gnu.org/cgit/guile-rpc.git/tree/modules/rpc/compiler/lexer.l
http://git.savannah.gnu.org/cgit/guile-rpc.git/tree/modules/Makefile.am#n58
http://git.savannah.gnu.org/cgit/guile-rpc.git/tree/modules/rpc/compiler/parser.scm#n101
Note that actually, the ‘location’ produced by Makefile.am does:
(make-lexical-token type (make-source-location ...)
(append value (list (vector line column))))
So the line/column info is also stored alongside the token’s value, and
then access from parser.scm with those cadr calls.
>> Besides, note that lalr.upstream.scm is a copy of the upstream lalr-scm,
>> hosted at <http://code.google.com/p/lalr-scm/>.
>
> Yes...that's looks quit dead. Isn't it? I can try though...
Well, that’s because it’s “finished.” :-)
But yeah, it’s worth trying. Dominique has been responsive and helpful
in the past.
Thanks,
Ludo’.