logoPlayer-syntax.galgas 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. syntax logoPlayer_syntax (logoPlayer_lexique) {
  2. rule <start_symbol> {
  3. # Routine definition
  4. $PROGRAM$
  5. @routineMap routineArray = {}
  6. <routines> !? routineArray
  7. $BEGIN$
  8. <instructions> !? routineArray
  9. $END$
  10. $.$
  11. }
  12. rule <routines> ?! @routineMap routineArray {
  13. repeat
  14. while
  15. <routine> !? routineArray
  16. end
  17. }
  18. rule <routine> ?! @routineMap ioRoutineArray {
  19. $ROUTINE$
  20. $identifier$ ?let @lstring routineId
  21. $BEGIN$
  22. <instructions> !? ioRoutineArray
  23. $END$
  24. [ !? ioRoutineArray insertKey !routineId ]
  25. }
  26. rule <instructions> ?! @routineMap ioRoutineArray {
  27. repeat
  28. while
  29. <instruction> !? ioRoutineArray
  30. end
  31. }
  32. rule <instruction> ?! @routineMap ioRoutineArray {
  33. select
  34. <move>
  35. or
  36. <set_pen>
  37. or
  38. <call_routine> !? ioRoutineArray
  39. end
  40. $;$
  41. }
  42. rule <move> {
  43. select
  44. <move_forward>
  45. or
  46. <move_rotate>
  47. end
  48. }
  49. rule <move_forward> {
  50. $FORWARD$
  51. $integer$ ?let @luint moveLen
  52. @instruction move = @forward.new { !moveLen }
  53. }
  54. rule <move_rotate> {
  55. $ROTATE$
  56. $integer$ ?let @luint moveAngle
  57. @instruction move = @rotate.new { !moveAngle }
  58. }
  59. rule <set_pen> {
  60. $PEN$
  61. select
  62. $UP$
  63. @instruction setPen = @penUp.new {}
  64. or
  65. $DOWN$
  66. @instruction setPen = @penDown.new {}
  67. end
  68. }
  69. rule <call_routine> ?! @routineMap ioRoutineArray {
  70. $CALL$
  71. $identifier$ ?let @lstring routineId
  72. [ ioRoutineArray searchKey !routineId ]
  73. }
  74. }