logoPlayer-syntax.galgas 2.0 KB

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