From 6a6c376a64c14d820298671481ceaf5dcaaac4a6 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Fri, 19 Feb 2016 18:28:09 -0500 Subject: Recognize reserved words --- (limited to 'parsing') diff --git a/parsing/lexer.sh b/parsing/lexer.sh index bf6ad7d..f92534a 100644 --- a/parsing/lexer.sh +++ b/parsing/lexer.sh @@ -456,13 +456,34 @@ accept() { local t="${1}" - if [ "x${tok%%${US}*}" = "x${t}" ]; then - dbg "accept $t" - tokens="${tokens}${tok}${RS}" - next - return 0 - fi - return 1 + 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) + # Reserved words are recognized as literal T_WORDs. + if ! [ "x${tok%%${US}*}" = T_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}" + ;; + *) + if ! [ "x${tok%%${US}*}" = "x${t}" ]; then + return 1 + fi + ;; + esac + + dbg "accept $t" + tokens="${tokens}${tok}${RS}" + next + return 0 } expect() -- cgit v0.9.1