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

When using archimetric operators in print, strings are ignored #54

Open
ghuls opened this issue Mar 25, 2021 · 3 comments
Open

When using archimetric operators in print, strings are ignored #54

ghuls opened this issue Mar 25, 2021 · 3 comments

Comments

@ghuls
Copy link
Contributor

ghuls commented Mar 25, 2021

When using archimetric operators in print, strings are ignored (or converted to 0).

❯ frawk 'BEGIN { print "test" 6}'
test6

# Should print "test11"
❯ frawk 'BEGIN { print "test" 6 + 5 }'
5

❯ frawk 'BEGIN { print "test" (6 + 5) }'
test11

❯ frawk 'BEGIN { print 6 "test" }'
6test

# Should print "11test"
❯ frawk 'BEGIN { print 6 + 5 "test" }'
11

❯ frawk 'BEGIN { print (6 + 5) "test" }'
11test
@ezrosent
Copy link
Owner

ezrosent commented Mar 25, 2021

Oh nice, thanks! This looks like an operator precedence issue. In Awk, 6 + 5 "test" gets parsed at (6 + 5) "test" but frawk is doing 6 + (5 "test").

I'll take a look.

@ghuls
Copy link
Contributor Author

ghuls commented Mar 25, 2021

Another error I just encountered (division seen as part of a regex):

❯ frawk 'BEGIN { t_array[0] = 5; t = 6; print "test/test\t" (t_array[0] + t); }'
test/test	11

❯ frawk 'BEGIN { t_array[0] = 5; t = 6; print "test/test\t" (t_array[0] * t); }'
test/test	30

❯ frawk 'BEGIN { t_array[0] = 5; t = 6; print "test/test\t" (t_array[0] / t); }'
line 1, column 65. incomplete regex literal

In the original script if gave a different error:

Unrecognized EOF found at line 41, column 81
Expected one of "\n", "!=", "!~", "$", "%", "%=", "&&", "(", ")", "*", "*=", "+", "++", "+=", ",", "-", "--", "-=", "/", "/=", ":", ";", "<", "<=", "=", "==", ">", ">=", ">>", "?", "CALLSTART", "FLOAT", "HEX", "IDENT", "INT", "PATLIT", "STRLIT", "[", "]", "^", "^=", "in", "{", "|", "||", "}" or "~"

ezrosent added a commit that referenced this issue Mar 31, 2021
This fixes one of the examples brought up in #54
@ezrosent
Copy link
Owner

ezrosent commented Apr 3, 2021

Quick update here, I should have a fix for the division issue soon, but I think I'll have to do a larger rewrite of the parser to fix the first concatenation issue. At the very least, it's not a quick fix. I'll be sure fix #49 as well when I get around to that.

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