summaryrefslogtreecommitdiffstats
path: root/parsing/lexer.sh
diff options
context:
space:
mode:
Diffstat (limited to 'parsing/lexer.sh')
-rw-r--r--parsing/lexer.sh43
1 files changed, 32 insertions, 11 deletions
diff --git a/parsing/lexer.sh b/parsing/lexer.sh
index c939d1c..01bc721 100644
--- a/parsing/lexer.sh
+++ b/parsing/lexer.sh
@@ -82,6 +82,7 @@ next()
return
;;
esac
+ dbg T_SEMI
tok=T_SEMI
return
;;
@@ -457,23 +458,28 @@ accept()
local t="${1}"
local rw=
+ dbg "looking for $t, current tok ${tok%%${US}*}"
case "${t}" in
T_IF|T_THEN|T_ELSE|T_ELIF|T_FI|\
T_DO|T_DONE|T_CASE|T_ESAC|T_WHILE|T_UNTIL|\
T_FOR|T_LBRACE|T_RBRACE|T_BANG|T_IN)
dbg "looking for reserved word $t, have '$tok'"
- # Reserved words are recognized as literal T_WORDs.
- if ! [ "x${tok%%${US}*}" = 'xT_WORD' ]; then
- return 1
- fi
- # T_WORD data unit must match reserved word exactly.
- if ! [ "x${tok#T_WORD${US}}" = "x$(tokname "${t}")" ]
- then
- return 1
+ if ! [ "x${tok%%${US}*}" = "x${t}" ]; then
+ # Reserved words are recognized as literal
+ # T_WORDs.
+ if ! [ "x${tok%%${US}*}" = 'xT_WORD' ]; then
+ return 1
+ fi
+ # T_WORD data unit must match reserved word
+ # exactly.
+ if ! [ "x${tok#T_WORD${US}}" = \
+ "x$(tokname "${t}")" ]; then
+ return 1
+ fi
+ # If the token matches the reserved word,
+ # replace it with the reserved word token.
+ tok="${t}"
fi
- # If the token matches the reserved word, replace it
- # with the reserved word token.
- tok="${t}"
;;
T_NAME)
# Names are recognized as literal T_WORDs.
@@ -516,6 +522,21 @@ accept()
done
tok="T_FNAME${US}${tok#T_WORD${US}}"
;;
+ T_WORD)
+ if ! [ "x${tok%%${US}*}" = "x${t}" ]; then
+ return 1
+ fi
+ # Verify that the word doesn't match any reserved words.
+ for rw in T_IF T_THEN T_ELSE T_ELIF T_FI T_DO T_DONE \
+ T_CASE T_ESAC T_WHILE T_UNTIL T_FOR \
+ T_IN; do
+ if [ "x${tok#T_WORD${US}}" = \
+ "x$(tokname "${rw}")" ]; then
+ tok="${rw}"
+ return 1
+ fi
+ done
+ ;;
*)
if ! [ "x${tok%%${US}*}" = "x${t}" ]; then
return 1