gawk1.01源码分析awk.y冲突了
yang@DESKTOP-V9HS3B6:~/gawk101/gawk$ echo "hello:ok" | ./gawk 'BEGIN { FS=":"}
> {print $1,$2}'
hello ok
看到没,单独是可以执行的。
但把awk指令写到文件中,再测试一下,其中t.awk内容如下:
yang@DESKTOP-V9HS3B6:~/gawk101/gawk$ cat t.awk
BEGIN {
FS=":"
}
{print $1,$2}
可执行时,报错了。
yang@DESKTOP-V9HS3B6:~/gawk101/gawk$ echo "hello:ok" |./gawk -f t.awk
Ambiguity detected.
Option 1,
whitespace -> <Rule 30, tokens 3 .. 3>
whitespace -> <Rule 26, empty>
NEWLINE <tokens 3 .. 3>
Option 2,
whitespace -> <Rule 28, tokens 3 .. 3>
NEWLINE <tokens 3 .. 3>
Error near line 2, ' FS=":"'
syntax is ambiguous
真是麻烦。
稍微修改一下文件,如下:
yang@DESKTOP-V9HS3B6:~/gawk101/gawk$ cat t.awk
BEGIN {FS=":" }
{print $1,$2}
再执行时,错误又变了。
yang@DESKTOP-V9HS3B6:~/gawk101/gawk$ echo "hello:ok" |./gawk -f t.awk
Ambiguity detected.
Option 1,
program -> <Rule 3, tokens 1 .. 19>
program -> <Rule 3, tokens 1 .. 18>
program <tokens 1 .. 8>
rule -> <Rule 4, tokens 9 .. 18>
pattern <empty>
action <tokens 9 .. 17>
NEWLINE <tokens 18 .. 18>
optional_newlines <empty>
rule -> <Rule 4, tokens 19 .. 19>
pattern -> <Rule 5, empty>
action -> <Rule 20, empty>
NEWLINE <tokens 19 .. 19>
optional_newlines -> <Rule 51, empty>
Option 2,
program -> <Rule 3, tokens 1 .. 19>
program <tokens 1 .. 8>
rule -> <Rule 4, tokens 9 .. 19>
pattern <empty>
action <tokens 9 .. 17>
NEWLINE <tokens 18 .. 18>
optional_newlines -> <Rule 52, tokens 19 .. 19>
optional_newlines <empty>
NEWLINE <tokens 19 .. 19>
Error near line 3, '(END OF FILE)'
syntax is ambiguous
这个还真是不好琢磨呀。