我正在Haskell中编写一个编译器,因此我们对s和构造函数有很多 (或者至少对我来说似乎很重要)data,例如:
data DataType
= Int | Float | Bool | Char | Range | Type
| String Width
| Record (Lexeme Identifier) (Seq Field) Width
| Union (Lexeme Identifier) (Seq Field) Width
| Array (Lexeme DataType) (Lexeme Expression) Width
| UserDef (Lexeme Identifier)
| Void | TypeError -- For compiler use
data Statement
-- Language
= StNoop
| StAssign (Lexeme Access) (Lexeme Expression)
-- Definitions
| StDeclaration (Lexeme Declaration)
| StDeclarationList (DeclarationList Expression)
| StStructDefinition (Lexeme …Run Code Online (Sandbox Code Playgroud) 我正在 Haskell 中实现一个编译器,将源语言编译为目标语言(类似汇编)。
出于调试目的,需要源映射将目标语言汇编指令映射到其相应的源位置(行和列)。
我已经广泛搜索了编译器实现,但没有一个包含源映射。
谁能指出我如何生成源地图的正确方向?
代码示例、书籍等。Haskell 优先,其他语言也欢迎。