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" <syshen@nudt.edu.cn>
Cc: caml-list <caml-list@inria.fr>
Subject: RE: [Caml-list] [OCAML]:: how to switch buffer in ocamllex?
Date: Wed, 9 Dec 2015 10:05:16 +0000	[thread overview]
Message-ID: <0F7D3B1B3C4B894D824F5B822E3E5A172CE4923F@IRSMSX102.ger.corp.intel.com> (raw)
In-Reply-To: <1d2e3f25.10d7.15185feb280.Coremail.syshen@nudt.edu.cn>

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

Dear Shen,

I guess we first need to discuss your BNF syntax. As far as I understand { x } means 0..n repeats of x and [ x ] means 0 or 1 copy of x. But what does [ [ constant_expression ] ] or { [ expression ] } mean? Also not sure what you mean by […].

Verilog A is a bit different here (no constant_expression in identifiers):

identifier ::=
IDENTIFIER [ { . IDENTIFIER } ]
NOTE: The period in identifier may not be preceded or followed by a space.

Also, as you can see, Verilog A syntax specifies that identifiers may not contain spaces, so you either need to handle spaces in the parser or hierarchical identifiers in the lexer. I did the latter, since handling spaces in the parser is no fun. As a result I don’t have any conflicts around this. Does your Verilog variant have the same restriction regarding spaces and identifiers? If so, I would check if you can move the whole hierarchical_identifier to the lexer level. If you have to move space handling to the parser, your syntax will get very verbose.

There are typically ways to make parser generators accept grammars for common computer languages (maybe except for Fortran). But if a grammar is translated 1:1 from BNF to a parser generator you usually get some issues. There are many ways to express the same grammar with different BNF and some are more suitable for parser generators than others. So usually you need to restructure the BNF a bit. As I mentioned, I found the “explain” function of Menhir quite useful to understand what the issue is.

Best regards,

Michael


From: 沈胜宇 [mailto:syshen@nudt.edu.cn]
Sent: Wednesday, December 09, 2015 10:07 AM
To: Soegtrop, Michael
Cc: caml-list
Subject: Re: RE: RE: [Caml-list] [OCAML]:: how to switch buffer in ocamllex?

Dear Michael

 one of the problem is with :

hierarchical_identifier ::= { identifier [ [ constant_expression ] ] . } identifier

you can notice that hierarchical_identifier end without [...],
but some times hierarchical_identifier can followed by [...], like the following rule:

primary ::=
number
| hierarchical_identifier [ { [ expression ] } [ range_expression ] ]
..

In such case, the parser will run ahead to consume all the following [...], can complain about no identifier can be found in the first rule.

while in other case, the hierarchical_identifier do not followed by [...]

So does this means that I need something stronger that LA(1) that can look further ahead, but I think such thing may not exist becasue of complexity.




-----原始邮件-----
发件人: "Soegtrop, Michael" <michael.soegtrop@intel.com<mailto:michael.soegtrop@intel.com>>
发送时间: 2015-12-09 16:42:33 (星期三)
收件人: "syshen@nudt.edu.cn<mailto:syshen@nudt.edu.cn>" <syshen@nudt.edu.cn<mailto:syshen@nudt.edu.cn>>
抄送: caml-list <caml-list@inria.fr<mailto:caml-list@inria.fr>>
主题: RE: RE: [Caml-list] [OCAML]:: how to switch buffer in ocamllex?
Desr Shen,

I have a working parser for a subset of analog Verilog in Menhir. I haven’t worked with ocamlyacc but compared to C yacc or bison, Menhir is quite user friendly, e.g. the capability to explain conflicts. This gave me sufficient insight to slightly change the productions (not the grammar!) such that it is acceptable to Menhir. Unfortunately I cannot share my parser, but if you name the specific production rules you have issues with, I might be able to help.

Best regards,

Michael


From: 沈胜宇 [mailto:syshen@nudt.edu.cn<mailto:syshen@nudt.edu.cn>]
Sent: Wednesday, December 09, 2015 2:41 AM
To: Soegtrop, Michael
Cc: caml-list
Subject: Re: RE: [Caml-list] [OCAML]:: how to switch buffer in ocamllex?


I have resolved it, and I have a further question:

I am developing a parser with ocamllex and ocamyacc for verilog language.

But I find the BNF include some rules that beyond the LA(1), so how to result this ?

Shen

-----原始邮件-----
发件人: "Soegtrop, Michael" <michael.soegtrop@intel.com<mailto:michael.soegtrop@intel.com>>
发送时间: 2015-11-25 22:24:57 (星期三)
收件人: ??? <syshen@nudt.edu.cn<mailto:syshen@nudt.edu.cn>>, caml-list <caml-list@inria.fr<mailto:caml-list@inria.fr>>
抄送:
主题: RE: [Caml-list] [OCAML]:: how to switch buffer in ocamllex?
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> [mailto: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<http://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

Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de<http://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
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: 19022 bytes --]

  parent reply	other threads:[~2015-12-09 10:05 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
     [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 [this message]
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=0F7D3B1B3C4B894D824F5B822E3E5A172CE4923F@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).