From db77a97119b4f8a8a5df5228774b181d4ebe7990 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 11 Mar 2020 07:46:39 +0000 Subject: [PATCH] updated README.md a bit --- hawk/README.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/hawk/README.md b/hawk/README.md index d30af734..ddff0179 100644 --- a/hawk/README.md +++ b/hawk/README.md @@ -141,10 +141,27 @@ The typical execution begins with the BEGIN block, goes through pattern-action b - string - byte string - array +- function +- regular expression + +To know the current type of a value, call typename(). + + function f() { return 10; } + BEGIN { + a="hello"; + b=12345; + print typename(a), typename(b), typename(c), typename(f), typename(1.23), typename(B"world"); + } + +A regular expression literal is special in that it never appears as an indendent value and still entails a match operation against $0 without an match operator. + + BEGIN { $0="ab"; print /ab/, typename(/ab/); } + +For this reason, there is no way to get the type name of a regular expressin literal. ### Pragmas -A program item of the file scope can be placed in any source files. +A pragma item of the file scope can be placed in any source files. A pragma item of the global scope can appear only once thoughout the all source files. | | Scope | Values | Description | @@ -180,6 +197,16 @@ Alternatively, you may form an array before passing it to a function. BEGIN { x[3]=99; q(x); for (i in x) print i, x[i]; }' +### Positional variable expression + +There are subtle differences when you put an expression for a position variable. In Hawk, most of the ambiguity issues are resolved if you enclose the expression inside parentheses. + +| | HAWK | AWK | +|--------------|---------------|-----------------| +| $++$++i | syntax error | OK | +| $(++$(++i)) | OK | syntax error | + + ## Basic Modules ### sys