Skip to content

awk does not support else statement with a single statement that does not end with ; or \n. #413

@ghuls

Description

@ghuls

Describe the bug

awk does not support else statement with a single statement that does not end with ; or \n. \n, ; and } (from optionally a higher level) should indicate the end of a statement.

To Reproduce
Steps to reproduce the behavior:

$ target/x86_64-unknown-linux-gnu/release/awk 'BEGIN { if (1 == 1) if (2==3) print "wrongtest"; else print "test" }'
 --> 1:68
  |
1 | BEGIN { if (1 == 1) if (2==3) print "wrongtest"; else print "test" }
  |                                                                    ^---
  |
  = expected string, ere, number, func_name, truncate, append, pipe, builtin_function_call, pre_inc, pre_dec, not, unary_plus, negate, post_inc, post_dec, pow, mul, div, modulus, add, binary_sub, match_op, not_match, and, or, in_op, or lvalue

# Adding ";" or "\n" after the single statement, parses without problem.
$ target/x86_64-unknown-linux-gnu/release/awk 'BEGIN { if (1 == 1) if (2==3) print "wrongtest"; else print "test"; }'
test

$ target/x86_64-unknown-linux-gnu/release/awk 'BEGIN { if (1 == 1) if (2==3) print "wrongtest"; else print "test"
}'
test

$ gawk 'BEGIN { if (1 == 1) if (2==3) print "wrongtest"; else print "test" }'
test

$ mawk 'BEGIN { if (1 == 1) if (2==3) print "wrongtest"; else print "test" }'
test

$ goawk 'BEGIN { if (1 == 1) if (2==3) print "wrongtest"; else print "test" }'
test

$ frawk 'BEGIN { if (1 == 1) if (2==3) print "wrongtest"; else print "test" }'
test

Expected behavior

Parse else statement without ; and \n properly.

Operaing system (OS) info:

  • Rocky Linux 8.9
  • Version posixutils-awk 0.2.2: commit 72788d8

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions