logoPlayer-syntax.galgas 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. syntax logoPlayer_syntax (logoPlayer_lexique) {
  2. rule <start_symbol> {
  3. # Routine definition
  4. $PROGRAM$
  5. @routineMap routineArray = {}
  6. @instructionList baseProgram = {}
  7. <routines> !? routineArray
  8. $BEGIN$
  9. <instructions> !? routineArray !? baseProgram
  10. $END$
  11. $.$
  12. # Code generation
  13. @bool penDown = false
  14. @double x = 0.0
  15. @double y = 0.0
  16. @double angle = 0.0 # Degrees
  17. @string svgLines = ""
  18. for i in baseProgram do
  19. [ i.mInstruction codeDisplay !?penDown !?x !?y !?angle !?svgLines ]
  20. end
  21. # File output
  22. let @string sourceFilePath = @string.stringWithSourceFilePath
  23. let @string code = [
  24. filewrapper generationTemplate.svg
  25. ![sourceFilePath lastPathComponent]
  26. !svgLines
  27. ]
  28. [code writeToFile ![sourceFilePath stringByDeletingPathExtension] + ".svg"]
  29. }
  30. rule <routines> ?! @routineMap routineArray {
  31. repeat
  32. while
  33. <routine> !? routineArray
  34. end
  35. }
  36. rule <routine> ?! @routineMap ioRoutineArray {
  37. $ROUTINE$
  38. $identifier$ ?let @lstring routineId
  39. @instructionList routineProgram = {}
  40. $BEGIN$
  41. <instructions> !? ioRoutineArray !? routineProgram
  42. $END$
  43. [ !? ioRoutineArray insertKey !routineId !routineProgram ]
  44. }
  45. rule <instructions> ?! @routineMap ioRoutineArray ?! @instructionList program {
  46. repeat
  47. while
  48. <instruction> !? ioRoutineArray !? program
  49. end
  50. }
  51. rule <instruction> ?! @routineMap ioRoutineArray ?! @instructionList program {
  52. select
  53. <move> !? program
  54. or
  55. <set_pen> !? program
  56. or
  57. <call_routine> !? ioRoutineArray !? program
  58. end
  59. $;$
  60. }
  61. rule <move> ?! @instructionList program {
  62. select
  63. <move_forward> !? program
  64. or
  65. <move_rotate> !? program
  66. end
  67. }
  68. rule <move_forward> ?! @instructionList program {
  69. $FORWARD$
  70. $integer$ ?let @luint moveLen
  71. @instruction move = @forward.new { !moveLen }
  72. program += !move
  73. }
  74. rule <move_rotate> ?! @instructionList program {
  75. $ROTATE$
  76. $integer$ ?let @luint moveAngle
  77. @instruction move = @rotate.new { !moveAngle }
  78. program += !move
  79. }
  80. rule <set_pen> ?! @instructionList program {
  81. $PEN$
  82. @instruction setPen
  83. select
  84. $UP$
  85. setPen = @penUp.new {}
  86. or
  87. $DOWN$
  88. setPen = @penDown.new {}
  89. end
  90. program += !setPen
  91. }
  92. rule <call_routine> ?! @routineMap ioRoutineArray ?! @instructionList program {
  93. $CALL$
  94. $identifier$ ?let @lstring routineId
  95. @instructionList routineProgram
  96. [ ioRoutineArray searchKey !routineId ?routineProgram ]
  97. program += routineProgram
  98. }
  99. }