Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
✨ v1.2.1! (#11)
Browse files Browse the repository at this point in the history
* License & BackCompat Flag + File Missing Fix

* Version Bump!
  • Loading branch information
JumperBot authored Nov 13, 2022
1 parent d18d628 commit f20955e
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 39 deletions.
44 changes: 44 additions & 0 deletions README.ufbb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<div align="center">

# UFB

`/UFB/*.class` | `UFB.jar` is the interpreter | compiler merged as one.

Only one file ending in `.ufbb` | `ufb` will be interpreted | compiled.

A file will not be compiled | interpreted if there are errors.

</div>

---

## Usage

```shell
java -jar UFB.jar [ -flags ] [ file ]
```

---

## Flags

- "-p" -> Performance measurement flag -> ms
- "-n" -> Accurately use the "-p" flag -> ns
- "-m" -> Time all commands being run
- "-v" -> Display semantic version tag
- "-h" -> Display help links and sources
- "-c" -> Compile file

---

## Example

```shell
java UFB -pnv
java UFB -p
java UFB -m
java UFB -nvp
java UFB -pnhv
java UFB -mn
java UFB -c ../test/UFB/Main.ufb
```
Binary file modified build/UFB.jar
Binary file not shown.
Binary file modified build/UFB/FlagManager.class
Binary file not shown.
Binary file modified build/UFB/Runner.class
Binary file not shown.
Binary file modified build/UFB/UFB.class
Binary file not shown.
8 changes: 7 additions & 1 deletion src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ java -jar UFB.jar [ -flags ] [ file ]
- "-m" -> Time all commands being run
- "-v" -> Display semantic version tag
- "-h" -> Display help links and sources
- "-c" -> Compile file
- "-c" -> Compile one of the provided files
- "-l" -> Display license notice (GPL v3)

---

(WARNING: NOT RECOMMENDED!):
- "-b" -> Activate backwards compatibility

---

Expand Down
46 changes: 16 additions & 30 deletions src/UFB/FlagManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
import java.util.regex.Pattern;

class FlagManager{
final boolean[] isActivated=new boolean[6];
final String flagString="[pnmvhclb]";
final boolean[] isActivated=new boolean[flagString.length()-2];
final String file;
final Pattern flags=Pattern.compile("[pnmhvc]");
final Pattern flags=Pattern.compile(flagString);
final Pattern repeats=Pattern.compile("(\\w)\\1+");
public FlagManager(final String[]a){
String fileName="";
Expand All @@ -43,42 +44,27 @@ else if(arg.startsWith("-")){
"Continuing anyway..."
);
}
if(str.contains("p"))isActivated[0]=true;
if(str.contains("n")){
isActivated[0]=true;
isActivated[1]=true;
}
if(str.contains("m")){
isActivated[0]=true;
isActivated[2]=true;
}
if(str.contains("v"))isActivated[3]=true;
if(str.contains("h"))isActivated[4]=true;
if(str.contains("c"))isActivated[5]=true;
if(str.contains("p"))isActivated[0]=true;
for(int i=1;i<3;i++)
if(str.contains(flagString.charAt(i+1)+""))
isActivated[0]=isActivated[i]=true;
for(int i=3;i<flagString.length()-2;i++)
if(str.contains(flagString.charAt(i+1)+""))
isActivated[i]=true;
}else System.out.printf(
"Unrecognized argument: %s\nContinuing anyway...\n\n", arg
);
}
file=fileName;
}
boolean isFlagActivated(final char c){
switch(c){
case 'p':
return isActivated[0];
case 'n':
return isActivated[1];
case 'm':
return isActivated[2];
case 'v':
return isActivated[3];
case 'h':
return isActivated[4];
case 'c':
return isActivated[5];
}
public boolean isFlagActivated(final char c){
final char[] array=flagString.substring(1).toCharArray();
for(int i=0;i<array.length-1;i++)
if(array[i]==c)
return isActivated[i];
return false;
}
String getFileName(){
public String getFileName(){
return file;
}
}
30 changes: 24 additions & 6 deletions src/UFB/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ class Runner{
int furthestLine=-1;
final boolean nanoseconds;
final boolean timeMethods;
final boolean backwardsCompat;
public Runner(final String fileName, final boolean performance,
final boolean nanoseconds, final boolean timeMethods)throws Exception{
final boolean nanoseconds, final boolean timeMethods,
final boolean backwardsCompat)throws Exception{
mem[0]=' ';
aKnownNonNum[0]=true;
for(int i=0;i<26;i++){
Expand All @@ -53,8 +55,13 @@ public Runner(final String fileName, final boolean performance,
for(int i=37;i<256;i++)aKnownNonNum[i]=true;
this.nanoseconds=nanoseconds;
this.timeMethods=timeMethods;
this.backwardsCompat=backwardsCompat;
if(fileName.length()!=0){
final File f=new File(fileName);
if(!f.exists()){
System.out.println("File Provided Does Not Exist...\nTerminating...");
System.exit(1);
}
buffer=new BufferedInputStream(new FileInputStream(f));
buffer.mark(Integer.MAX_VALUE);
size=(int)f.length();
Expand All @@ -74,7 +81,10 @@ public Runner(final String fileName, final boolean performance,
}catch(final Exception e){
buffer.close();
scan.close();
throw new RuntimeException(e);
if(!e.toString().contains("Unsupported Command Lol"))
throw new RuntimeException(e);
else
System.exit(1);
}
return;
}
Expand Down Expand Up @@ -148,10 +158,18 @@ private void runCommand(final int com)throws Exception{
read();
break;
default:
System.out.printf(
"\nCommand Index: %d Is Not Recognized By The Interpreter...\n", com
);
break;
if(backwardsCompat){
System.out.printf(
"\nCommand Index: %d Is Not Recognized By The Interpreter...\n%s\n",
com, "Skipping Instead Since '-b' Flag Is Toggled..."
);
break;
}
System.out.printf(
"\nCommand Index: %d Is Not Recognized By The Interpreter...\n%s\n",
com, "Terminating..."
);
throw new Exception("Unsupported Command Lol");
}
}
int byteInd=0;
Expand Down
32 changes: 30 additions & 2 deletions src/UFB/UFB.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class UFB{
* MINOR CHANGES should give new commands/major features.
* PATCH CHANGES should give new flags/performance-boosts/bug-fixes/etc.
**/
final static String version_tag="v1.2.0";
final static String version_tag="v1.2.1";
//----------------------------------------------------------------------//
public static void main(final String[]a)throws Exception{
final FlagManager flagManager=new FlagManager(a);
Expand All @@ -52,6 +52,33 @@ public static void main(final String[]a)throws Exception{
"Flag triggered, continuing anyway..."
);
}
if(flagManager.isFlagActivated('l')){
final StringBuilder license=new StringBuilder()
.append("GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007\n\n")
.append("Unsafe Four Bit is a compiled-interpreted, dynamically-typed programming language.\n")
.append("Copyright (C) 2022 JumperBot_\n")
.append("\n")
.append("This program is free software: you can redistribute it and/or modify\n")
.append("it under the terms of the GNU General Public License as published by\n")
.append("the Free Software Foundation, either version 3 of the License, or\n")
.append("(at your option) any later version.\n")
.append("\n")
.append("This program is distributed in the hope that it will be useful,\n")
.append("but WITHOUT ANY WARRANTY; without even the implied warranty of\n")
.append("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n")
.append("GNU General Public License for more details.\n")
.append("\n")
.append("You should have received a copy of the GNU General Public License\n")
.append("along with this program. If not, see <https://www.gnu.org/licenses/>.\n");
System.out.printf(
"%s\n%s\n%s\n%s\n%s\n\n",
"----------------------------------------------------------------------------------\n",
license.toString(),
"The copy of the license can be viewed at the root of this repository.\n",
"----------------------------------------------------------------------------------\n",
"Flag triggered, continuing anyway..."
);
}
final String fileName=flagManager.getFileName();
if(fileName.length()==0){
System.out.println("No file input found, terminating.");
Expand All @@ -76,7 +103,8 @@ public static void main(final String[]a)throws Exception{
fileName,
flagManager.isFlagActivated('p'),
flagManager.isFlagActivated('n'),
flagManager.isFlagActivated('m')
flagManager.isFlagActivated('m'),
flagManager.isFlagActivated('b')
);
}
}

0 comments on commit f20955e

Please sign in to comment.