Awk Technical Notes
20 days ago
- #Programming Languages
- #AWK
- #Syntax
- AWK was designed without a garbage collector, similar to sh/bash, making its implementation simple, fast, and portable.
- AWK does not allow returning arrays from functions due to deterministic heap allocation requirements, but arrays can be passed to functions and filled there.
- All variables in AWK are global by default, but function parameters are treated as local variables, similar to JavaScript.
- AWK supports associative arrays through autovivification, where arrays are declared implicitly by usage.
- The '$' operator in AWK is unary and can be used dynamically, allowing expressions like '$$$$1' for field access.
- AWK has specific syntax rules, such as no space before '(' in user-defined function calls, due to its string concatenation operator being an empty space.
- Built-in functions in AWK are part of the grammar, preventing users from naming variables or functions after them.
- AWK's syntax includes ad-hoc parsing challenges, such as distinguishing between regular expressions and division operators, requiring lexer hacks.
- Older programming languages like AWK, Perl, and shell have ad-hoc syntax for flexibility and human-like language features, contrasting with modern languages like Go that have more regular syntax.