gocc
gocc copied to clipboard
fix int64-define-in-calc-example
if not, panic:
{"1 + 0", 1}
...
calc_test.go:28: Error in S7: INVALID(0,0), Pos(offset=4, line=1, column=5), expected one of: ( int64
calc_test.go:31: Error: 1 + 0 = %!d(<nil>). Expected 1
@shivansh thanks for you reply, done.
@Chyroc Awesome, thanks! Can you also please squash all commits into one, that'd make the git history cleaner.
@shivansh done, and for github, we can use squash and merge
option, the result is the same:
Good catch I also think {"1 + 0", 1}
should work.
But I don't think {"1 + 01", 2}
should work. I think this should give an error.
So the lexer needs to updated not to parse 01
as a digit.
@awalterschulze oic ; although wouldn't 01
count as a valid whole number representation ?
but in golang strconv.Atoi
package main
import (
"strconv"
"fmt"
)
func main() {
x, err := strconv.Atoi("01")
if err != nil {
panic(err)
}
fmt.Printf("%v\n", x)
}
print 1, not panic with err
Ok fair, I think I am wrong and you are right, my bad :)
On Fri, 8 Jun 2018 at 13:09 Chyroc [email protected] wrote:
but in golang strconv.Atoi
package main import ( "strconv" "fmt" ) func main() { x, err := strconv.Atoi("01") if err != nil { panic(err) }
fmt.Printf("%v\n", x) }
print 1, not panic with err
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/goccmack/gocc/pull/79#issuecomment-395729029, or mute the thread https://github.com/notifications/unsubscribe-auth/ABvsLYhkmTCCf3fiOIG97NVUnqlbhW6oks5t6lthgaJpZM4Uf3xQ .
Shouldn't it also support input like 0x1 in that case?
01 should be interpreted as octal right?
Try with 10, 010 and 0x10 instead to avoid false positives.
Med Vänliga Hälsningar Alexander Andersson
Atoi is only base 10 and does parse 010 to decimal 10. I expected it to work like ParseInt(s, 0, 0) for some reason. I would not like to accept leading zeros as there might be an expectation for it to be interpreted as octal. https://golang.org/pkg/strconv/#Atoi https://gobyexample.com/number-parsing
Sunny regards from Sweden Rock Festival