FSharpCompiler.Parsing 1.1.3

Suggested Alternatives

FslexFsyacc

Additional Details

Replace this package with the FslexFsyacc package, which implements all the features of this package and is more friendly.

dotnet add package FSharpCompiler.Parsing --version 1.1.3
NuGet\Install-Package FSharpCompiler.Parsing -Version 1.1.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FSharpCompiler.Parsing" Version="1.1.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FSharpCompiler.Parsing --version 1.1.3
#r "nuget: FSharpCompiler.Parsing, 1.1.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FSharpCompiler.Parsing as a Cake Addin
#addin nuget:?package=FSharpCompiler.Parsing&version=1.1.3

// Install FSharpCompiler.Parsing as a Cake Tool
#tool nuget:?package=FSharpCompiler.Parsing&version=1.1.3

The FSharpCompiler.Parsing is a runtime for parser.

The Yacc parser reads a sequence of tokens as its input, and groups the tokens using the grammar rules. If the input is valid, the end result is that the entire token sequence reduces to a single grouping whose symbol is the grammar’s start symbol.

Parse Tree

The ParseTree type describes a generic abstract syntax tree.

type ParseTree<'tok> =
    | Interior of symbol:string * children: list<ParseTree<'tok>>
    | Terminal of 'tok

An Interor node represents a production. The symbol is the result of the production, or the left side of the production. The children is the components of the production, or the right side of the production. An Terminal node represents a terminal symbol. The parameters of the node represent a token of the input stream.

The parse tree is implicitly constructed during the parse. As the parser executes, it builds an internal representation of the the structure of the program. The internal representation is based on the right hand side of the production rules. When a right hand side is recognized, it is reduced to the corresponding left hand side. Parsing is complete when the entire program has been reduced to the start symbol of the grammar.

Syntactic Parser

The type SyntacticParser is a model of a parsing table driven parser.

To construct SyntacticParser type, you need to provide parsing table that be written by hand or be automatically generated By Yacc.

open FSharpCompiler.Parsing
let private parser = 
    SyntacticParser(
        ExprParsingTable.rules,
        ExprParsingTable.kernelSymbols,
        ExprParsingTable.parsingTable)

Provides a function that associates terminal symbol in grammar input file with the token in source stream. and let's assemble a parsing function:

let parseToTree tokens = 
    parser.parse(tokens, Tokenizer.getTag) 

We can now test it on some sample inputs:

let x = [Number 1.0;Plus;Number 2.0]
let y = parsingTree x
Should.equal y 
<| Interior("expr",[Interior("expr",[Terminal(Number 1.0)]);Terminal Plus;Interior("expr",[Terminal(Number 2.0)])])

How to build a parser using FSharpCompiler.Parsing is detailed in the resolution: xp44mm/ArithmeticExpressions

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on FSharpCompiler.Parsing:

Package Downloads
FSharpCompiler.Lex

Lex are tools for generating lexical analyzer.

FSharpCompiler.Yacc

Yacc utility for.NET platform. Yacc are tools for generating parsers.

FSharp.JLinq

`FSharp.JLinq` is a library to enhance JToken located in `Newtonsoft.Json.Linq`.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.3 2,620 10/19/2021
1.1.2 1,093 10/19/2021
1.1.1 1,045 10/15/2021
1.1.0 1,588 8/21/2021
1.0.5 2,663 7/18/2021
1.0.4 4,885 3/13/2021
1.0.3 1,889 2/20/2021
1.0.2 1,363 2/5/2021
1.0.1 1,251 2/2/2021
1.0.0 1,901 1/21/2021

add module ParseTreeUtils