I basically modify the parser to handle additional statements. Before my changes, one part of the analyzer looked like this:
parseExpRec e1 (op : ts) = let (e2, ts') = parsePrimExp ts in case op of T_Plus -> parseExpRec (BinOpApp Plus e1 e2) ts' T_Minus -> parseExpRec (BinOpApp Minus e1 e2) ts' T_Times -> parseExpRec (BinOpApp Times e1 e2) ts' T_Divide -> parseExpRec (BinOpApp Divide e1 e2) ts' _ -> (e1, op : ts)
T_Plus, etc. are members of the data type Token, and Plus, Minus, etc. are part of BinOp, which BinOpApp applies to two operands. I updated the Token and BinOpApp data types to handle Power token (exponentiation). This is the resulting code:
parseExpRec e1 (op : ts) = let (e2, ts') = parsePrimExp ts in case op of T_Plus -> parseExpRec (BinOpApp Plus e1 e2) ts' T_Minus -> parseExpRec (BinOpApp Minus e1 e2) ts' T_Times -> parseExpRec (BinOpApp Times e1 e2) ts' T_Divide -> parseExpRec (BinOpApp Divide e1 e2) ts' T_Power -> parseExpRec (BinOpApp Power e1 e2) ts' _ -> (e1, op : ts)
It seems simple, but now it gives the following error:
TXL.hs: 182: 13: parsing error at input '->'
Line 182 is the line in which I added "T_Power β parseExpRec ..." - I donβt see how it differs from other lines that are perfectly parsed. I use GHCi as a medium.
source share