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

bc: define is broken #172

Open
briandfoy opened this issue Jun 21, 2023 · 1 comment
Open

bc: define is broken #172

briandfoy opened this issue Jun 21, 2023 · 1 comment
Labels
Priority: low get to this whenever Program: bc The bc program Type: bug an existing feature does not work Type: testing testing, that is not an existing test bug

Comments

@briandfoy
Copy link
Owner

No description provided.

@briandfoy briandfoy added Type: bug an existing feature does not work Priority: low get to this whenever Program: bc The bc program Type: testing testing, that is not an existing test bug labels Jun 21, 2023
@mknos
Copy link
Contributor

mknos commented Oct 14, 2023

  • "define" indicates a function declaration
  • When I declare a trivial function adding 1 to the input param, bc will only accept the syntax if the return expression is wrapped in parens
  • Every single return statement in the bc math library appears to wrap the expression in parens
  • Possibly the parens are required by the standard bc language[1]
  • GNU bc and OpenBSD bc allow return_expression without parens
  • Maybe this can only be fixed in the perl bc by generating a new parser from the yacc file of modern version of bc
$ cat fun.bc 
define yo(x)
{
 return (x + 1);
}
yo(1)
$ perl bc < fun.bc
2
$ cat fun2.bc
define yo(x)
{
 return x + 1;
}
yo(1)
$ perl bc < fun2.bc
line 3: syntax error
line 4: syntax error
No function yo() has been defined
  1. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html -- Return | Return '(' return_expression ')'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: low get to this whenever Program: bc The bc program Type: bug an existing feature does not work Type: testing testing, that is not an existing test bug
Projects
None yet
Development

No branches or pull requests

2 participants