diff --git a/Makefile b/Makefile index 4560a42..ac4d0e0 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ all: - mkdir -p target - scalac -d target src/stasiak/karol/fimpp/* - cd target && jar cfe ../bin/fimpp.jar stasiak.karol.fimpp.Main stasiak + #mkdir -p target + scalac -d bin/fimpp.jar src/stasiak/karol/fimpp/* + #cd target && fastjar -cvf ../bin/fimpp.jar stasiak/karol/fimpp/ -clean: - rm -r target +#clean: +# rm -r target diff --git a/bin/fimpp b/bin/fimpp index 1aad73c..369a249 100755 --- a/bin/fimpp +++ b/bin/fimpp @@ -1,3 +1,3 @@ #!/bin/bash DIR=`dirname "$0"` -java -cp "$DIR/scala-library.jar:$DIR/fimpp.jar" stasiak.karol.fimpp.Main "$@" +java -cp "$DIR/scala-library.jar:$DIR/fimpp.jar:$DIR/scala-parser-combinators.jar" stasiak.karol.fimpp.Mane "$@" diff --git a/bin/fimpp.bat b/bin/fimpp.bat index 4f87008..10b2a30 100644 --- a/bin/fimpp.bat +++ b/bin/fimpp.bat @@ -1 +1 @@ -java -cp "%~dp0\scala-library.jar;%~dp0\fimpp.jar" stasiak.karol.fimpp.Main "%1" +java -cp "%~dp0\scala-library.jar;%~dp0\fimpp.jar" stasiak.karol.fimpp.Mane "%1" diff --git a/bin/scala-library.jar b/bin/scala-library.jar index a871b3e..016b228 100644 Binary files a/bin/scala-library.jar and b/bin/scala-library.jar differ diff --git a/bin/scala-parser-combinators.jar b/bin/scala-parser-combinators.jar new file mode 100644 index 0000000..d75bc7d Binary files /dev/null and b/bin/scala-parser-combinators.jar differ diff --git a/examples/factorials.fimpp b/examples/factorials.fimpp new file mode 100644 index 0000000..0fb177f --- /dev/null +++ b/examples/factorials.fimpp @@ -0,0 +1,20 @@ +Dear Princess Celestia: Letter about Factorials. + +I learned about the factorial with Spike: + By the way, this function will return a factorial of Spike's number. + + Did you know that Sweetie Belle likes Spike? + I did this while Spike had more than the number one: + Spike got one fewer. + Sweetie Belle did the product of Sweetie Belle and Spike! + That's what I did. +That's about the factorial with Sweetie Belle! + +Today I learned: + Did you know that Rarity likes the number one? + I did this 20 times: + Twilight Sparkle did the factorial of Rarity. + I wrote: Twilight Sparkle! + Rarity got one more. + That's what I did! +Your faithful student, Jared MF. \ No newline at end of file diff --git a/examples/fourth_power.fimpp b/examples/fourth_power.fimpp new file mode 100644 index 0000000..8d9bc7a --- /dev/null +++ b/examples/fourth_power.fimpp @@ -0,0 +1,22 @@ +Dear Princess Celestia: Letter about the Fourth Power. + +I learned about the fourth power with Twilight Sparkle: + Did you know Flash Sentry likes Twilight Sparkle? + Flash Sentry did the product of Twilight Sparkle and Flash Sentry! + Spike did the product of Twilight Sparkle and Flash Sentry! + Princess Luna did the product of Twilight Sparkle and Spike! + + Did you know Twilight Sparkle likes the number zero? + Did you know Flash Sentry likes Twilight Sparkle? + Did you know Spike likes Twilight Sparkle? +That's about the fourth power with Princess Luna. + +Today I learned: + Did you know Applejack likes the number two? + + I did this 20 times: + Pinkie Pie did the fourth power of Applejack. + I wrote: Pinkie Pie! + Applejack got one more. + That's what I did! +Your faithful student, Jared MF. \ No newline at end of file diff --git a/examples/multiples.fimpp b/examples/multiples.fimpp new file mode 100644 index 0000000..bf56f6a --- /dev/null +++ b/examples/multiples.fimpp @@ -0,0 +1,34 @@ +Dear Princess Celestia: Letter about Multiples. + +I learned about multiples with Princess Luna: + Did you know Rarity likes the number one? + Did you know Spike likes Rarity? + Did you know Twilight Sparkle likes Spike? + + Spike got one more, because he is Twilight Sparkle's sidekick. + Twilight Sparkle got two more, because she is the leader of the Mane 6. + + Did you know Discord likes Rarity, Spike, and Twilight Sparkle? + Discord made the dictionary of Discord! + + I did this while Princess Luna was not equal to 0: + I wrote: Discord! + On the first page of Discord I read about Rarity. + Rarity got one more. + On the first page of Discord I wrote what I knew about Rarity. + + On the second page of Discord I read about Spike. + Spike got two more, because he is Twilight Sparkle's sidekick. + On the second page of Discord I wrote what I knew about Spike. + + On the third page of Discord I read about Twilight Sparkle. + Twilight Sparkle got three more, because she is the leader of the Mane 6. + On the third page of Discord I wrote what I knew about Twilight Sparkle. + + Princess Luna got one fewer. + That's what I did! +That's about multiples. + +Today I learned how this works: + I made multiples of 200! +Your faithful student, Jared MF. \ No newline at end of file diff --git a/examples/odd_even.fimpp b/examples/odd_even.fimpp new file mode 100644 index 0000000..f1b5828 --- /dev/null +++ b/examples/odd_even.fimpp @@ -0,0 +1,72 @@ +Dear Princess Celestia: Against All Odds and Evens: + +I learned about sorting odds with Twilight Sparkle: + By the way, this function checks for all the odd numbers, such as 1, 3, and 5. + + Did you know Rarity likes the number one? + Did you know Spike likes Rarity? + I found a book titled Sweetie Belle today, because she will hold the odd numbers. + + On the first page of Twilight Sparkle I read about Tom Dan, because he might hold the current odd number. + On the first page of Sweetie Belle I noted about Tom Dan, because that's where the odd numbers go. + Rarity got two more. Spike got one more. + On the page numbered by Rarity of Twilight Sparkle I read about Tom Dan. + I did this while Tom Dan was something: + On the page numbered by Spike of Sweetie Belle I noted about Tom Dan. + Rarity got two more. Spike got one more. + On the page numbered by Rarity of Twilight Sparkle I read about Tom Dan. + That's what I did! +That's about sorting odds with Sweetie Belle. + +I learned about sorting evens with Fluttershy: + By the way, this function checks for all the even numbers, such as 2, 4, and 6. + + Did you know Rainbow Dash likes the number one? + Did you know Scootaloo likes Rainbow Dash? + Rainbow Dash got one more. + I found a book titled Spitfire today, because she will hold the even numbers. + + On the second page of Fluttershy I read about Tank, because he might hold the current even number. + On the first page of Spitfire I noted about Tank, because that's where the even numbers go. + Rainbow Dash got two more. Scootaloo got one more. + On the page numbered by Rainbow Dash of Fluttershy I read about Tank. + I did this while Tank was something: + On the page numbered by Scootaloo of Spitfire I noted about Tank. + Rainbow Dash got two more. Scootaloo got one more. + On the page numbered by Rainbow Dash of Fluttershy I read about Tank. + That's what I did! +That's about sorting evens with Spitfire. + +I learned about viewing numbers with Applejack. + By the way, this function checks for all the numbers instead of nothing. + + Did you know Pinkie Pie likes the number one? + I found a book titled Apple Bloom today, because she will hold ALL of Appljack's numbers, and she is her sister. + + On the first page of Applejack I read about Big Mac, because he will hold the current number. + On the first page of Apple Bloom I noted about Big Mac, because of what I already mentioned about Apple Bloom! + Pinkie Pie got one more. + On the page numbered by Pinkie Pie of Applejack I read about Big Mac. + I did this while Big Mac was somepony: + On the page numbered by Pinkie Pie of Apple Bloom I noted about Big Mac. + Pinkie Pie got one more. + On the page numbered by Pinkie Pie of Applejack I read about Big Mac. + That's what I did! +That's about viewing numbers with Apple Bloom. + +Today I learned about sorting: + Did you know Twilight Sparkle likes 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, nothing, and nothing? + Sunset Shimmer did the dictionary of Twilight Sparkle! + Princess Cadance did viewing numbers of Sunset Shimmer. + + I wrote: "All numbers: 'Princess Cadance'", because she will show ALL the numbers. + I sang new line. + + Snips did sorting odds of Sunset Shimmer. + Snails did sorting evens of Sunset Shimmer. + + I wrote: "Odd numbers: 'Snips'", because he will show all the odd numbers. + I wrote: "Even numbers: 'Snails'", because he will show all the even numbers. + + By the way, that has been my odds and evens program. +Your faithful student, Jared MF. \ No newline at end of file diff --git a/examples/squared_cubed.fimpp b/examples/squared_cubed.fimpp new file mode 100644 index 0000000..a3f81a3 --- /dev/null +++ b/examples/squared_cubed.fimpp @@ -0,0 +1,42 @@ +Dear Princess Celestia: Squared and Cubed. + +I learned about square cube numbers with Queen Chrysalis: + Did you know Rarity likes the number one? + Did you know Spike likes Rarity? + Did you know Twilight Sparkle likes Spike? + Did you know Discord likes Rarity, Spike, and Twilight Sparkle? + + Fluffle Puff did the dictionary of Discord. + I did this while Queen Chrysalis was not equal to zero: + I wrote: Fluffle Puff! + + On the first page of Fluffle Puff I read about Rarity. + On the second page of Fluffle Puff I read about Spike. + On the third page of Fluffle Puff I read about Twilight Sparkle. + Rarity got one more. + Did you know Spike likes Rarity? + Did you know Twilight Sparkle likes Spike? + I did this once: + Did you know Sweetie Belle likes Spike? + Sweetie Belle did the product of Spike and Sweetie Belle! + Spike did the difference of Spike and Sweetie Belle. + That's what I did! + I did this once: + Did you know Flash Sentry likes Twilight Sparkle? + Flash Sentry did the product of Twilight Sparkle and Flash Sentry! + Princess Luna did the product of Twilight Sparkle and Flash Sentry! + Did you know Twilight Sparkle likes the number zero? + Did you know Flash Sentry likes Twilight Sparkle, because I said that earlier? + That's what I did. + On the first page of Fluffle Puff I noted about Rarity. + On the second page of Fluffle Puff I noted about Sweetie Belle. + On the third page of Fluffle Puff I noted about Princess Luna. + + Queen Chrysalis got one fewer. + That's what I did. +That's about square cube numbers. + +Today I learned: + I made square cube numbers of the number 200. + By the way, that is how square numbers and cube numbers are made. +Your faithful student, Jared MF. \ No newline at end of file diff --git a/src/stasiak/karol/fimpp/ErrorMessageProvider.scala b/src/stasiak/karol/fimpp/ErrorMessageProvider.scala index 8639141..a2fe8fd 100644 --- a/src/stasiak/karol/fimpp/ErrorMessageProvider.scala +++ b/src/stasiak/karol/fimpp/ErrorMessageProvider.scala @@ -17,9 +17,9 @@ trait ErrorMessageProvider { object Trollestia extends ErrorMessageProvider { def syntaxError(functionName: String) = "Now say, do you like mmm-syntax errors? You have one in function ‘"+ functionName+"’ after all. No? So let me get it straight: you're a mmm-biatch that does not like syntax errors. " + - "That's good, because there are no syntax errors... ON THE MOOOON!" + "That's good, because there are no syntax errors... ON THE MOOOON! -Princess Celestia" def mismatchedFunctionNameInFooter(expected: String, found: String) = "This function is a changeling! At the beginning it was named ‘" + - expected + "’, and now it's ‘" + found + "’!" - def unknownError = "To the moon with that code!" - def invalidIdentifier(id: String) = "‘"+id.capitalize+"’ ain't no pony I've heard of. Do they have tea parties with ‘"+id.capitalize+"’?" -} \ No newline at end of file + expected + "’, and now it's ‘" + found + "’! -Princess Celestia" + def unknownError = "To the moon with that code! -Princess Celestia and Princess Luna" + def invalidIdentifier(id: String) = "Mmm-‘"+id.capitalize+"’... I've never heard of such pony, you know. Do they have tea parties with ‘"+id.capitalize+"’? -Princess Celestia" +} diff --git a/src/stasiak/karol/fimpp/Main.scala b/src/stasiak/karol/fimpp/Mane.scala similarity index 50% rename from src/stasiak/karol/fimpp/Main.scala rename to src/stasiak/karol/fimpp/Mane.scala index 2e29cd9..c665342 100644 --- a/src/stasiak/karol/fimpp/Main.scala +++ b/src/stasiak/karol/fimpp/Mane.scala @@ -10,21 +10,24 @@ import io.Source * Time: 11:26 * To change this template use File | Settings | File Templates. */ -object Main { +object Mane { def main(args: Array[String]){ //TODO: flags args.length match { case 0 => println("To run a FIM++ program, pass it as the first argument to this program.") case 1=> - println("parsing: "+args(0)) - val program = Source.fromFile(args(0)).getLines().mkString("\n") - val parsed = FimppParser.parseAll(FimppParser.module, program) - if (parsed.successful) { - println("interpreting: "+args(0)) - parsed.get.run() + if args(0).endsWith (".fimpp") { + println("parsing: "+args(0)) + val program = Source.fromFile(args(0)).getLines().mkString("\n") + val parsed = FimppParser.parseAll(FimppParser.module, program) + if (parsed.successful) { + println("interpreting: "+args(0)) + parsed.get.run() + } + else println(parsed) } - else println(parsed) + else println("That ain't no program I've ever heard of. TO THE MOOOOOOON!!! -Princess Luna") case _ => println("Hold your horses! One file at a time, please!") } diff --git a/syntax/Program structure.md b/syntax/Program structure.md index b8bec26..219e483 100644 --- a/syntax/Program structure.md +++ b/syntax/Program structure.md @@ -3,16 +3,16 @@ FIM++ program structure FIM++ programs can have one of two structures: -* Main function contains functions inside (wrapped style). +* 'Mane' function contains functions inside (wrapped style). -* Functions precede the main function, and the main function, being the last one in the code, contains statements (C style). +* Functions precede the 'mane' function, and the 'mane' function, being the last one in the code, contains statements (C style). In all examples below, colons can be replaced with full stops, except after the word Celestia. Parts in braces {...} are optional. Wrapped style: ------------- -Execution of the program will start from the function that has the same name as the main function. It will be called with no arguments. +Execution of the program will start from the function that has the same name as the 'mane' function. It will be called with no arguments. Dear Princess Celestia: : @@ -25,7 +25,7 @@ Execution of the program will start from the function that has the same name as C style ------ -Execution of the program will start from the main function. +Execution of the program will start from the 'mane' function. Dear Princess Celestia: :