caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Soegtrop, Michael" <michael.soegtrop@intel.com>
To: ??? <syshen@nudt.edu.cn>, caml-list <caml-list@inria.fr>
Subject: RE: [Caml-list] [OCAML]:: how to switch buffer in ocamllex?
Date: Wed, 25 Nov 2015 14:24:57 +0000	[thread overview]
Message-ID: <0F7D3B1B3C4B894D824F5B822E3E5A172CE439AC@IRSMSX102.ger.corp.intel.com> (raw)
In-Reply-To: <3796b53d.4c21.1513ef59b69.Coremail.syshen@nudt.edu.cn>

[-- Attachment #1: Type: text/plain, Size: 1557 bytes --]

Dear Shen,

the technique I typically use is to define a preprocessor, which sits in between the lexer and the parser. It provides the same interface to the parser as a lexer and takes your lexer at the other end. Your lexer also includes preprocessor tokens. The preprocessor usually just forwards tokens from the lexer to the parser, but it intercepts preprocessor tokens and then creates e.g. a new instance of the lexer to read from an include file or plays back token from a define. When the preprocessor receives an EOF token from an include file, it closes the include lexer and switches back to the main lexer. So typically the preprocessor maintains a stack of lexers. The advantage compared to messing around inside of the lexer is that it is clearer and more easily reused.

Best regards,

Michael


From: caml-list-request@inria.fr [mailto:caml-list-request@inria.fr] On Behalf Of ???
Sent: Wednesday, November 25, 2015 3:04 PM
To: caml-list
Subject: [Caml-list] [OCAML]:: how to switch buffer in ocamllex?

Dear all:

I am using ocamllex to write a lexer, the language I am analyzing have "include" mechanism that refer to another file.

So how can I open the refered file and switch to it in ocamllex?

Shen
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

[-- Attachment #2: Type: text/html, Size: 5266 bytes --]

  reply	other threads:[~2015-11-25 14:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-25 14:04 沈胜宇
2015-11-25 14:24 ` Soegtrop, Michael [this message]
     [not found]   ` <13dd7e2d.1043.1518465adb0.Coremail.syshen@nudt.edu.cn>
2015-12-09  8:42     ` Soegtrop, Michael
     [not found]       ` <1d2e3f25.10d7.15185feb280.Coremail.syshen@nudt.edu.cn>
2015-12-09 10:05         ` Soegtrop, Michael
2015-11-25 15:30 ` Gerd Stolpmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0F7D3B1B3C4B894D824F5B822E3E5A172CE439AC@IRSMSX102.ger.corp.intel.com \
    --to=michael.soegtrop@intel.com \
    --cc=caml-list@inria.fr \
    --cc=syshen@nudt.edu.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).