Skip to content

Commit

Permalink
Merge pull request antlr#1538 from antlr/scotty
Browse files Browse the repository at this point in the history
scotty
  • Loading branch information
teverett authored Oct 27, 2019
2 parents 8591e75 + 9c5e2e8 commit 1b3e58e
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 0 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
<module>rpn</module>
<module>ruby</module>
<module>scala</module>
<module>scotty</module>
<module>scss</module>
<module>sexpression</module>
<module>sgf</module>
Expand Down
3 changes: 3 additions & 0 deletions scotty/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Scotty Grammar

An ANTLR4 grammar for [Scotty](https://esolangs.org/wiki/Scotty) files.
1 change: 1 addition & 0 deletions scotty/examples/example1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
+ 1 1
55 changes: 55 additions & 0 deletions scotty/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>scotty</artifactId>
<packaging>jar</packaging>
<name>khubla.com Scotty grammar</name>
<parent>
<groupId>org.antlr.grammars</groupId>
<artifactId>grammarsv4</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>${antlr.version}</version>
<configuration>
<sourceDirectory>${basedir}</sourceDirectory>
<grammars>scotty.g4</grammars>
<visitor>true</visitor>
<listener>true</listener>
</configuration>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.khubla.antlr</groupId>
<artifactId>antlr4test-maven-plugin</artifactId>
<version>${antlr4test-maven-plugin.version}</version>
<configuration>
<verbose>false</verbose>
<showTree>false</showTree>
<entryPoint>prog</entryPoint>
<grammarName>scotty</grammarName>
<packageName></packageName>
<exampleFiles>examples/</exampleFiles>
</configuration>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
96 changes: 96 additions & 0 deletions scotty/scotty.g4
Original file line number Diff line number Diff line change
@@ -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
;

0 comments on commit 1b3e58e

Please sign in to comment.