Skip to content

Commit

Permalink
校正
Browse files Browse the repository at this point in the history
  • Loading branch information
Seasawher committed Dec 13, 2024
1 parent d59120f commit e59ab20
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
4 changes: 1 addition & 3 deletions Monkey/Ast/Ast.lean
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@ inductive Statement where

deriving Repr, DecidableEq

/-- Statement を文字列に変換する -/
def Statement.toString (stmt: Statement) : String :=
private def Statement.toString (stmt: Statement) : String :=
match stmt with
| .letStmt name value => s!"let {name} = {value}"
| .returnStmt returnValue => s!"return {returnValue}"
| .exprStmt expr => s!"{expr}"
| .notImplemented => "notImplemented"

/-- Repr インスタンスから ToString インスタンスを生成する -/
instance : ToString Statement where
toString s := s.toString

Expand Down
2 changes: 1 addition & 1 deletion Monkey/Lexer/Lexer.lean
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def nextToken : StateM Lexer Token := do
| _ => ILLEGAL
if l.ch.isLetter then
let literal ← readIdentifier
let token := LookupIdent literal
let token := lookupIdent literal
return token
else if l.ch.isDigit then
let literal ← readNumber
Expand Down
8 changes: 4 additions & 4 deletions Monkey/Token/Token.lean
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ def Token.sameType (t1 t2 : Token) : Bool :=
/-- `ILLEGAL` を初期値にする -/
instance : Inhabited Token := ⟨Token.ILLEGAL⟩

/-- Token を文字列に変換する -/
def Token.toString (t : Token) : String :=
private def Token.toString (t : Token) : String :=
match t with
| .ILLEGAL => "ILLEGAL"
| .EOF => "EOF"
Expand Down Expand Up @@ -121,8 +120,9 @@ def keywords : Std.HashMap String Token :=
]
Std.HashMap.ofList list

/-- ユーザ定義の識別子なのか、言語のキーワードなのか分類する -/
def LookupIdent (ident : String) : Token :=
/-- 文字列をトークンに変換する。
その過程でユーザ定義の識別子なのか、言語のキーワードなのか見分ける作業を行う。-/
def lookupIdent (ident : String) : Token :=
match keywords[ident]? with
| some tok => tok
| none => IDENT ident

0 comments on commit e59ab20

Please sign in to comment.