Wolfram Language
Paclet Repository
Community-contributed installable additions to the Wolfram Language
Primary Navigation
Categories
Cloud & Deployment
Core Language & Structure
Data Manipulation & Analysis
Engineering Data & Computation
External Interfaces & Connections
Financial Data & Computation
Geographic Data & Computation
Geometry
Graphs & Networks
Higher Mathematical Computation
Images
Knowledge Representation & Natural Language
Machine Learning
Notebook Documents & Presentation
Scientific and Medical Data & Computation
Social, Cultural & Linguistic Data
Strings & Text
Symbolic & Numeric Computation
System Operation & Setup
Time-Related Computation
User Interface Construction
Visualization & Graphics
Random Paclet
Alphabetical List
Using Paclets
Create a Paclet
Get Started
Download Definition Notebook
Learn More about
Wolfram Language
Parser
Tutorials
Building Language Front-Ends
Inside CodeAnalysis - How CodeStructure Parses C
Design and Compilation Strategy
Implementing the LaTeX Math Parser
MaTeX Comparison Showcase
The Parser Landscape - a Survey of What Exists Today
The Parser Zoo - language front-ends over a shared algebra
Parsing BNF Grammars (and bootstrapping a TPTP parser)
Parsing GrammarRules Locally
A Markdown Inline Parser in Parser Combinators
ParsingOpenQASM
Parsing TPTP, Auto-Generated from the Published BNF
PrattVsPEG
The Wolfram Box Typesetting Reference
Guides
Parsing in the Wolfram Language
Symbols
ASTAddSource
ASTAlgebra
ASTContainer
ASTLeafQ
ASTNodeQ
ASTStripSource
BinaryNode
BrainfuckAST
BrainfuckGrammar
BrainfuckRun
BrainfuckSemantic
CalculatorAST
CalculatorEval
CalculatorGrammar
CalculatorSemantic
CallNode
ContainerNode
EBNFParse
EBNFRules
ErrorNode
ExportLaTeX
GroupNode
InfixNode
JSONAST
JSONGrammar
JSONImport
JSONSemantic
LambdaAST
LambdaEval
LambdaGrammar
LambdaSemantic
LaTeXMathParse
LaTeXMathParser
LaTeXMathStyle
LeafNode
LispAST
LispGrammar
LispRead
LispSemantic
LispSymbol
MarkdownInlineParse
MarkdownInlineParser
MarkdownParse
MarkdownParser
ParseAction
ParseBetween
ParseChainLeft
ParseChainRight
ParseCharacter
ParseChoiceLongest
ParseChoice
ParseFail
ParseLiteral
ParseLookahead
ParseMany
Parse
ParseNotFollowedBy
ParseOperatorTable
ParseOptional
ParsePartial
ParsePosition
ParserCombinator
ParserCombinatorQ
ParserCompile
ParseRecursive
ParseRegex
ParseSepBy1
ParseSepBy
ParseSequence
ParseSome
ParseSucceed
ParseTry
PostfixNode
PrefixNode
RecCell
RecRef
SetRec
SpannedToken
TernaryNode
ToCodeParser
TPTPExport
TPTPImport
Overviews
WolframParser
Wolfram`Parser`Languages`Lambda`
L
a
m
b
d
a
A
S
T
L
a
m
b
d
a
A
S
T
[
t
e
r
m
]
p
a
r
s
e
s
t
h
e
u
n
t
y
p
e
d
l
a
m
b
d
a
-
c
a
l
c
u
l
u
s
t
e
r
m
t
o
a
s
t
a
n
d
a
r
d
s
y
n
t
a
x
t
r
e
e
-
a
C
o
n
t
a
i
n
e
r
N
o
d
e
o
f
C
a
l
l
N
o
d
e
a
n
d
L
e
a
f
N
o
d
e
.
D
e
t
a
i
l
s
a
n
d
O
p
t
i
o
n
s
▪
L
a
m
b
d
a
A
S
T
is the standard-AST mode of the lambda grammar: it runs
L
a
m
b
d
a
G
r
a
m
m
a
r
over the shared abstract-syntax algebra, so the result carries only structure, no reduction.
▪
The surface syntax is
\
name
.
body
(or the unicode
λ
name
.
body
) for abstraction, juxtaposition for application (left associative), and parentheses for grouping.
\
x
y
.
b
is sugar for
\
x
.
\
y
.
b
. In a Wolfram string a backslash doubles, so the term
\
x
.
x
is written
"
\
\
x
.
x
"
.
▪
A variable is a
L
e
a
f
N
o
d
e
with kind
"
S
y
m
b
o
l
"
. An application
f
x
is a
C
a
l
l
N
o
d
e
with
f
as its head and
{
x
}
as its single argument. An abstraction
\
name
.
body
is a
C
a
l
l
N
o
d
e
headed by the lambda leaf
L
e
a
f
N
o
d
e
[
"
S
y
m
b
o
l
"
,
"
λ
"
,
]
, with the bound name and the body as its two children.
▪
L
a
m
b
d
a
E
v
a
l
runs the
same
grammar over
L
a
m
b
d
a
S
e
m
a
n
t
i
c
instead, compiling each abstraction to a native
F
u
n
c
t
i
o
n
and letting the kernel beta-reduce. The grammar is written once; only the algebra differs.
▪
Application binds tighter than abstraction, so
\
x
.
x
y
reads as
\
x
.
(
x
y
)
, not
(
\
x
.
x
)
y
.
▪
Input that does not parse to completion returns a
F
a
i
l
u
r
e
(see
P
a
r
s
e
).
Examples
(
4
)
Basic Examples
(
1
)
The identity term is a
C
a
l
l
N
o
d
e
headed by the lambda leaf, binding
x
over the body
x
:
I
n
[
1
]
:
=
L
a
m
b
d
a
A
S
T
[
"
\
\
x
.
x
"
]
O
u
t
[
1
]
=
C
o
n
t
a
i
n
e
r
N
o
d
e
[
S
t
r
i
n
g
,
{
C
a
l
l
N
o
d
e
[
L
e
a
f
N
o
d
e
[
S
y
m
b
o
l
,
λ
,
]
,
{
L
e
a
f
N
o
d
e
[
S
y
m
b
o
l
,
x
,
]
,
L
e
a
f
N
o
d
e
[
S
y
m
b
o
l
,
x
,
S
o
u
r
c
e
{
{
1
,
4
}
,
{
1
,
5
}
}
]
}
,
S
o
u
r
c
e
{
{
1
,
4
}
,
{
1
,
5
}
}
]
}
,
S
o
u
r
c
e
{
{
1
,
4
}
,
{
1
,
5
}
}
]
Nodes carry a
"
S
o
u
r
c
e
"
span of
{
{
startLine
,
startCol
}
,
{
endLine
,
endCol
}
}
(
C
o
d
e
P
a
r
s
e
r
LineColumn). An abstraction is special: its
λ
head and its bound-name leaf are
synthesized
by the builder, not lexed from a token, so they have no source and keep empty metadata
<
|
|
>
. Only the parsed variable occurrence in the body - here the trailing
x
at columns
4
-
5
- carries a span, and the abstraction node inherits that body span (the binder is not included).
The K combinator
\
x
.
\
y
.
x
nests one abstraction inside another:
I
n
[
2
]
:
=
L
a
m
b
d
a
A
S
T
[
"
\
\
x
.
\
\
y
.
x
"
]
O
u
t
[
2
]
=
C
o
n
t
a
i
n
e
r
N
o
d
e
[
S
t
r
i
n
g
,
{
C
a
l
l
N
o
d
e
[
L
e
a
f
N
o
d
e
[
S
y
m
b
o
l
,
λ
,
]
,
{
L
e
a
f
N
o
d
e
[
S
y
m
b
o
l
,
x
,
]
,
C
a
l
l
N
o
d
e
[
L
e
a
f
N
o
d
e
[
S
y
m
b
o
l
,
λ
,
]
,
{
L
e
a
f
N
o
d
e
[
S
y
m
b
o
l
,
y
,
]
,
L
e
a
f
N
o
d
e
[
S
y
m
b
o
l
,
x
,
S
o
u
r
c
e
{
{
1
,
7
}
,
{
1
,
8
}
}
]
}
,
S
o
u
r
c
e
{
{
1
,
7
}
,
{
1
,
8
}
}
]
}
,
S
o
u
r
c
e
{
{
1
,
7
}
,
{
1
,
8
}
}
]
}
,
S
o
u
r
c
e
{
{
1
,
7
}
,
{
1
,
8
}
}
]
The same source through
L
a
m
b
d
a
E
v
a
l
reduces to a value, not a tree:
I
n
[
3
]
:
=
L
a
m
b
d
a
E
v
a
l
[
"
(
\
\
x
.
\
\
y
.
x
)
a
b
"
]
O
u
t
[
3
]
=
a
S
c
o
p
e
(
1
)
P
r
o
p
e
r
t
i
e
s
&
R
e
l
a
t
i
o
n
s
(
1
)
P
o
s
s
i
b
l
e
I
s
s
u
e
s
(
1
)
S
e
e
A
l
s
o
L
a
m
b
d
a
E
v
a
l
▪
L
a
m
b
d
a
G
r
a
m
m
a
r
▪
L
a
m
b
d
a
S
e
m
a
n
t
i
c
▪
C
a
l
l
N
o
d
e
▪
L
e
a
f
N
o
d
e
▪
C
o
n
t
a
i
n
e
r
N
o
d
e
R
e
l
a
t
e
d
G
u
i
d
e
s
▪
P
a
r
s
e
r
Z
o
o
"
"