Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grammar railroad diagram #9

Open
mingodad opened this issue Jul 17, 2021 · 0 comments
Open

Grammar railroad diagram #9

mingodad opened this issue Jul 17, 2021 · 0 comments

Comments

@mingodad
Copy link

Using this tool https://www.bottlecaps.de/convert/ (using https://github.com/konclude/rasqal) and manually adding the tokens from rasqal/blob/master/src/sparql_lexer.l we can see a railroad diagram for the grammar in rasqal/master/src/sparql_parser.y copy and paste the EBNF shown bellow on https://www.bottlecaps.de/rr/ui in the tab Edit Grammar then switching to the tab View Diagram.

/*
From https://raw.githubusercontent.com/konclude/rasqal/master/src/sparql_parser.y
*/

/* converted on Sat Jul 17, 2021, 13:47 (UTC+02) by bison-to-w3c v0.53 which is Copyright (c) 2011-2021 by Gunther Rademacher <[email protected]> */

Sparql   ::= Query
           | Update
Query    ::= Prologue ExplainOpt ReportFormat ValuesClauseOpt
ExplainOpt
         ::= EXPLAIN?
ReportFormat
         ::= SelectQuery
           | ConstructQuery
           | DescribeQuery
           | AskQuery
Update   ::= Prologue UpdateOperation UpdateTailOpt
UpdateTailOpt
         ::= ( ';' Update? )?
UpdateOperation
         ::= DeleteQuery
           | InsertQuery
           | UpdateQuery
           | ClearQuery
           | CreateQuery
           | DropQuery
           | LoadQuery
           | AddQuery
           | MoveQuery
           | CopyQuery
Prologue ::= BaseDeclOpt ( PREFIX IDENTIFIER URI_LITERAL )*
BaseDeclOpt
         ::= ( BASE URI_LITERAL )?
SelectQuery
         ::= SelectClause DatasetClauseListOpt WhereClause SolutionModifier
SubSelect
         ::= SelectClause WhereClause SolutionModifier ValuesClauseOpt
SelectClause
         ::= SELECT ( DISTINCT | REDUCED )? SelectExpressionList
SelectExpressionList
         ::= SelectTerm ( ','? SelectTerm )*
           | '*'
SelectTerm
         ::= Var
           | '(' Expression AS VarOrBadVarName ')'
AggregateExpression
         ::= CountAggregateExpression
           | SumAggregateExpression
           | AvgAggregateExpression
           | MinAggregateExpression
           | MaxAggregateExpression
           | GroupConcatAggregateExpression
           | SampleAggregateExpression
DistinctOpt
         ::= DISTINCT?
ExpressionOrStar
         ::= Expression
           | '*'
CountAggregateExpression
         ::= COUNT '(' DistinctOpt ExpressionOrStar ')'
SumAggregateExpression
         ::= SUM '(' DistinctOpt Expression ')'
AvgAggregateExpression
         ::= AVG '(' DistinctOpt Expression ')'
MinAggregateExpression
         ::= MIN '(' DistinctOpt Expression ')'
MaxAggregateExpression
         ::= MAX '(' DistinctOpt Expression ')'
SeparatorOpt
         ::= ( ';' SEPARATOR EQ STRING )?
ExpressionList
         ::= Expression ( ',' Expression )*
GroupConcatAggregateExpression
         ::= GROUP_CONCAT '(' DistinctOpt ExpressionList SeparatorOpt ')'
SampleAggregateExpression
         ::= SAMPLE '(' DistinctOpt Expression ')'
ConstructQuery
         ::= CONSTRUCT ( ConstructTemplate DatasetClauseListOpt WhereClause | DatasetClauseListOpt WHERE '{' ConstructTriples '}' ) SolutionModifier
DescribeQuery
         ::= DESCRIBE ( VarOrIRIref ( ','? VarOrIRIref )* | '*' ) DatasetClauseListOpt WhereClauseOpt SolutionModifier
AskQuery ::= ASK DatasetClauseListOpt WhereClause
DatasetClause
         ::= FROM ( DefaultGraphClause | NamedGraphClause )
GraphRef ::= GRAPH URI_LITERAL
DeleteQuery
         ::= DELETE ( DatasetClauseList WhereClauseOpt | '{' ModifyTemplateList '}' WhereClause | DATA '{' GraphTriples '}' | WHERE GroupGraphPattern )
GraphTriples
         ::= TriplesBlock
           | GRAPH URI_LITERAL '{' TriplesBlock '}'
GraphTemplate
         ::= GRAPH VarOrIRIref '{' ConstructTriples '}'
ModifyTemplate
         ::= ConstructTriples
           | GraphTemplate
ModifyTemplateList
         ::= ModifyTemplate+
InsertQuery
         ::= INSERT ( ( DatasetClauseList | '{' ModifyTemplateList '}' ) WhereClauseOpt | DATA '{' GraphTriples '}' )
UpdateQuery
         ::= WITH URI_LITERAL ( DELETE '{' ModifyTemplateList '}' ( INSERT '{' ModifyTemplateList '}' )? WhereClauseOpt | INSERT ( '{' ModifyTemplateList '}' WhereClauseOpt | DATA '{' GraphTriples '}' ) )
GraphRefAll
         ::= GraphRef
           | GRAPH? DEFAULT
           | NAMED
           | ALL
ClearQuery
         ::= CLEAR ( SilentOpt GraphRefAll )?
SilentOpt
         ::= SILENT?
CreateQuery
         ::= CREATE SilentOpt ( URI_LITERAL | GraphRef )
DropQuery
         ::= DROP SilentOpt GraphRefAll
GraphOrDefault
         ::= DEFAULT
           | URI_LITERAL
OldGraphRef
         ::= GraphRef
           | URI_LITERAL
           | DEFAULT
LoadQuery
         ::= LOAD SilentOpt ( URI_LITERAL | URI_LITERAL+ INTO OldGraphRef )
AddQuery ::= ADD SilentOpt GraphOrDefault TO GraphOrDefault
MoveQuery
         ::= MOVE SilentOpt GraphOrDefault TO GraphOrDefault
CopyQuery
         ::= COPY SilentOpt GraphOrDefault TO GraphOrDefault
DatasetClauseList
         ::= DatasetClause+
DatasetClauseListOpt
         ::= DatasetClauseList?
DefaultGraphClause
         ::= SourceSelector
NamedGraphClause
         ::= NAMED SourceSelector
SourceSelector
         ::= IRIref
WhereClause
         ::= WHERE? GroupGraphPattern
WhereClauseOpt
         ::= WhereClause?
SolutionModifier
         ::= GroupClauseOpt HavingClauseOpt OrderClauseOpt LimitOffsetClausesOpt
AsVarOpt ::= ( AS Var )?
GroupCondition
         ::= BuiltInCall
           | FunctionCall
           | '(' Expression AsVarOpt ')'
           | Var
GroupClauseOpt
         ::= ( GROUP BY GroupCondition+ )?
HavingCondition
         ::= Constraint
HavingClauseOpt
         ::= ( HAVING HavingCondition+ )?
LimitOffsetClausesOpt
         ::= ( LimitClause OffsetClause? | OffsetClause LimitClause? )?
OrderClauseOpt
         ::= ( ORDER BY OrderCondition+ )?
OrderCondition
         ::= ( ASC | DESC )? BrackettedExpression
           | FunctionCall
           | Var
           | BuiltInCall
LimitClause
         ::= LIMIT INTEGER_LITERAL
OffsetClause
         ::= OFFSET INTEGER_LITERAL
ValuesClauseOpt
         ::= ( VALUES DataBlock )?
VarListOpt
         ::= Var*
DataBlockRowListOpt
         ::= DataBlockRow*
DataBlockRow
         ::= '(' DataBlockValueList? ')'
DataBlockValueList
         ::= DataBlockValue+
RDFLiteral
         ::= STRING ( LANGTAG | HATHAT IRIref )?
           | NumericLiteral HATHAT IRIref
DataBlockValue
         ::= IRIref
           | RDFLiteral
           | NumericLiteral
           | BOOLEAN_LITERAL
           | UNDEF
GroupGraphPattern
         ::= '{' ( SubSelect | GroupGraphPatternSub ) '}'
GroupGraphPatternSub
         ::= TriplesBlockOpt GraphPatternList? GraphPatternList*
TriplesBlockOpt
         ::= TriplesBlock?
GraphPatternList
         ::= GraphPatternListFilter DotOptional TriplesBlockOpt
GraphPatternListFilter
         ::= GraphPatternNotTriples
           | Filter
DotOptional
         ::= '.'?
TriplesBlock
         ::= TriplesSameSubject ( '.' TriplesBlockOpt )?
GraphPatternNotTriples
         ::= GroupOrUnionGraphPattern
           | OptionalGraphPattern
           | MinusGraphPattern
           | GraphGraphPattern
           | ServiceGraphPattern
           | LetGraphPattern
           | Bind
           | InlineDataGraphPattern
OptionalGraphPattern
         ::= OPTIONAL GroupGraphPattern
GraphGraphPattern
         ::= GRAPH VarOrIRIref GroupGraphPattern
ServiceGraphPattern
         ::= SERVICE SilentOpt VarOrIRIref GroupGraphPattern
Bind     ::= BIND '(' Expression AS Var ')'
InlineData
         ::= VALUES DataBlock
DataBlock
         ::= InlineDataOneVar
           | InlineDataFull
InlineDataOneVar
         ::= Var '{' DataBlockValueListOpt '}'
DataBlockValueListOpt
         ::= DataBlockValueList?
InlineDataFull
         ::= '(' VarListOpt ')' '{' DataBlockRowListOpt '}'
InlineDataGraphPattern
         ::= InlineData
MinusGraphPattern
         ::= MINUS GroupGraphPattern
GroupOrUnionGraphPattern
         ::= GroupGraphPattern ( UNION GroupGraphPattern )*
LetGraphPattern
         ::= LET '(' Var ASSIGN Expression ')'
Filter   ::= FILTER Constraint
Constraint
         ::= BrackettedExpression
           | BuiltInCall
           | FunctionCall
ParamsOpt
         ::= ';'?
FunctionCall
         ::= ( IRIref '(' DistinctOpt ArgListNoBraces ParamsOpt | IRIrefBrace ArgListNoBraces ) ')'
CoalesceExpression
         ::= COALESCE ArgList
ArgList  ::= '(' ArgListNoBraces ')'
ArgListNoBraces
         ::= Expression? ( ',' Expression )*
ConstructTemplate
         ::= '{' ConstructTriplesOpt '}'
ConstructTriplesOpt
         ::= ConstructTriples?
ConstructTriples
         ::= TriplesSameSubject ( '.' ConstructTriplesOpt )?
TriplesSameSubject
         ::= VarOrTerm PropertyListNotEmpty
           | TriplesNode PropertyList
PropertyListNotEmpty
         ::= Verb ObjectList PropertyListTailOpt
PropertyListTailOpt
         ::= ( ';' PropertyList )?
PropertyList
         ::= PropertyListNotEmpty?
ObjectList
         ::= Object ObjectTail
ObjectTail
         ::= ( ',' ObjectList )?
Object   ::= GraphNode
Verb     ::= VarOrIRIref
           | A
TriplesNode
         ::= Collection
           | BlankNodePropertyList
BlankNodePropertyList
         ::= '[' PropertyListNotEmpty ']'
Collection
         ::= '(' GraphNode+ ')'
GraphNode
         ::= VarOrTerm
           | TriplesNode
VarOrTerm
         ::= Var
           | GraphTerm
VarOrIRIref
         ::= Var
           | IRIref
Var      ::= ( '?' | '$' ) VarName
VarName  ::= IDENTIFIER
VarOrBadVarName
         ::= ( '?' | '$' )? VarName
GraphTerm
         ::= IRIref
           | RDFLiteral
           | NumericLiteral
           | BOOLEAN_LITERAL
           | BlankNode
           | '(' ')'
Expression
         ::= ConditionalAndExpression ( SC_OR ConditionalAndExpression )*
ConditionalAndExpression
         ::= RelationalExpression ( SC_AND RelationalExpression )*
RelationalExpression
         ::= AdditiveExpression ( ( EQ | NEQ | LT | GT | LE | GE ) AdditiveExpression | NOT? IN ArgList )?
AdditiveExpression
         ::= MultiplicativeExpression AdExOpExpressionListInner*
AdExOpExpressionListInner
         ::= ( '+' | '-' ) MultiplicativeExpression
           | ( NumericLiteralPositive | NumericLiteralNegative ) AdExOpUnaryExpressionListOpt
AdExOpUnaryExpressionListOpt
         ::= AdExOpUnaryExpression*
AdExOpUnaryExpression
         ::= ( '*' | '/' ) UnaryExpression
MultiplicativeExpression
         ::= UnaryExpression MuExOpUnaryExpression*
MuExOpUnaryExpression
         ::= ( '*' | '/' ) UnaryExpression
UnaryExpression
         ::= ( '!' | '+' | '-' )? PrimaryExpression
PrimaryExpression
         ::= BrackettedExpression
           | BuiltInCall
           | FunctionCall
           | GraphTerm
           | Var
           | AggregateExpression
BrackettedExpression
         ::= '(' Expression ')'
BuiltInCall
         ::= ( ( ( STR | LANG | DATATYPE | IRI | URI | ABS | CEIL | FLOOR | ROUND | MD5 | SHA1 | SHA224 | SHA256 | SHA384 | SHA512 | ISURI | ISBLANK | ISLITERAL | ISNUMERIC ) '(' | ( ( LANGMATCHES | STRLANG | STRDT | SAMETERM ) '(' | IF '(' Expression ',' ) Expression ',' ) Expression | BOUND '(' Var | ( RAND | UUID | STRUUID ) '(' | BNODE '(' Expression? ) ')'
           | StringExpression
           | CoalesceExpression
           | RegexExpression
           | DatetimeBuiltinAccessors
           | DatetimeExtensions
StringExpression
         ::= ( ( ( STRLEN | UCASE | LCASE | ENCODE_FOR_URI ) '(' | ( ( STRSTARTS | STRENDS | CONTAINS | STRBEFORE | STRAFTER ) '(' | ( SUBSTR '(' | REPLACE '(' Expression ',' ) ( Expression ',' )? ) Expression ',' ) Expression | CONCAT '(' ExpressionList ) ')'
RegexExpression
         ::= REGEX '(' Expression ',' Expression ( ',' Expression )? ')'
DatetimeBuiltinAccessors
         ::= ( YEAR | MONTH | DAY | HOURS | MINUTES | SECONDS | TIMEZONE | TZ ) '(' Expression ')'
DatetimeExtensions
         ::= ( ( CURRENT_DATETIME | NOW ) '(' | ( FROM_UNIXTIME | TO_UNIXTIME ) '(' Expression ) ')'
IRIrefBrace
         ::= URI_LITERAL_BRACE
           | QNAME_LITERAL_BRACE
NumericLiteral
         ::= NumericLiteralUnsigned
           | NumericLiteralPositive
           | NumericLiteralNegative
NumericLiteralUnsigned
         ::= INTEGER_LITERAL
           | DECIMAL_LITERAL
           | DOUBLE_LITERAL
NumericLiteralPositive
         ::= INTEGER_POSITIVE_LITERAL
           | DECIMAL_POSITIVE_LITERAL
           | DOUBLE_POSITIVE_LITERAL
NumericLiteralNegative
         ::= INTEGER_NEGATIVE_LITERAL
           | DECIMAL_NEGATIVE_LITERAL
           | DOUBLE_NEGATIVE_LITERAL
IRIref   ::= URI_LITERAL
           | QNAME_LITERAL
BlankNode
         ::= BLANK_LITERAL
           | '[' ']'

// Tokens from https://github.com/konclude/rasqal/blob/master/src/sparql_lexer.l

SELECT ::= "SELECT"
FROM ::= "FROM"
WHERE ::= "WHERE"
PREFIX ::= "PREFIX"
DESCRIBE ::= "DESCRIBE"
CONSTRUCT ::= "CONSTRUCT"
ASK ::= "ASK"
DISTINCT ::= "DISTINCT"
REDUCED ::= "REDUCED"
LIMIT ::= "LIMIT"
UNION ::= "UNION"
OPTIONAL ::= "OPTIONAL"
BASE ::= "BASE"
BOUND ::= "BOUND"
STRLANG ::= "STRLANG"
STRDT ::= "STRDT"
STR ::= "STR"
LANG ::= "LANG"
DATATYPE ::= "DATATYPE"
ISURI ::= "ISURI"
ISBLANK ::= "ISBLANK"
ISLITERAL ::= "ISLITERAL"
GRAPH ::= "GRAPH"
NAMED ::= "NAMED"
FILTER ::= "FILTER"
OFFSET ::= "OFFSET"
ORDER ::= "ORDER"
BY ::= "BY"
REGEX ::= "REGEX"
ASC ::= "ASC"
DESC ::= "DESC"
LANGMATCHES ::= "LANGMATCHES"
EXPLAIN ::= "EXPLAIN"
GROUP ::= "GROUP"
HAVING ::= "HAVING"
COUNT ::= "COUNT"
SUM ::= "SUM"
AVG ::= "AVG"
MIN ::= "MIN"
MAX ::= "MAX"
AS ::= "AS"
DELETE ::= "DELETE"
INSERT ::= "INSERT"
SAMETERM ::= "SAMETERM"
LET ::= "LET"
COALESCE ::= "COALESCE"
WITH ::= "WITH"
CLEAR ::= "CLEAR"
CREATE ::= "CREATE"
SILENT ::= "SILENT"
DATA ::= "DATA"
DROP ::= "DROP"
LOAD ::= "LOAD"
INTO ::= "INTO"
IF ::= "IF"
IRI ::= "IRI"
URI ::= "URI"
BNODE ::= "BNODE"
DEFAULT ::= "DEFAULT"
NOT ::= "NOT"
IN ::= "IN"
GROUP_CONCAT ::= "GROUP_CONCAT"
SEPARATOR ::= "SEPARATOR"
BIND ::= "BIND"
BINDINGS ::= "BINDINGS"
UNDEF ::= "UNDEF"
SERVICE ::= "SERVICE"
MINUS ::= "MINUS"
ISNUMERIC ::= "ISNUMERIC"
SAMPLE ::= "SAMPLE"
YEAR ::= "YEAR"
MONTH ::= "MONTH"
DAY ::= "DAY"
HOURS ::= "HOURS"
MINUTES ::= "MINUTES"
SECONDS ::= "SECONDS"
TIMEZONE ::= "TIMEZONE"
CURRENT_DATETIME ::= "CURRENT_DATETIME"
NOW ::= "NOW"
FROM_UNIXTIME ::= "FROM_UNIXTIME"
TO_UNIXTIME ::= "TO_UNIXTIME"
CONCAT ::= "CONCAT"
STRLEN ::= "STRLEN"
SUBSTR ::= "SUBSTR"
UCASE ::= "UCASE"
LCASE ::= "LCASE"
STRSTARTS ::= "STRSTARTS"
STRENDS ::= "STRENDS"
CONTAINS ::= "CONTAINS"
ENCODE_FOR_URI ::= "ENCODE_FOR_URI"
TO ::= "TO"
ADD ::= "ADD"
MOVE ::= "MOVE"
COPY ::= "COPY"
ALL ::= "ALL"
TZ ::= "TZ"
RAND ::= "RAND"
ABS ::= "ABS"
ROUND ::= "ROUND"
CEIL ::= "CEIL"
FLOOR ::= "FLOOR"
MD5 ::= "MD5"
SHA1 ::= "SHA1"
SHA224 ::= "SHA224"
SHA256 ::= "SHA256"
SHA384 ::= "SHA384"
SHA512 ::= "SHA512"
STRBEFORE ::= "STRBEFORE"
STRAFTER ::= "STRAFTER"
REPLACE ::= "REPLACE"
UUID ::= "UUID"
STRUUID ::= "STRUUID"
VALUES ::= "VALUES"

A ::= "a"


SC_OR ::= "||"
SC_AND ::= "&&"

EQ ::= "="
NEQ ::= "!="
LT ::= "<"
GT ::= ">"
LE ::= "<="
GE ::= ">="

ASSIGN ::= ":="

HATHAT ::= "^^"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant