Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #1596

Re: lex - how to get current file position of parser file

Path csiph.com!xmission!news.glorb.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED!nerds-end
From Kaz Kylheku <kaz@kylheku.com>
Newsgroups comp.compilers
Subject Re: lex - how to get current file position of parser file
Date Tue, 1 Sep 2015 14:19:33 +0000 (UTC)
Organization Aioe.org NNTP Server
Lines 53
Sender news@iecc.com
Approved comp.compilers@iecc.com
Message-ID <15-09-001@comp.compilers> (permalink)
References <15-08-019@comp.compilers>
NNTP-Posting-Host news.iecc.com
X-Trace miucha.iecc.com 1441292553 54084 2001:470:1f07:1126:0:676f:7373:6970 (3 Sep 2015 15:02:33 GMT)
X-Complaints-To abuse@iecc.com
NNTP-Posting-Date Thu, 3 Sep 2015 15:02:33 +0000 (UTC)
Keywords parse, design
Posted-Date 03 Sep 2015 11:02:32 EDT
X-submission-address compilers@iecc.com
X-moderator-address compilers-request@iecc.com
X-FAQ-and-archives http://compilers.iecc.com
Xref csiph.com comp.compilers:1596

Show key headers only | View raw


On 2015-09-01, Jens Kallup <jkallup@web.de> wrote:
> Hello,
>
> I used flex, and bison under Linux.  But how can I handle multiple
> input files?  When I follow the examples of the documentation, I fail
> to handle tokens after include file.
>
> Example:
>
> PRINT "Before"
> SET PROCEDURE TO testproc
> PRINT "After"

> this is a abstract language, which does (should) open a file called
> "testproc".

I think that in a dBase-type language, SET PROCEDURE doesn't necessarily have
to open the file at parse time. According to current documentation that
I'm able to find, it's actually become a complex module-loading command, and
not parse-time textual inclusion. It can load compiled files, not only text,
and cause non-persistent files to be unloaded. Loaded files have a refcount so
that if you invoke SET PROCEDURE on some file N times, you have to CLOSE
PROCEDURE that many times before it is unloaded.

> But I can not handle line 3.
> I try to "ftell" the position after testproc,
> but get the size of the parser file.
>
> So, now I have no glue, how to fix that.  It would be great, if
> someone have a idea, and maybe a short code snippet.
>
> Thanks
> Jens
> [Flex buffers its input, so you can't just do an ftell().  Use the
> yy_create_buffer() and related routines.  If you have a copy of my
> book "flex & bison" there's an example of nested include files in
> chapter 2. -John]

The benefit of yy_create_buffer et al is that you maintain the illusion that
there is just a single stream of tokens, though multiple files are being
shuffled around by the lexer, which maintains the "include stack".  This
multiple stream of tokens is handled by a single parse job (one big yyparse).

Another approach (if you can design the language that way) is to specify
reentrant parser and lexer. This lets you issue a new, recursive call to
yyparse to handle the loaded/included file. The call has its own instance
of the lexer, which has no interaction with the suspended lexer of
the parent. If your parser builds an abstract syntax tree, then the phrase
structure rule for the include construct pulls out the AST from the nested
yyparse job, and integrates it into the surrounding AST.  Of course, this can't
be used if you're implementing "dumb" textual inclusion, such that the syntax
matched by a single phrase structure rule can span across multiple files, and
even start in one file and end in another.

Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

lex - how to get current file position of parser file Jens Kallup <jkallup@web.de> - 2015-09-01 04:20 +0200
  Re: lex - how to get current file position of parser file Kaz Kylheku <kaz@kylheku.com> - 2015-09-01 14:19 +0000
    Re: lex - how to get current file position of parser file federation2005@netzero.com - 2015-09-03 15:47 -0700
      Re: include files, was lex - how to get current file position of parser file Kaz Kylheku <kaz@kylheku.com> - 2015-09-04 05:26 +0000
    Re: lex - how to get current file position of parser file Gene Wirchenko <genew@telus.net> - 2015-09-03 18:19 -0700
      Re: lex - how to get current file position of parser file Jens Kallup <jkallup@web.de> - 2015-09-06 21:53 +0200
        Re: lex - how to get current file position of parser file Kaz Kylheku <kaz@kylheku.com> - 2015-09-07 05:59 +0000
    Re: lex - how to get current file position of parser file Jens Kallup <jkallup@web.de> - 2015-09-07 17:11 +0200

csiph-web