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]
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>
发送时间: 2015-11-25 22:24:57 (星期三)
收件人: ??? <syshen@nudt.edu.cn>, caml-list <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] 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

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