123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- syntax logoPlayer_syntax (logoPlayer_lexique) {
- rule <start_symbol> {
- # Routine definition
- $PROGRAM$
- @routineMap routineArray = {}
- @instructionList baseProgram = {}
- <routines> !? routineArray
- $BEGIN$
- <instructions> !? routineArray !? baseProgram
- $END$
- $.$
- # Code generation
- @bool penDown = false
- @double x = 0.0
- @double y = 0.0
- @double angle = 0.0 # Degrees
- @string svgLines = ""
- for i in baseProgram do
- [ i.mInstruction codeDisplay !?penDown !?x !?y !?angle !?svgLines ]
- end
- # File output
- let @string sourceFilePath = @string.stringWithSourceFilePath
- let @string code = [
- filewrapper generationTemplate.svg
- ![sourceFilePath lastPathComponent]
- !svgLines
- ]
- [code writeToFile ![sourceFilePath stringByDeletingPathExtension] + ".svg"]
- }
- rule <routines> ?! @routineMap routineArray {
- repeat
- while
- <routine> !? routineArray
- end
- }
- rule <routine> ?! @routineMap ioRoutineArray {
- $ROUTINE$
- $identifier$ ?let @lstring routineId
- @instructionList routineProgram = {}
- $BEGIN$
- <instructions> !? ioRoutineArray !? routineProgram
- $END$
- [ !? ioRoutineArray insertKey !routineId !routineProgram ]
- }
- rule <instructions> ?! @routineMap ioRoutineArray ?! @instructionList program {
- repeat
- while
- <instruction> !? ioRoutineArray !? program
- end
- }
- rule <instruction> ?! @routineMap ioRoutineArray ?! @instructionList program {
- select
- <move> !? program
- or
- <set_pen> !? program
- or
- <call_routine> !? ioRoutineArray !? program
- end
- $;$
- }
- rule <move> ?! @instructionList program {
- select
- <move_forward> !? program
- or
- <move_rotate> !? program
- end
- }
- rule <move_forward> ?! @instructionList program {
- $FORWARD$
- $integer$ ?let @luint moveLen
- @instruction move = @forward.new { !moveLen }
- program += !move
- }
- rule <move_rotate> ?! @instructionList program {
- $ROTATE$
- $integer$ ?let @luint moveAngle
- @instruction move = @rotate.new { !moveAngle }
- program += !move
- }
- rule <set_pen> ?! @instructionList program {
- $PEN$
- @instruction setPen
- select
- $UP$
- setPen = @penUp.new {}
- or
- $DOWN$
- setPen = @penDown.new {}
- end
- program += !setPen
- }
- rule <call_routine> ?! @routineMap ioRoutineArray ?! @instructionList program {
- $CALL$
- $identifier$ ?let @lstring routineId
- @instructionList routineProgram
- [ ioRoutineArray searchKey !routineId ?routineProgram ]
- program += routineProgram
- }
-
- }
|