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

Robot grammar adjustment #44

Open
ReubenJ opened this issue Jun 5, 2024 · 2 comments
Open

Robot grammar adjustment #44

ReubenJ opened this issue Jun 5, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@ReubenJ
Copy link
Member

ReubenJ commented Jun 5, 2024

Some ideas regarding the robot grammar after discussing today with @pwochner.

Current Implementation

In the new robot grammar, here:

grammar_robots = @csgrammar begin
Start = Sequence #1
Sequence = Operation #2
Sequence = (Operation; Sequence) #3
Operation = Transformation #4
Operation = ControlStatement #5
Transformation = moveRight() | moveDown() | moveLeft() | moveUp() | drop() | grab() #6
ControlStatement = IF(Condition, Sequence, Sequence) #12
ControlStatement = WHILE(Condition, Sequence) #13
Condition = atTop() | atBottom() | atLeft() | atRight() | notAtTop() | notAtBottom() | notAtLeft() | notAtRight() #14
end

the resulting syntax trees are cluttered with RuleNode(3, [...]). For example, the program for grab, move up, and finally move right is written as

(grab(); (moveUp(); moveRight()))

which corresponds to the RuleNodes: 3{11,3{9,6}}.

Note that this current Sequence syntax does not allow us to write variable-length sequences. It always results in a quote block with two children, the first one being another operation and the other being either an operation or another nested quote block.

Alternative

What if we let each Transformation take the next action as an argument? We would then remove the Sequence rules and maybe add a single End() terminal operation.

The expression would become

grab(moveUp(moveRight(End())))

and the RuleNode representation: `11{9,{6,{22}}

We can keep the interpret function mostly the same, meaning that we first apply grab to the state, thenmoveUp, etc. Functionally, it would be the same, but the resulting syntax trees will contain roughly half the number of nodes.

@ReubenJ ReubenJ added the enhancement New feature or request label Jun 5, 2024
@sebdumancic
Copy link
Member

The only issue that I can spot with the proposed version is that it is quite unintuitive.
I would read

grab(moveUp(moveRight(End())))

as move right, move up, and then grab rather than the other way around.

@ReubenJ
Copy link
Member Author

ReubenJ commented Jun 6, 2024

Yep, I see your point. I guess this would be a tradeoff between readability of the expression, and size of the synthesized program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants