소스 검색

Compile instructions to terminal messages

DricomDragon 5 년 전
부모
커밋
118a5244c5
2개의 변경된 파일57개의 추가작업 그리고 0개의 파일을 삭제
  1. 48 0
      logoPlayer/galgas-sources/logoPlayer-semantics.galgas
  2. 9 0
      logoPlayer/galgas-sources/logoPlayer-syntax.galgas

+ 48 - 0
logoPlayer/galgas-sources/logoPlayer-semantics.galgas

@@ -26,3 +26,51 @@ class @rotate : @instruction {
     @luint mAngle
 }
 
+abstract method @instruction codeDisplay
+    ?! @bool ioPenDown
+    ?! @double ioX
+    ?! @double ioY
+    ?! @double ioAngle
+
+override method @penUp codeDisplay
+    ?! @bool ioPenDown
+    ?! @double unused ioX
+    ?! @double unused ioY
+    ?! @double unused ioAngle
+{
+    ioPenDown = false
+}
+    
+override method @penDown codeDisplay
+    ?! @bool ioPenDown
+    ?! @double unused ioX
+    ?! @double unused ioY
+    ?! @double unused ioAngle
+{
+    ioPenDown = true
+}
+
+override method @rotate codeDisplay
+    ?! @bool unused ioPenDown
+    ?! @double unused ioX
+    ?! @double unused ioY
+    ?! @double ioAngle
+{
+    ioAngle = ioAngle + [[mAngle uint] double]
+}
+    
+override method @forward codeDisplay
+    ?! @bool ioPenDown
+    ?! @double ioX
+    ?! @double ioY
+    ?! @double ioAngle
+{
+    let @double x = ioX + [mLength double] * [ioAngle cosDegree]
+    let @double y = ioY + [mLength double] * [ioAngle sinDegree]
+    if ioPenDown then
+        message "[" + ioX + ", " + ioY + "] -> ["+ x + ", " + y + "]\n"
+    end
+    ioX = x
+    ioY = y
+}
+

+ 9 - 0
logoPlayer/galgas-sources/logoPlayer-syntax.galgas

@@ -13,6 +13,15 @@ syntax logoPlayer_syntax (logoPlayer_lexique) {
     <instructions> !? routineArray !? baseProgram
     $END$
     $.$
+
+    # Code generation
+    @bool penDown = false
+    @double x = 0.0
+    @double y = 0.0
+    @double angle = 0.0 # Degrees
+    for i in baseProgram do
+        [ i.mInstruction codeDisplay !?penDown !?x !?y !?angle ]
+    end
   }
 
   rule <routines> ?! @routineMap routineArray {