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

BNFC grammar vs natural4 grammar rules #602

Open
fendor opened this issue Jul 25, 2024 · 7 comments
Open

BNFC grammar vs natural4 grammar rules #602

fendor opened this issue Jul 25, 2024 · 7 comments

Comments

@fendor
Copy link
Contributor

fendor commented Jul 25, 2024

The recently added BNFC #591 parser for a fragment of natural4 has some seeming inconsistencies with the csv-based language.

This issue is for tracking these differences and discussing parts of the syntax and informal semantics.

One thing I found a bit confusing is the where clauses of a Hornlike rule. For example take:

GIVEN x
DECIDE g x IS y
WHERE y IS 5

The Hornlike rule has a wwhere :: [Rule] field, but according to #591, the WHERE part can only contain RelationalPredicates. Is this an intentional difference to natural4 or actually the status-quo of how the natural4 parser works right now?

Note, I am omitting (ignoring) a discussion from the 25.7.2024 where it sounded like WHERE should mirror Haskell's where, allowing the declaration and definition of arbitrary rules.

@fendor
Copy link
Contributor Author

fendor commented Jul 25, 2024

@inariksit I think you are likely the best person to answer this question?

@mengwong
Copy link
Contributor

mengwong commented Aug 2, 2024

My initial ambition was to adopt Haskell where semantics. I think the narrowing to RelationalPredicates was due entirely to limitations at the time, so we went with a simplified implementation. To fully support Haskell where semantics required a fuller notion of scope. We are only now beginning to address that issue. This past week we have tentatively agreed on Module-style semantics for binding scope.

@inariksit
Copy link
Contributor

I believe we had some discussion on whether a GIVETH would make sense in a WHERE, and the results were inconclusive. GIVEN would make sense: this is the (very ad hoc) syntax I/we established for functions last spring, fully based on the PAU case.

GIVEN x IS A Number ; 
            y IS A Number
DECIDE x `discounted by` y IS `x * (1 - y)`

Or in a table form, it looks like

GIVEN x IS A Number
y IS A Number
DECIDE x discounted by y IS x * (1 - y)

@fendor
Copy link
Contributor Author

fendor commented Aug 13, 2024

Is x * (1 - y) supposed to be a function or the bnfc equivalent MUL(x, MINUS(1, y))?

@fendor
Copy link
Contributor Author

fendor commented Aug 13, 2024

Regarding the semantics of GIVETH, if we treat as GIVETH as a declaration of output variables, then rules in WHERE clauses may have a GIVETH. For example;

GIVEN x DECIDE f x IS SUM(y, z)
WHERE
  GIVETH y, z 
  DECIDE y IS 5;
         z IS 7

Even though, it is possible to write this in two separate Rules, I think it makes sense to support this syntax. Especially, since we decided WHERE should have Haskell-like where semantics, then the rules in WHERE clauses could be allowed to be full blown Hornlike rules. However, I am unsure how this interacts with UPON and other temporal rules.

@inariksit
Copy link
Contributor

Is x * (1 - y) supposed to be a function or the bnfc equivalent MUL(x, MINUS(1, y))?

Yes, it is! The GML transpiler uses an expression parser inside the cells, but for other targets MUL(x, MINUS(1, y)) should be used.

So in conclusion, should I amend the BNFC parser to accept full Rules in the WHERE clause? (In a way that doesn't break existing examples, of course.)

@fendor
Copy link
Contributor Author

fendor commented Aug 13, 2024

should I amend the BNFC parser to accept full Rules in the WHERE clause?

For now, I believe so, yeah :)

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

3 participants