Skip to content

Instantly share code, notes, and snippets.

@AndreasHassing
Last active August 6, 2024 11:20
Show Gist options
  • Save AndreasHassing/16567f299b77b0090d94441115a5d031 to your computer and use it in GitHub Desktop.
Save AndreasHassing/16567f299b77b0090d94441115a5d031 to your computer and use it in GitHub Desktop.
How to get FsYacc and FsLex (FsLexYacc) on OS X

Installing FsYacc and FsLex (FsLexYacc) on OS X

Step by step guide to getting FsYacc and FsLex for development on OS X.

Changes

  • 2017-01-09: Updated guide to reflect latest version of FsLexYacc (7.0.3)
  • 2016: Created

1. Install Mono

By doing one of these:

2. Get NuGet Package Manager (CLI)

Download nuget.exe to ~/fsharp.

3. Install FsLexYacc

Copy paste into a terminal:

cd ~/fsharp                      # move to the ~/fsharp directory
mono nuget.exe install FsLexYacc # install fslexyacc with nuget
ls                               # list which files are in the current directory

# Should output something like:
# FsLexYacc.7.0.3/  FsLexYacc.Runtime.7.0.3/ FSharp.Core.3.1.2.5/ nuget.exe

4. Create links to FsLex and FsYacc binaries

Copy paste into a terminal:

cd /usr/local/bin
echo -e '#!/bin/bash\nmono /Users/'$USER'/fsharp/FsLexYacc.7.0.3/build/fslex.exe $*' > fslex
echo -e '#!/bin/bash\nmono /Users/'$USER'/fsharp/FsLexYacc.7.0.3/build/fsyacc.exe $*' > fsyacc
chmod a+x fslex fsyacc

5. Link the runtime DLL to your ~/fsharp folder

The FsLexYacc.Runtime.dll file needs to be referred to when lexing and compiling your language,

# link the Runtime to your ~/fsharp folder (once):
ln -s "~/fsharp/FsLexYacc.Runtime.7.0.3/lib/portable-net45+netcore45+wpa81+wp8+MonoAndroid10+MonoTouch10/FsLexYacc.Runtime.dll" ~/fsharp

# then henceforth, you can use the following from your project directory
# (referring to the link you just made):
fsharpi -r ~/fsharp/FsLexYacc.Runtime.dll Absyn.fs FunPar.fs FunLex.fs Parse.fs

5. Profit!

You should now totally have FsLexYacc on your OS X computer, ready to create awesome languages and compilers!

Footnotes

  1. When building from Homebrew, the Mono runtime gets odd parameters which sets tail-call optimizations to disabled for some reason, avoid this by using the downloadable installer from mono-project.
@liweijian
Copy link

@AndreasHassing Nice! You made my day, thank you.

$ ln -s ~/fsharp/FsLexYacc.Runtime.10.2.0/lib/netstandard2.0/FsLexYacc.Runtime.dll ~/fsharp

$ fsharpi -r ~/fsharp/FsLexYacc.Runtime.dll Absyn.fs ExprPar.fs ExprLex.fs

Microsoft (R) F# Interactive version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

[Loading /Users/lwj/Downloads/todel/fs101/Absyn.fs
 Loading /Users/lwj/Downloads/todel/fs101/ExprPar.fs
 Loading /Users/lwj/Downloads/todel/fs101/ExprLex.fs]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment