Browsable ANTLR4 Grammar

CC-BY

Grammar extracted by Vadim Zaytsev, see the Grammar Zoo entry for details: meta/syntax/antlr/antlr4/zaytsev/extracted
Source used for this grammar: Vadim Zaytsev, GrammarLab, grammarlab::extract::ANTLR4, 13 October 2014

Summary

Syntax

OptionsSpec ::=
	"options" "{" (Option ";")* "}"
SetElement ::=
	Range
SetElement ::=
	STRING_LITERAL ElementOptions?
SetElement ::=
	Id ElementOptions?
LexerCommand ::=
	(Id | "mode") ("(" (Id | INT) ")")?
LexerCommands ::=
	"->" {LexerCommand ","}+
EbnfSuffix ::=
	("+" | "*" | "?") "?"?
LexerAlt ::=
	LexerElement+ LexerCommands?
LexerAtom ::=
	Range
LexerAtom ::=
	LEXER_CHAR_SET
LexerAtom ::=
	"." ElementOptions?
LexerAtom ::=
	"~" (SetElement | BlockSet)
LexerAtom ::=
	(Id | STRING_LITERAL) ElementOptions?
Range ::=
	STRING_LITERAL ".." STRING_LITERAL
Element ::=
	LabeledElement EbnfSuffix?
Element ::=
	ACTION "?"?
Element ::=
	Atom EbnfSuffix?
Element ::=
	Ebnf
OptionValue ::=
	Id ("." Id)*
OptionValue ::=
	INT
OptionValue ::=
	ACTION
OptionValue ::=
	STRING_LITERAL
ModeSpec ::=
	"mode" Id ";" LexerRule*
RuleBlock ::=
	{LabeledAlt "|"}+
Atom ::=
	"." ElementOptions?
Atom ::=
	Id ARG_ACTION? ElementOptions?
Atom ::=
	Range
Atom ::=
	"~" (SetElement | BlockSet)
Atom ::=
	(Id | STRING_LITERAL) ElementOptions?
DelegateGrammars ::=
	"import" {DelegateGrammar ","}+ ";"
ElementOption ::=
	Id ("=" (Id | STRING_LITERAL))?
ExceptionGroup ::=
	("catch" ARG_ACTION ACTION)* ("finally" ACTION)?
LexerElement ::=
	LabeledLexerElement EbnfSuffix?
LexerElement ::=
	LexerBlock EbnfSuffix?
LexerElement ::=
	LexerAtom EbnfSuffix?
LexerElement ::=
	ACTION "?"?
RuleModifier ::=
	"private"
RuleModifier ::=
	"fragment"
RuleModifier ::=
	"public"
RuleModifier ::=
	"protected"
RuleAction ::=
	"@" Id ACTION
RulePrequel ::=
	RuleAction
RulePrequel ::=
	OptionsSpec
Ebnf ::=
	Block EbnfSuffix?
BlockSet ::=
	"(" {SetElement "|"}+ ")"
Option ::=
	Id "=" OptionValue
TokensSpec ::=
	"tokens" "{" {Id ","}+ "}"
RuleSpec ::=
	LexerRule
RuleSpec ::=
	ParserRuleSpec
Action ::=
	"@" (ActionScopeName "::")? Id ACTION
ParserRuleSpec ::=
	RuleModifier* Id ARG_ACTION? RuleReturns? ThrowsSpec? LocalsSpec? RulePrequel* ":" RuleBlock ";" ExceptionGroup
LabeledAlt ::=
	Alternative ("#" Id)?
ActionScopeName ::=
	"parser"
ActionScopeName ::=
	"lexer"
ActionScopeName ::=
	Id
LabeledElement ::=
	Id ("=" | "+=") (Atom | Block)
PrequelConstruct ::=
	OptionsSpec
PrequelConstruct ::=
	Action
PrequelConstruct ::=
	DelegateGrammars
PrequelConstruct ::=
	TokensSpec
ThrowsSpec ::=
	"throws" {Id ","}+
LexerRule ::=
	"fragment"? Id ":" {LexerAlt "|"}+ ";"
Alternative ::=
	ElementOptions? Element*
Block ::=
	"(" (OptionsSpec? RuleAction* ":")? AltList ")"
GrammarType ::=
	("lexer" | "parser")? "grammar"
LexerBlock ::=
	"(" {LexerAlt "|"}+ ")"
ANTLR4Grammar ::=
	GrammarType Id ";" PrequelConstruct* RuleSpec* ModeSpec*
LocalsSpec ::=
	"locals" ARG_ACTION
LabeledLexerElement ::=
	Id ("=" | "+=") (LexerAtom | Block)
DelegateGrammar ::=
	Id ("=" Id)?
ElementOptions ::=
	"<" {ElementOption ","}+ ">"
RuleReturns ::=
	"returns" ARG_ACTION
AltList ::=
	{Alternative "|"}+

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