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

CQL2 grammar rules Conflict between "(" booleanExpression ")" and "(" arrayElement ")" #972

Open
kunlinyu opened this issue Dec 31, 2024 · 1 comment
Assignees
Labels

Comments

@kunlinyu
Copy link

I am develping a c++ parser and evaluator for CQL2 using bison. https://github.com/IndoorSpatial/cql2cpp
When I handling the arrayPredicate, the bison prints some warnings about reduce/reduce conflicts and shift/reduce conflict.
After I go thourgh the whole bison rules file and the BNF file in the standard. I found the reason.

Example 1 consider this query:

A_CONTAINS( (TRUE, FALSE, TRUE), (TRUE, FALSE) )

apperently the evaluation result should be TRUE.

Example 2 But consider about this query:

A_CONTAINS( (TRUE, FALSE, TRUE), ( (TRUE), (FALSE) ) )

The parser will be confused: what is the type of array elements in the second array?
Option 1
according to BNF:

booleanPrimary = function
               | predicate
               | booleanLiteral
               | "(" booleanExpression ")"  // <-----

TRUE -> booleanLiteral -> booleanPrimary -> booleanFactor -> booleanTerm -> booleanExpression
(TRUE) -> ( booleanExpression ) -> booleanPrimary -> booleanFactor -> booleanTerm -> booleanExpression
so the (TRUE) and (FALSE) are boolExpression. basically, Example 2 equals to Example 1 and the evaluation result should be TRUE.

Option 2
according to BNF:

array = "(" ")"  | "(" arrayElement [ { "," arrayElement } ] ")";
arrayElement = characterClause
             | numericLiteral
             | temporalInstance
             | spatialInstance
             | array
             | arithmeticExpression
             | booleanExpression   // <-------
             | propertyName
             | function;

the "(TRUE)" and "(FALSE)" is another array. So the evaluation result should be NULL or error.

I think the reason is, we use "( )" for both booleanExpression and array.
Let's say if we use "( )" for booleanExpression and "[ ]" for array, it is easy to handle it in my parser.
for example of Option1

A_CONTAINS( [TRUE, FALSE, TRUE], [ (TRUE), (FALSE) ] )

for example of Option2

A_CONTAINS( [TRUE, FALSE, TRUE], [ [TRUE], [FALSE] ] )
@kunlinyu kunlinyu changed the title Conflict when we use "(" boolExpression ")" in an array Conflict between "(" booleanExpression ")" and "(" arrayElement ")" Dec 31, 2024
@kunlinyu kunlinyu changed the title Conflict between "(" booleanExpression ")" and "(" arrayElement ")" CQL2 grammar rules Conflict between "(" booleanExpression ")" and "(" arrayElement ")" Dec 31, 2024
@pvretano
Copy link
Contributor

@kunlinyu I seem to recall a discussion in the SWG about using "[]" for arrays but I am not sure why we did not do that. Let me go back and check about that. Also, I'll try the grammar with YACC too, just to verify that it complains as well. Please stand by ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants