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
這個還真是不好琢磨呀。