我必须做一个软件来识别 C 中的令牌。我有这个代码:
*main = do
x <- readFile "progc.c"
let resultado = lexCmm X
print resultado
lexCmm :: String -> [Tok]
lexCmm X = case X of
c:cs | isSpace c -> lexCmm cs
c:cs | isAlpha c -> getId s
c:cs | isDigit c -> getInt s
c:d:cs | isSymb [c,d] -> TS [c,d] : lexCmm cs
c:cs | isSymb [c] -> TS [c] : lexCmm cs
_ -> []
where
getId s = lx i : lexCmm cs where (i,cs) = span isIdChar s
getInt s = TI (read i) : lexCmm cs where (i,cs) = span isDigit s
isIdChar c = isAlpha c || isDigit c
lx i = if isReservedWord i then TS i else TI i
isSymb s = elem s $ words "++ -- == <= >= ++ { } = , ; + * - ( ) < >"
isReservedWord w = elem w $ words "else if int main printInt return while"*
错误是:
file:{Hugs}\prog.hs:7 - Syntax error in input (unexpected `=')