Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trans :: Expression -> String
- trans = trans_E []
- trans_E :: Tab -> Expression -> String
- trans_E varDefs ex = case ex of
- Val valOfNum -> "top++; S[top] = " ++ (show valOfNum :: Int)
- Idf valName -> "top++; S[top] = L[" ++ (show (lookup valName varDefs)) ++ "];"
- Binary lhs op rhs -> case op of
- Plus -> (trans varDefs lhs) ++ (trans varDefs rhs) ++ "top--;S[top]=S[top]+S[top+1];"
- Minus -> (trans varDefs lhs) ++ (trans varDefs rhs) ++ "top--;S[top]=S[top]-S[top+1];"
- Times -> (trans varDefs lhs) ++ (trans varDefs rhs) ++ "top--;S[top]=S[top]*S[top+1];"
- Div -> (trans varDefs lhs) ++ (trans varDefs rhs) ++ "top--;S[top]=S[top]/S[top+1];"
- Let valName valExpr inExpr -> (trans varDefs valExpr) ++ "L["++(show (lookup valName varDefs))++"]=S[top]; top--,"++(trans (valName,(lookup valName varDefs)):varDefs inExpr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement