logoPlayer-syntax.galgas 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. for i in baseProgram do
  18. [ i.mInstruction codeDisplay !?penDown !?x !?y !?angle ]
  19. end
  20. }
  21. rule <routines> ?! @routineMap routineArray {
  22. repeat
  23. while
  24. <routine> !? routineArray
  25. end
  26. }
  27. rule <routine> ?! @routineMap ioRoutineArray {
  28. $ROUTINE$
  29. $identifier$ ?let @lstring routineId
  30. @instructionList routineProgram = {}
  31. $BEGIN$
  32. <instructions> !? ioRoutineArray !? routineProgram
  33. $END$
  34. [ !? ioRoutineArray insertKey !routineId !routineProgram ]
  35. }
  36. rule <instructions> ?! @routineMap ioRoutineArray ?! @instructionList program {
  37. repeat
  38. while
  39. <instruction> !? ioRoutineArray !? program
  40. end
  41. }
  42. rule <instruction> ?! @routineMap ioRoutineArray ?! @instructionList program {
  43. select
  44. <move> !? program
  45. or
  46. <set_pen> !? program
  47. or
  48. <call_routine> !? ioRoutineArray !? program
  49. end
  50. $;$
  51. }
  52. rule <move> ?! @instructionList program {
  53. select
  54. <move_forward> !? program
  55. or
  56. <move_rotate> !? program
  57. end
  58. }
  59. rule <move_forward> ?! @instructionList program {
  60. $FORWARD$
  61. $integer$ ?let @luint moveLen
  62. @instruction move = @forward.new { !moveLen }
  63. program += !move
  64. }
  65. rule <move_rotate> ?! @instructionList program {
  66. $ROTATE$
  67. $integer$ ?let @luint moveAngle
  68. @instruction move = @rotate.new { !moveAngle }
  69. program += !move
  70. }
  71. rule <set_pen> ?! @instructionList program {
  72. $PEN$
  73. @instruction setPen
  74. select
  75. $UP$
  76. setPen = @penUp.new {}
  77. or
  78. $DOWN$
  79. setPen = @penDown.new {}
  80. end
  81. program += !setPen
  82. }
  83. rule <call_routine> ?! @routineMap ioRoutineArray ?! @instructionList program {
  84. $CALL$
  85. $identifier$ ?let @lstring routineId
  86. @instructionList routineProgram
  87. [ ioRoutineArray searchKey !routineId ?routineProgram ]
  88. program += routineProgram
  89. }
  90. }