From 9c5e2e87525af01e7f42a81486e63ff8ce1e1d2f Mon Sep 17 00:00:00 2001 From: Tom Everett Date: Sun, 27 Oct 2019 17:40:42 -0400 Subject: [PATCH] scotty --- pom.xml | 1 + scotty/README.md | 3 ++ scotty/examples/example1.txt | 1 + scotty/pom.xml | 55 +++++++++++++++++++++ scotty/scotty.g4 | 96 ++++++++++++++++++++++++++++++++++++ 5 files changed, 156 insertions(+) create mode 100755 scotty/README.md create mode 100644 scotty/examples/example1.txt create mode 100644 scotty/pom.xml create mode 100644 scotty/scotty.g4 diff --git a/pom.xml b/pom.xml index 6e61cb69b6..ad5e2608d4 100644 --- a/pom.xml +++ b/pom.xml @@ -210,6 +210,7 @@ rpn ruby scala + scotty scss sexpression sgf diff --git a/scotty/README.md b/scotty/README.md new file mode 100755 index 0000000000..def0b9597c --- /dev/null +++ b/scotty/README.md @@ -0,0 +1,3 @@ +# Scotty Grammar + +An ANTLR4 grammar for [Scotty](https://esolangs.org/wiki/Scotty) files. diff --git a/scotty/examples/example1.txt b/scotty/examples/example1.txt new file mode 100644 index 0000000000..ce92fbe46e --- /dev/null +++ b/scotty/examples/example1.txt @@ -0,0 +1 @@ ++ 1 1 diff --git a/scotty/pom.xml b/scotty/pom.xml new file mode 100644 index 0000000000..24d5a503d5 --- /dev/null +++ b/scotty/pom.xml @@ -0,0 +1,55 @@ + + 4.0.0 + scotty + jar + khubla.com Scotty grammar + + org.antlr.grammars + grammarsv4 + 1.0-SNAPSHOT + ../pom.xml + + + + + org.antlr + antlr4-maven-plugin + ${antlr.version} + + ${basedir} + scotty.g4 + true + true + + + + + antlr4 + + + + + + com.khubla.antlr + antlr4test-maven-plugin + ${antlr4test-maven-plugin.version} + + false + false + prog + scotty + + examples/ + + + + + test + + + + + + + diff --git a/scotty/scotty.g4 b/scotty/scotty.g4 new file mode 100644 index 0000000000..2d74df85b8 --- /dev/null +++ b/scotty/scotty.g4 @@ -0,0 +1,96 @@ +/* +BSD License + +Copyright (c) 2019, Tom Everett +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. Neither the name of Tom Everett nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +grammar scotty; + +prog + : program_lines + ; + +program_lines + : prefix_exp + | fn_def program_lines + | var_assign program_lines + ; + +var_assign + : identifier '=' prefix_exp + ; + +fn_def + : 'fun' identifier identifier '=' prefix_exp + ; + +prefix_exp + : ('+' prefix_exp prefix_exp) + | ('-' prefix_exp prefix_exp) + | ('*' prefix_exp prefix_exp) + | ('/' prefix_exp prefix_exp) + | ('(' identifier prefix_exp ')') + | identifier + | number + ; + +identifier + : LETTER id_tail + | LETTER + ; + +id_tail + : LETTER id_tail + | DIGIT id_tail + | LETTER + | DIGIT + ; + +number + : '-' digits + | digits + ; + +digits + : DIGIT digits + | '.' digits + | DIGIT + ; + +DIGIT + : [0-9] + ; + +LETTER + : [A-Za-z] + ; + +WS + : [ \t\r\n] -> skip + ; +