Below the grammar i make.
- S' -> sqf
- sqf -> declarations
- declarations -> declaration
- declarations -> declaration declarations
- declaration -> relation
- declaration -> norelation
- relation -> head body
- norelation -> relatts
- norelation -> reldata
- norelation -> relatts reldata
- head -> relname attributes
- body -> reldata
- body -> empty
- relname -> RELKW IDENTIFIER
- attributes -> relatts
- attributes -> empty
- relatts -> attname
- relatts -> attname relatts
- reldata -> DATAKW tuples
- reldata -> DATAKW
- tuples -> tuple
- tuples -> tuple tuples
- attname -> ATTKW IDENTIFIER
- tuple -> VALUE
- empty ->
The problem is that the grammar is ambiguous because for some rules there are shift/reduce conflicts. Particularly
at the rules below for DATAKW we have shift/reduce conflict
- relation -> head body
- body -> reldata
- body -> empty
- reldata -> DATAKW tuples
- reldata -> DATAKW
- *empty -> *
at the rules below for DATAKW we have shift/reduce conflict
- norelation -> relatts
- norelation -> relatts reldata
- reldata -> DATAKW tuples
- reldata -> DATAKW
at the rules below for ATTKW we have shift/reduce conflict
- head -> relname attributes
- attributes -> relatts
- attributes -> empty
- relatts -> attname
- relatts -> attname relatts
- *empty -> *
- attname -> ATTKW IDENTIFIER
at the rules below for ATTKW we have shift/reduce conflict
- relatts -> attname
- relatts -> attname relatts
- relatts -> attname
- relatts -> attname relatts
- attname -> ATTKW IDENTIFIER
Can anyone help me to solve that conflicts, please.
A problem is that the grammar cannot determine where one
declarationends and the next one begins.A simple instance of this general problem:
norelationcan be just arelattswhich can be a list ofattnames. So if you have two consecutivenorelation, that could be two sequences ofattnames. How can you distinguish two consecutive sequences from one longer sequence? Or three shorter ones? Etc.There are many other instances of the same issue.
Unless you've transcribed the language incorrectly, this is a problem of language design, and semicolons are a common solution.