-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
Using an EBNF understood by https://github.com/GuntherRademacher/rr we can have a nice navigable railroad diagram for the A BNF-style Grammar for ERGO shown in the appendix A of the Ergo Manual (see bellow a hand made conversion, basically replace := by ::=, backquote by single quote).
See instructions a the top bellow to view the railroad diagram online.
//
// EBNF to be viewd at
// (IPV6) https://www.bottlecaps.de/rr/ui
// (IPV4) https://rr.red-dove.com/ui
//
// Copy and paste this at one url shown above in the 'Edit Grammar' tab
// then click the 'View Diagram' tab.
//
// To avoid confusion between some language elements and meta-syntax
// (e.g., parentheses and brackets are part of BNF and also of the language
// being described), we enclose some symbols in single quotes to make it
// clear that they are part of the language syntax, not of the grammar.
// However, in ERGO these symbols can be used with or without the quotes.
Statement ::= (Rule | Query | LatentQuery | Directive) '.'
Rule ::= (RuleDescriptor)? Head (':-' Body)? '.'
Query ::= '?-' Body '.'
LatentQuery ::= RuleDescriptor '!-' Body '.'
Directive ::= ':-' ExportDirective | OperatorDirective | SetSemanticsDirective
| IgnoreDependencyCheckDirective | ImportModuleDirective
| PrefixDirective | CompilerDirective | IndexDirective
RuleDescriptor ::= '{' RuleTag '}'
| '{' BooleanRuleDescriptor '}'
| '@!{' RuleId ( '[' DescrBody ']' )? '}'
RuleTag ::= Term
RuleId ::= Term
BooleanRuleDescriptor ::= Term
DescrBody ::= DescrBodyElement (',' DescrBodyElement)*
DescrBodyElement ::= Term | Term '->' Term
// Heads in ERGO (not Flora-2 ) can also have ==>, <==, <==>, \or, and quantifiers
Head ::= ('\neg')? HeadLiteral
Head ::= Head (',' | '\and') Head
HeadLiteral ::= BinaryRelationship | ObjectSpecification | Term
Body ::= BodyLiteral
Body ::= BodyConjunct | BodyDisjunct | BodyNegative | ControlFlowStatement
// 'exists' can be used instead of 'exist'.
// Body-parentheses are optional, if Body is BodyLiteral
Body ::= 'forall(' VarList ')' 'b' '(' Body ')' | 'exist(' VarList ')' 'b' '(' Body ')'
Body ::= Body '@' ModuleName
Body ::= BodyConstraint
ModuleName ::= Atom | 'Atom()' | Atom '(' Atom ')' | ThisModuleName
BodyConjunct ::= Body (',' | '\and') Body
BodyDisjunct ::= Body (';' | '\or') Body
BodyNegative ::= (('\naf' | '\neg' | '\+') Body)
BodyConstraint ::= '{' CLPR-style constraint '}'
ControlFlowStatement ::= IfThenElse | UnlessDo
| WhileDo | WhileLoop
| DoUntil | LoopUntil
IfThenElse ::= '\if' Body '\then' Body ('\else' Body)?
| Body '<~~' Body | Body '~~>' Body | Body '<~~>' Body
| Body '<==' Body | Body '==>' Body | Body '<==>' Body
UnlessDo ::= '\unless' Body '\do' Body
WhileDo ::= '\while' Body '\do' Body
WhileLoop ::= '\while' Body '\loop' Body
DoUntil ::= '\do' Body '\until' Body
LoopUntil ::= '\loop' Body '\until' Body
BodyLiteral ::= BinaryRelationship | ObjectSpecification | Term
| DBUpdate | RuleUpdate | Refresh
| NewSkolemOp | Builtin | Loading | Compiling
| CatchExpr | ThrowExpr | TruthTest
Builtin ::= ArithmeticComparison | Unification | MetaUnification | "..."
Loading ::= '[' LoadingCommand (',' LoadingCommand)* ']'
| 'load{' LoadingCommand (',' LoadingCommand)* '}'
LoadingCommand ::= Filename ('>>' Atom)
Compiling ::= 'compile{' Filename '}'
BinaryRelationship ::= PathExpression ':' PathExpression
BinaryRelationship ::= PathExpression '::' PathExpression
ObjectSpecification ::= PathExpression '[' SpecBody ']'
SpecBody ::= ('\naf')? MethodSpecification
SpecBody ::= ('\neg')? ExplicitlyNegatableMethodSpecification
SpecBody ::= SpecBody ',' SpecBody
SpecBody ::= SpecBody ';' SpecBody
MethodSpecification ::= ('%')? Term
MethodSpecification ::= PathExpression (ValueReferenceConnective | SigReferenceConnective) PathExpression
ValueReferenceConnective ::= '->' | '+>>' | '->->' | '-->>'
SigReferenceConnective ::= ('{' (Integer|Variable) ':' (Integer|Variable) '}')? ('=>')
ExplicitlyNegatableMethodSpecification ::= Term
ExplicitlyNegatableMethodSpecification ::= PathExpression ExplicitlyNegatableReferenceConnective PathExpression
ExplicitlyNegatableReferenceConnective ::= '->' | SigReferenceConnective
PathExpression ::= Atom | Number | String | Iri | Variable | SpecialOidToken
PathExpression ::= Term | List | ReifiedFormula
PathExpression ::= PathExpression PathExpressionConnective PathExpression
PathExpression ::= BinaryRelationship
PathExpression ::= ObjectSpecification
PathExpression ::= Aggregate
Iri ::= SQname | FullIri
SQname ::= Identifier '#' String
FullIri ::= 'Śtring'
PathExpressionConnective ::= '.' | '!'
SpecialOidToken ::= AnonymousSkolem | NumberedSkolem | NamedSkolem | ThisModuleName
ReifiedFormula ::= '${' (Body | '(' Rule ')') '}'
// No quotes are allowed in the following quasi-constants!
// No space allowed between \# and Integer and \# and AlphanumAtom
// AnonymousSkolem & NumberedSkolem can occur only in rule head
// or in reified formulas
AnonymousSkolem ::= '\#'
// No space between \# and Integer
NumberedSkolem ::= '\#'Integer
// No space between \# and AlphanumAtom
NamedSkolem ::= '\#'AlphanumAtom
ThisModuleName ::= '\@'
List ::= '[' PathExpression (',' PathExpression)* ('|' PathExpression)? ']'
Term ::= Functor '(' Arguments ')'
Term ::= '%' Functor '(' Arguments ')'
Functor ::= PathExpression
Arguments ::= PathExpression (',' PathExpression)*
Aggregate ::= AggregateOperator '{' TargetVariable (GroupingVariables)? '|' Body '}'
AggregateOperator ::= 'max' | 'min' | 'avg' | 'sum' | 'setof' | 'bagof'
// Note: only one TargetVariable is permitted.
// It must be a variable, not a term. If you need to aggregate over terms,
// as for example, in setof/bagof, use the following idiom:
// S = setof{ V | ... , V=Term }
TargetVariable ::= Variable
GroupingVariables ::= '[' VarList ']'
Variable ::= '?' ([_a-zA-Z][_a-zA-Z0-9]*)?
VarList ::= Variable (',' Variable)*
DBUpdate ::= DBOp '{' UpdateList ('|' Body)? '}'
DBOp ::= 'insert' | 'insertall' | 'delete' | 'deleteall' | 'erase' | 'eraseall'
// In ERGO, UpdateList can also contain stealth literals
UpdateList ::= HeadLiteral ('@' Atom)?
UpdateList ::= UpdateList (',' | 'and') UpdateList
Refresh ::= 'refresh{' UpdateList '}'
RuleUpdate ::= RuleOp '{' RuleList '}'
RuleOp ::= 'insertrule' | 'insertrule_a' | 'insertrule_z' | 'deleterule' | 'deleterule_a' | 'deleterule_z'
RuleList ::= Rule | '(' Rule ')' ( (',' | 'and') '(' Rule ')' )*
NewSkolemOp ::= 'skolem{' Variable '}'
CatchExpr ::= 'catch{' Body Term Body '}'
ThrowExpr ::= 'throw{' Term '}'
TruthTest ::= 'true{' Body '}' | 'undefined{' Body '}' | 'false{' Body '}'
| 'truthvalue{' Variable '}'
Metadata
Metadata
Assignees
Labels
No labels