Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whenever #4100

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions esolang/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
<module>sickbay</module>
<module>snowball</module>
<module>wheel</module>
<module>whenever</module>
</modules>
</project>
3 changes: 3 additions & 0 deletions esolang/whenever/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# whenever grammar

[whenever](https://www.dangermouse.net/esoteric/whenever.html)
4 changes: 4 additions & 0 deletions esolang/whenever/desc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<desc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../_scripts/desc.xsd">
<targets>CSharp;Cpp;Dart;Java;JavaScript;Python3;TypeScript;Antlr4ng</targets>
</desc>
10 changes: 10 additions & 0 deletions esolang/whenever/examples/example1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1 again (1) defer (3 || N(1)<=N(2) || N(7)>99) 2#N(1),3,7;
2 again (2) defer (3 || N(2)<=N(1) || N(7)>99) 1#N(2),3,7;
3 defer (5) print(N(1)+N(2));
4 defer (5) print("1");
5 4,-3,7;
6 defer (4) 3;
7 7;
8 defer (N(7)<100) -1#N(1),-2#N(2),-7#100,-3;
9 defer (3 || 6) 1,3;

4 changes: 4 additions & 0 deletions esolang/whenever/examples/example2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1 defer (4 || N(1)<N(2) || N(2)<N(3)) print(N(1)+" bottles of beer on the wall, "+N(1)+" bottles of beer,");
2 defer (4 || N(1)==N(2)) print("Take one down and pass it around,");
3 defer (4 || N(2)==N(3)) print(N(1)+" bottles of beer on the wall.");
4 1#98,2#98,3#98;
1 change: 1 addition & 0 deletions esolang/whenever/examples/example3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 1#9;
1 change: 1 addition & 0 deletions esolang/whenever/examples/example4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 print("Hello world!");
1 change: 1 addition & 0 deletions esolang/whenever/examples/example5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 1;
56 changes: 56 additions & 0 deletions esolang/whenever/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<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>whenever</artifactId>
<packaging>jar</packaging>
<name>Whenever grammar</name>
<parent>
<groupId>org.antlr.grammars</groupId>
<artifactId>esolangparent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>${antlr.version}</version>
<configuration>
<sourceDirectory>${basedir}</sourceDirectory>
<includes>
<include>whenever.g4</include>
</includes>
<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>program_</entryPoint>
<grammarName>whenever</grammarName>
<packageName></packageName>
<exampleFiles>examples/</exampleFiles>
</configuration>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
172 changes: 172 additions & 0 deletions esolang/whenever/whenever.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*
BSD License

Copyright (c) 2024 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.
*/

// $antlr-format alignTrailingComments true, columnLimit 150, minEmptyLines 1, maxEmptyLinesToKeep 1, reflowComments false, useTab false


// $antlr-format allowShortRulesOnASingleLine false, allowShortBlocksOnASingleLine true, alignSemicolons hanging, alignColons hanging

grammar whenever;

program_
: line_* EOL* EOF
;

line_
: linenumber_ when_* statement_list_ ';' EOL
;

when_
: again_
| defer_
| forget_
;

defer_
: 'defer' '(' expression_ ')'
;

again_
: 'again' '(' expression_ ')'
;

forget_
: 'forget' '(' expression_ ')'
;

linenumber_
: term_
;

addremove_
: termlist_ '#' termlist_
;

termlist_
: term_ (',' term_)*
;

statement_list_
: statement_ (',' statement_)*
;

statement_
: addremove_? (print_statement_ | read_statement_ | decl_statement_)?
;

decl_statement_
: term_ (',' term_)*
;

print_statement_
: 'print' '(' term_ ')'
;

read_statement_
: 'read' '(' ')'
;

expression_
: term_ (COMPARE term_)*
;

term_
: NOT? mult_term_
;

mult_term_
: add_term_ (MULT_OP add_term_)*
;

add_term_
: value_ (ADD_OP value_)*
;

value_
: NUMBER
| func_
| QUOTED_STRING
;

func_
: func_n_
| func_u_
;

func_n_
: 'N' '(' term_ ')'
;

func_u_
: 'U' '(' term_ ')'
;

COMPARE
: '<'
| '>'
| '>='
| '<='
| '=='
| '||'
| '&&'
;

NOT
: '!'
;

MULT_OP
: '*'
| '/'
;

ADD_OP
: '+'
| '-'
;

QUOTED_STRING
: '"' ~ '"'* '"'
;

NUMBER
: '-'? [0-9]+
;

EOL
: [\r\n]
;

WHITESPACE
: [ \t]+ -> skip
;

Loading