Browsable XPath Grammar

CC-BY

Grammar extracted by Vadim Zaytsev, see the Grammar Zoo entry for details: xmlware/xpath/xpath-1/w3c/w3c-19991116/extracted
Source used for this grammar: W3C, XML Path Language (XPath), Version 1.0, xmlspec-v20.dtd, 16 November 1999 [Source]

Summary

Syntax

LocationPath ::=
	[NT-LocationPath]::(RelativeLocationPath | AbsoluteLocationPath)
AbsoluteLocationPath ::=
	[NT-AbsoluteLocationPath]::("/" RelativeLocationPath? | AbbreviatedAbsoluteLocationPath)
RelativeLocationPath ::=
	[NT-RelativeLocationPath]::(Step | RelativeLocationPath "/" Step | AbbreviatedRelativeLocationPath)
Step ::=
	[NT-Step]::(AxisSpecifier NodeTest Predicate* | AbbreviatedStep)
AxisSpecifier ::=
	[NT-AxisSpecifier]::(AxisName "::" | AbbreviatedAxisSpecifier)
AxisName ::=
	[NT-AxisName]::("ancestor" | "ancestor-or-self" | "attribute" | "child" | "descendant" | "descendant-or-self" | "following" | "following-sibling" | "namespace" | "parent" | "preceding" | "preceding-sibling" | "self")
NodeTest ::=
	[NT-NodeTest]::(NameTest | NodeType "(" ")" | "processing-instruction" "(" Literal ")")
Predicate ::=
	[NT-Predicate]::("[" PredicateExpr "]")
PredicateExpr ::=
	[NT-PredicateExpr]::Expr
AbbreviatedAbsoluteLocationPath ::=
	[NT-AbbreviatedAbsoluteLocationPath]::("//" RelativeLocationPath)
AbbreviatedRelativeLocationPath ::=
	[NT-AbbreviatedRelativeLocationPath]::(RelativeLocationPath "//" Step)
AbbreviatedStep ::=
	[NT-AbbreviatedStep]::("." | "..")
AbbreviatedAxisSpecifier ::=
	[NT-AbbreviatedAxisSpecifier]::"@"?
Expr ::=
	[NT-Expr]::OrExpr
PrimaryExpr ::=
	[NT-PrimaryExpr]::(VariableReference | "(" Expr ")" | Literal | Number | FunctionCall)
FunctionCall ::=
	[NT-FunctionCall]::(FunctionName "(" (Argument ("," Argument)*)? ")")
Argument ::=
	[NT-Argument]::Expr
UnionExpr ::=
	[NT-UnionExpr]::(PathExpr | UnionExpr "|" PathExpr)
PathExpr ::=
	[NT-PathExpr]::(LocationPath | FilterExpr | FilterExpr "/" RelativeLocationPath | FilterExpr "//" RelativeLocationPath)
FilterExpr ::=
	[NT-FilterExpr]::(PrimaryExpr | FilterExpr Predicate)
OrExpr ::=
	[NT-OrExpr]::(AndExpr | OrExpr "or" AndExpr)
AndExpr ::=
	[NT-AndExpr]::(EqualityExpr | AndExpr "and" EqualityExpr)
EqualityExpr ::=
	[NT-EqualityExpr]::(RelationalExpr | EqualityExpr "=" RelationalExpr | EqualityExpr "!=" RelationalExpr)
RelationalExpr ::=
	[NT-RelationalExpr]::(AdditiveExpr | RelationalExpr "<" AdditiveExpr | RelationalExpr ">" AdditiveExpr | RelationalExpr "<=" AdditiveExpr | RelationalExpr ">=" AdditiveExpr)
AdditiveExpr ::=
	[NT-AdditiveExpr]::(MultiplicativeExpr | AdditiveExpr "+" MultiplicativeExpr | AdditiveExpr "-" MultiplicativeExpr)
MultiplicativeExpr ::=
	[NT-MultiplicativeExpr]::(UnaryExpr | MultiplicativeExpr MultiplyOperator UnaryExpr | MultiplicativeExpr "div" UnaryExpr | MultiplicativeExpr "mod" UnaryExpr)
UnaryExpr ::=
	[NT-UnaryExpr]::(UnionExpr | "-" UnaryExpr)
ExprToken ::=
	[NT-ExprToken]::("(" | ")" | "[" | "]" | "." | ".." | "@" | "," | "::" | NameTest | NodeType | Operator | FunctionName | AxisName | Literal | Number | VariableReference)
Number ::=
	[NT-Number]::(Digits ("." Digits?)? | "." Digits)
Operator ::=
	[NT-Operator]::(OperatorName | MultiplyOperator | "/" | "//" | "|" | "+" | "-" | "=" | "!=" | "<" | "<=" | ">" | ">=")
OperatorName ::=
	[NT-OperatorName]::("and" | "or" | "mod" | "div")
MultiplyOperator ::=
	[NT-MultiplyOperator]::"*"
VariableReference ::=
	[NT-VariableReference]::("$" QName)
NameTest ::=
	[NT-NameTest]::("*" | NCName ":" "*" | QName)
NodeType ::=
	[NT-NodeType]::("comment" | "text" | "processing-instruction" | "node")
ExprWhitespace ::=
	[NT-ExprWhitespace]::S
Digits ::=
	[NT-Digits]::("0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9")+

GrammarLabMaintained by Dr. Vadim Zaytsev a.k.a. @grammarware. Last updated in September 2015. []