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`
E
B
N
F
P
a
r
s
e
E
B
N
F
P
a
r
s
e
[
s
o
u
r
c
e
]
r
e
a
d
s
a
B
N
F
/
E
B
N
F
g
r
a
m
m
a
r
f
r
o
m
t
h
e
s
t
r
i
n
g
s
o
u
r
c
e
a
n
d
r
e
t
u
r
n
s
a
n
A
s
s
o
c
i
a
t
i
o
n
m
a
p
p
i
n
g
e
a
c
h
r
u
l
e
n
a
m
e
t
o
t
h
e
P
a
r
s
e
r
C
o
m
b
i
n
a
t
o
r
i
t
l
o
w
e
r
s
t
o
.
E
B
N
F
P
a
r
s
e
[
F
i
l
e
[
p
a
t
h
]
]
r
e
a
d
s
t
h
e
g
r
a
m
m
a
r
f
r
o
m
a
f
i
l
e
.
D
e
t
a
i
l
s
a
n
d
O
p
t
i
o
n
s
▪
A grammar rule has the shape
<
n
a
m
e
>
:
:
=
a
l
t
1
|
a
l
t
2
|
…
: a non-terminal name in angle brackets, an arrow, then alternatives separated by
|
. Each alternative is a whitespace-separated sequence of elements.
▪
In a rule body a non-terminal reference
<
n
a
m
e
>
lowers to a recursive reference resolved at parse time (through
P
a
r
s
e
R
e
c
u
r
s
i
v
e
), a bare token lowers to a
P
a
r
s
e
L
i
t
e
r
a
l
, and a postfix
<
n
a
m
e
>
*
lowers to a
P
a
r
s
e
M
a
n
y
.
▪
Whitespace between adjacent elements is consumed automatically, so
1
2
+
3
4
and
1
2
+
3
4
both parse.
▪
Each value in the returned association is the parser for one rule; run it on input with
P
a
r
s
e
.
▪
Four arrow kinds are recognized:
:
:
=
(syntactic),
:
=
=
(semantic, same surface shape),
:
:
-
(token construction), and
:
:
:
(character class). The
:
:
-
and
:
:
:
bodies compile through a regex-style meta-parser that handles classes (
[
a
-
z
]
,
[
^
*
]
), grouping (
(
x
|
y
)
), references (
<
n
a
m
e
>
), and the postfix operators
*
,
+
,
?
.
▪
A directly left-recursive rule
A
:
:
=
A
r
|
b
is rewritten to the equivalent
A
:
:
=
b
(
r
)
*
before lowering; indirect (mutual) left recursion is not rewritten.
▪
Each rule's alternatives are sorted longest-first by element count, so a longer shared-prefix alternative is tried before a shorter one.
▪
The BNF source is itself parsed by a grammar built entirely from
P
a
r
s
e
*
combinators — see the tutorial
P
a
r
s
i
n
g
B
N
F
G
r
a
m
m
a
r
s
.
O
p
t
i
o
n
D
e
f
a
u
l
t
D
e
s
c
r
i
p
t
i
o
n
"
P
r
i
m
i
t
i
v
e
O
v
e
r
r
i
d
e
s
"
`
<
"
A
c
t
i
o
n
s
"
`
<
"
C
h
o
i
c
e
M
o
d
e
"
"
A
u
t
o
"
h
o
w
a
l
t
e
r
n
a
t
i
v
e
s
c
o
m
b
i
n
e
:
"
P
E
G
"
(
f
i
r
s
t
m
a
t
c
h
w
i
n
s
)
,
"
L
o
n
g
e
s
t
"
(
l
o
n
g
e
s
t
m
a
t
c
h
w
i
n
s
)
,
o
r
"
A
u
t
o
"
(
l
o
n
g
e
s
t
m
a
t
c
h
o
n
l
y
w
h
e
n
a
l
t
e
r
n
a
t
i
v
e
s
h
a
v
e
e
q
u
a
l
e
l
e
m
e
n
t
c
o
u
n
t
s
)
Examples
(
1
8
)
Basic Examples
(
4
)
Read a three-rule arithmetic grammar; the result is an association keyed by rule name:
I
n
[
1
]
:
=
g
=
E
B
N
F
P
a
r
s
e
[
"
<
d
i
g
i
t
>
:
:
=
0
|
1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
<
n
u
m
b
e
r
>
:
:
=
<
d
i
g
i
t
>
<
d
i
g
i
t
>
*
<
e
x
p
r
>
:
:
=
<
n
u
m
b
e
r
>
+
<
n
u
m
b
e
r
>
"
]
;
K
e
y
s
[
g
]
O
u
t
[
1
]
=
{
d
i
g
i
t
,
n
u
m
b
e
r
,
e
x
p
r
}
Each rule name maps to the parser combinator it lowers to:
I
n
[
1
]
:
=
g
[
"
n
u
m
b
e
r
"
]
O
u
t
[
1
]
=
P
a
r
s
e
r
C
o
m
b
i
n
a
t
o
r
T
y
p
e
:
A
c
t
i
o
n
A
r
i
t
y
:
2
C
o
m
p
i
l
e
d
:
F
a
l
s
e
Run one of the lowered rules on input with
P
a
r
s
e
:
I
n
[
1
]
:
=
P
a
r
s
e
[
g
[
"
n
u
m
b
e
r
"
]
,
"
1
2
3
4
5
"
]
O
u
t
[
1
]
=
{
1
,
{
2
,
3
,
4
,
5
}
}
The
<
e
x
p
r
>
rule composes the other rules, and the whitespace around
+
is optional:
I
n
[
1
]
:
=
P
a
r
s
e
[
g
[
"
e
x
p
r
"
]
,
"
1
2
+
3
4
"
]
O
u
t
[
1
]
=
{
{
1
,
{
2
}
}
,
+
,
{
3
,
{
4
}
}
}
S
c
o
p
e
(
9
)
P
r
o
p
e
r
t
i
e
s
&
R
e
l
a
t
i
o
n
s
(
2
)
P
o
s
s
i
b
l
e
I
s
s
u
e
s
(
2
)
N
e
a
t
E
x
a
m
p
l
e
s
(
1
)
S
e
e
A
l
s
o
E
B
N
F
R
u
l
e
s
▪
P
a
r
s
e
▪
P
a
r
s
e
A
c
t
i
o
n
▪
P
a
r
s
e
C
h
o
i
c
e
▪
P
a
r
s
e
R
e
c
u
r
s
i
v
e
▪
P
a
r
s
e
O
p
e
r
a
t
o
r
T
a
b
l
e
▪
T
P
T
P
I
m
p
o
r
t
▪
P
a
r
s
e
r
C
o
m
b
i
n
a
t
o
r
R
e
l
a
t
e
d
G
u
i
d
e
s
▪
P
a
r
s
i
n
g
i
n
t
h
e
W
o
l
f
r
a
m
L
a
n
g
u
a
g
e
"
"