#๐Ÿ”’ problem with parsing

37 messages ยท Page 1 of 1 (latest)

oak nimbus
#

i'm following this tutorial (translating to python) and i'm at the prefix and postfix operators section.

my problem is that it terminates early on the test case --1 * 2. i believe it's due to some early return somewhere here, but i'm not really sure how to debug this.

my code: https://paste.pythondiscord.com/7KNQ (comment out line 74 - that's a stray debug statement)

graceful lynxBOT
#

@oak nimbus

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

oak nimbus
#

bump

oak nimbus
#

bump 2

misty saddle
#

do you have a case for -- as a token?

#

or is the intent to have it bind in such a way that --1*2 is basically -(-1*2)?

oak nimbus
misty saddle
#

right, I wasn't sure what -- was supposed to do there

oak nimbus
coarse abyss
#

theres no diff between match-case and if-else so u could use either and in my opinion if-else is more common just saying

misty saddle
#

well, it does look like a prefix - is set to have a higher binding power than other operations

#

does it output what it thinks is the token stream for that test?

oak nimbus
#

and i understand they're the same

misty saddle
# oak nimbus wdym

when you run your tests, can you print what it thinks the tokens and binding are for the input?

#

to me that would seem like a good first step to figuring out what it's doing and why it might be failing

oak nimbus
# misty saddle when you run your tests, can you print what it thinks the tokens and binding are...
Tokens: [<Token value='-' type='operation'>, <Token value='-' type='operation'>, <Token value='1' type='number-literal'>, <Token value='*' type='operation'>, <Token value='2' type='number-literal'>, <Token value='' type='eof'>]
On token: <Token value='-' type='operation'>
On token: <Token value='-' type='operation'>
On token: <Token value='1' type='number-literal'>
``` ```yml
Failed test #1!
Input: '--1 * 2'
Expected: '(* (- (- 1)) 2)'
Result: '(- (- 1))'
misty saddle
#

what happens if you test -1 * 2?

oak nimbus
# misty saddle what happens if you test `-1 * 2`?
Tokens: [<Token value='-' type='operation'>, <Token value='1' type='number-literal'>, <Token value='*' type='operation'>]
On token: <Token value='-' type='operation'>
On token: <Token value='1' type='number-literal'>
Failed test #1!
Input: '-1 * 2'
Expected: '(* (- 1) 2)'
Result: '(- 1)'
misty saddle
#

it sounds like there's some issue with the way you're handling *

#

try 1 * 2 + 3, for instance

oak nimbus
oak nimbus
# misty saddle try ` 1 * 2 + 3`, for instance

ignore the test number ```yml
Tokens: [<Token value='1' type='number-literal'>, <Token value='+' type='operation'>, <Token value='2' type='number-literal'>, <Token value='*' type='operation'>]
On token: <Token value='1' type='number-literal'>
On token: <Token value='2' type='number-literal'>
On token: <Token value='3' type='number-literal'>
Passed test #1!

#

sorry if i'm disappearing for long periods of time

#

i'm in between debugging this and helping a friend with their math homework

#

so ping me with every response

misty saddle
#

same, I have to leave in a little

#

so it sounds like there's some issue with the way the higher binding strength is with a unary op, I don't have more than that offhand

oak nimbus
oak nimbus
oak nimbus
#

ah this is painful to debug

oak nimbus
#

bump

graceful lynxBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.