gocc icon indicating copy to clipboard operation
gocc copied to clipboard

fix int64-define-in-calc-example

Open chyroc opened this issue 6 years ago • 9 comments

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

chyroc avatar Jun 08 '18 10:06 chyroc

@shivansh thanks for you reply, done.

chyroc avatar Jun 08 '18 10:06 chyroc

@Chyroc Awesome, thanks! Can you also please squash all commits into one, that'd make the git history cleaner.

shivansh avatar Jun 08 '18 10:06 shivansh

@shivansh done, and for github, we can use squash and merge option, the result is the same: image

chyroc avatar Jun 08 '18 11:06 chyroc

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 avatar Jun 08 '18 11:06 awalterschulze

@awalterschulze oic ; although wouldn't 01 count as a valid whole number representation ?

shivansh avatar Jun 08 '18 11:06 shivansh

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

chyroc avatar Jun 08 '18 11:06 chyroc

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 .

awalterschulze avatar Jun 08 '18 11:06 awalterschulze

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

sangisos avatar Jun 08 '18 14:06 sangisos

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

sangisos avatar Jun 09 '18 10:06 sangisos