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

backslash used as operator (integer division) #23

Closed
dequeb opened this issue Jan 24, 2024 · 2 comments
Closed

backslash used as operator (integer division) #23

dequeb opened this issue Jan 24, 2024 · 2 comments

Comments

@dequeb
Copy link

dequeb commented Jan 24, 2024

in BASIC, the backslash character (\) is used for integer division on float numbers. When I try to use it, I get an error. Here is the code:

package "BUG_REPPORT"

Expr
	: number "\\" number;      	    								

And here is the message :

Parse Errors:
Parse Error: SyntaxRule : nt : ∙SyntaxAlternates ;  I[4]=number (36,42) number at line 6 col 7
Expected one of: [empty,nt,string_lit,tokid]

I also tried:

package "BUG_REPPORT"

Expr
	: number intDivOp number;      	    								

intDivOp: '\\';

This gives me the same error as above.

@goccmack
Copy link
Owner

gogll does not allow escaped chars in string_lit. You can define and use a division token as in the following grammar:

package "test"

div : '\\' ;

int : number {number} ;

Expr : int div int ;

You can test the grammar as follows:

package test

import (
"test/lexer"
"test/parser"
"testing"
)

const input = 12 \ 4

func Test1(t *testing.T) {
l := lexer.New([]rune(input))
_, errs := parser.Parse(l)
if len(errs) > 0 {
t.Fail()
}
}

go test -v
=== RUN Test1
--- PASS: Test1 (0.00s)
PASS
ok test 0.414s

@dequeb dequeb closed this as completed Jan 24, 2024
@dequeb
Copy link
Author

dequeb commented Jan 24, 2024

Thank you for your suggestion.

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

2 participants