List Info

Thread: "ocaml_beginners"::[] ocamlyacc and AST's




"ocaml_beginners"::[] ocamlyacc and AST's
country flaguser name
United States
2007-05-08 16:17:47

Hi all
First of all, sorry for the complete newbie question, I'm trying to
create an abstract syntax tree + parser for a small language, can
some one help me understand what they following error is telling me
and why?

-----
The implementation parser.ml does not match the interface parser.cmi:
Values do not match:
val file : (Lexing.lexbuf -> Lexer.token) -> Lexing.lexbuf -> Ast.ast
is not included in
val file : (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast.ast
make: *** [parser.cmo] Error 2
------

My lexer works, i have tested tokenizing simple and complex
expressions but my parser / ast code fails miserably, this is the code
for it.

ast.ml:
------------
<code&gt;
type ast =
File of ast
| Start of string
</code>

parser.mly:
-------
<code>
%token <string > IDENT
%token EOF
%token START

%type <Ast.ast> file

%start file

%%


file :

start EOF { Ast.File (Ast.Start ($1) ) }

;



start :

START IDENT { $2 }

;
</code>

I have reduced it to the bare bones to try to find what i'm missing,
its simply meant to create a structure root node <file&gt; and node
named <start&gt; with an identifier, i.e. in this case, the test file to
read would only contain "start hello";

thanks in advance

-deeq

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] ocamlyacc and AST's
country flaguser name
United States
2007-05-08 16:35:11

On Tue, 8 May 2007, mo.deeq wrote:

> Hi all
> First of all, sorry for the complete newbie question, I'm trying to
> create an abstract syntax tree + parser for a small language, can
> some one help me understand what they following error is telling me
> and why?
>;
>
> -----
&gt; The implementation parser.ml does not match the interface parser.cmi:
> Values do not match:
&gt; val file : (Lexing.lexbuf -> Lexer.token) -> Lexing.lexbuf -> Ast.ast
> is not included in
> val file : (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast.ast
> make: *** [parser.cmo] Error 2

What it's telling you is that your lexer is returning a type of
Lexer.token, rather than the expected (Parser.)token. Did you define your
set of tokens over in your mll file as well? If so, you'll want to use
the ones defined by the parser. You can do this easily enough by tossing
an "open Parser&quot; up in the header of the lexer source. Just make sure you
compile parser.mli before lexer.ml so it'll have the token type
information.

William D. Neumann

---

"There's just so many extra children, we could just feed the
children to these tigers. We don't need them, we're not doing
anything with them.

Tigers are noble and sleek; children are loud and messy.&quot;

-- Neko Case

Life is unfair. Kill yourself or get over it.
-- Black Box Recorder

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )