3

I'm working on a toy compiler using F#, i.e., the combo of FsLex and FsYacc. To get familiar with them, I've read the Lexer/Parser chapter of Expert F# (v2) book (a good book btw). Right now, I've half way through the well-recommended ocamlyacc tutorial, and stuck at the last example Multi-Function Calculator mfcalc. Particularly, the following statement

%token <float->float> FNCT

in the parser file keeps getting error "error: parse error" in my F# version. Am I missing anything here, or is this a feature currently not supported by F#?

Cygwin98
  • 510
  • 5
  • 13

2 Answers2

4

This looks like a bug. Adding parens doesn't help. I have tried various workarounds, but I couldn't find a clean way. You should do a bug report.

If you have only one function (like in the tutorial example), you should define a type in the prelude:

type floatFunction = float -> float
...
%token <floatFunction> FNCT

If you have many functions, you could also define a generic type:

type functionType<'a, 'b> = 'a -> 'b
...
%token < ('a, 'b) functionType > FNCT

Any angle bracket in the type leads to a parse error (even functionType<float,float>).

Laurent
  • 2,951
  • 16
  • 19
0

You might need to put parens, like

%token <(float->float)> FNCT

I forget (am away from an F# machine to check).

Brian
  • 117,631
  • 17
  • 236
  • 300
  • Hi, Brian, I added parens and now the error changed to Parser.fsy(11,21): error: Unexpected character ')' – Cygwin98 Apr 08 '11 at 12:40