syntax logoPlayer_syntax (logoPlayer_lexique) { rule { # Routine definition $PROGRAM$ @routineMap routineArray = {} @instructionList baseProgram = {} !? routineArray $BEGIN$ !? 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 ?! @routineMap routineArray { repeat while !? routineArray end } rule ?! @routineMap ioRoutineArray { $ROUTINE$ $identifier$ ?let @lstring routineId @instructionList routineProgram = {} $BEGIN$ !? ioRoutineArray !? routineProgram $END$ [ !? ioRoutineArray insertKey !routineId !routineProgram ] } rule ?! @routineMap ioRoutineArray ?! @instructionList program { repeat while !? ioRoutineArray !? program end } rule ?! @routineMap ioRoutineArray ?! @instructionList program { select !? program or !? program or !? ioRoutineArray !? program end $;$ } rule ?! @instructionList program { select !? program or !? program end } rule ?! @instructionList program { $FORWARD$ $integer$ ?let @luint moveLen @instruction move = @forward.new { !moveLen } program += !move } rule ?! @instructionList program { $ROTATE$ $integer$ ?let @luint moveAngle @instruction move = @rotate.new { !moveAngle } program += !move } rule ?! @instructionList program { $PEN$ @instruction setPen select $UP$ setPen = @penUp.new {} or $DOWN$ setPen = @penDown.new {} end program += !setPen } rule ?! @routineMap ioRoutineArray ?! @instructionList program { $CALL$ $identifier$ ?let @lstring routineId @instructionList routineProgram [ ioRoutineArray searchKey !routineId ?routineProgram ] program += routineProgram } }