FSharpCompiler.Parsing
1.1.3
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
<PackageReference Include="FSharpCompiler.Parsing" Version="1.1.3" />
paket add FSharpCompiler.Parsing --version 1.1.3
#r "nuget: FSharpCompiler.Parsing, 1.1.3"
// 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 | Versions 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. |
-
.NETStandard 2.0
- FSharp.Core (>= 6.0.0)
- FSharp.Idioms (>= 1.1.14)
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.
add module ParseTreeUtils