Réponse au prompt “Génère un diagramme de classe UML (format plantuml) de ce code.”

codex

26 mai 2026

Voici un diagramme de classes PlantUML pour la partie principale du projet :

@startuml
skinparam classAttributeIconSize 0

package logo {
  enum TokenType {
    TokenSign
    TokenNumber
    TokenName
    TokenKeyword
  }

  enum GetNextReason {
    FinishedInstruction
    BackFromSubroutine
  }

  class TokenList
  class Token

  abstract class Instruction {
    +~Instruction()
    +execute(interpreter: Interpreter&) : void
    +getNext(interpreter: Interpreter&, reason: GetNextReason) : InstructionPointer
    +display(os: ostream&) : void
    -doExecute(interpreter: Interpreter&) : void
    -doGetNext(interpreter: Interpreter&, reason: GetNextReason) : InstructionPointer
    -doDisplay(os: ostream&) : void
  }

  class UnaryInstruction {
    #myParameter : int
    +UnaryInstruction(tokens: TokenList&, currentPos: iterator&)
  }

  class Move {
    -isForward : bool
    +Move(tokens: TokenList&, currentPos: iterator&, forward: bool)
    -doExecute(interpreter: Interpreter&) : void
    -doDisplay(os: ostream&) : void
  }

  class Turn {
    -isClockwise : bool
    +Turn(tokens: TokenList&, currentPos: iterator&, clockwise: bool)
    -doExecute(interpreter: Interpreter&) : void
    -doDisplay(os: ostream&) : void
  }

  class SetPenPos {
    -isUp : bool
    +SetPenPos(tokens: TokenList&, currentPos: iterator&, up: bool)
    -doExecute(interpreter: Interpreter&) : void
    -doDisplay(os: ostream&) : void
  }

  class FunctionCall {
    -myMainProgram : Program&
    -myName : string
    +FunctionCall(mainProgram: Program&, name: string, currentPos: iterator&)
    -doExecute(interpreter: Interpreter&) : void
    -doGetNext(interpreter: Interpreter&, reason: GetNextReason) : InstructionPointer
    -doDisplay(os: ostream&) : void
  }

  class Program {
    -myInstructions : InstructionList
    -myFunctions : map<string, unique_ptr<Program>>
    -isMainProgram : bool
    +Program(tokens: TokenList&, currentToken: iterator&, mainProgram: Program*)
    +~Program()
    +display(os: ostream&, subFunctions: bool) : void
    +begin() : InstructionPointer
    +end() : InstructionPointer
    +findSubProgram(name: string) : Program*
    -parseKeyword(tokens: TokenList&, token: iterator&, endProgram: bool&, mainProgram: Program*) : void
  }

  class Interpreter {
    -myCompilationMessage : string
    -myProgram : unique_ptr<Program>
    -myCallStack : vector<ExecutionContext>
    +Interpreter(code: string&)
    +Interpreter(is: istream&)
    +~Interpreter()
    +isProgramValid() : bool
    +compilationMessage() : string
    +startProgram() : void
    +nextStep() : void
    +isProgramRunning() : bool
    +pushNewContext(ec: ExecutionContext&&) : void
    +currentInstruction() : Instruction*
    +currentPos() : InstructionPointer
    +endOfBlock() : InstructionPointer
    +showTrace(os: ostream&) : void
    +display(os: ostream&) : void
    -parse(code: string&) : void
  }

  class ExecutionContext {
    -myInterpreter : Interpreter&
    -myCurrentPos : InstructionPointer
    -myEndOfBlock : InstructionPointer
    -myVariables : map<string, int>
    +ExecutionContext(startingPos: InstructionPointer, endOfBlock: InstructionPointer, interpreter: Interpreter&)
    +variable(name: string&) : int&
    +currentPos() : InstructionPointer
    +endOfBlock() : InstructionPointer
    +setCurrentPos(pos: InstructionPointer) : void
  }

  class ParseError {
    -myErrorPos : TokenList::const_iterator
    +ParseError(whatString: string&, errorPos: iterator)
    +errorPos() : iterator
  }

  Instruction <|-- UnaryInstruction
  UnaryInstruction <|-- Move
  UnaryInstruction <|-- Turn
  Instruction <|-- SetPenPos
  Instruction <|-- FunctionCall

  Program *-- "0..*" Instruction : myInstructions
  Program *-- "0..*" Program : myFunctions
  Interpreter *-- "1" Program : myProgram
  Interpreter *-- "0..*" ExecutionContext : myCallStack
  ExecutionContext --> Interpreter
  FunctionCall --> Program : main program
  ParseError --|> runtime_error
}

package turtle {
  class TurtleState <<namespace>> {
    +turtleX : double
    +turtleY : double
    +turtleDir : double
    +turtlePenDown : bool
    +turtleColor : unsigned char*
    +initTurtle() : void
    +uninitTurtle() : void
    +redraw() : void
    +rest(s: float) : void
    +interrupt() : bool
    +waitEnd() : void
    +drawLine(x1: double, y1: double, x2: double, y2: double, color: unsigned char*) : void
  }
}

Move ..> TurtleState : modifie position / dessine
Turn ..> TurtleState : modifie direction
SetPenPos ..> TurtleState : modifie stylo
@enduml