mirror of
https://github.com/Noratrieb/Hunterlang.git
synced 2026-01-14 12:35:01 +01:00
lexer working
This commit is contained in:
commit
9d9c06f51b
18 changed files with 549 additions and 0 deletions
5
.idea/.gitignore
generated
vendored
Normal file
5
.idea/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
out\
|
||||||
|
.class
|
||||||
16
.idea/compiler.xml
generated
Normal file
16
.idea/compiler.xml
generated
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<module name="Hunterlang" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
<bytecodeTargetLevel>
|
||||||
|
<module name="Hunterlang" target="15" />
|
||||||
|
</bytecodeTargetLevel>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/discord.xml
generated
Normal file
6
.idea/discord.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DiscordProjectSettings">
|
||||||
|
<option name="show" value="PROJECT_FILES" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
20
.idea/jarRepositories.xml
generated
Normal file
20
.idea/jarRepositories.xml
generated
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
13
.idea/misc.xml
generated
Normal file
13
.idea/misc.xml
generated
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_15" default="true" project-jdk-name="15" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/Hunterlang.iml" filepath="$PROJECT_DIR$/Hunterlang.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
124
.idea/uiDesigner.xml
generated
Normal file
124
.idea/uiDesigner.xml
generated
Normal file
|
|
@ -0,0 +1,124 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Palette2">
|
||||||
|
<group name="Swing">
|
||||||
|
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Button" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="RadioButton" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="CheckBox" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Label" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||||
|
<preferred-size width="-1" height="20" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
</group>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
15
Hunterlang.iml
Normal file
15
Hunterlang.iml
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_15">
|
||||||
|
<output url="file://$MODULE_DIR$/target/classes" />
|
||||||
|
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
16
pom.xml
Normal file
16
pom.xml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<groupId>com.github.nilstrieb</groupId>
|
||||||
|
<artifactId>Hunterlang</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>15</maven.compiler.source>
|
||||||
|
<maven.compiler.target>15</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.github.nilstrieb.hunterlang.editor.EditorView">
|
||||||
|
<grid id="27dc6" binding="panel1" default-binding="true" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<xy x="20" y="20" width="500" height="400"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="beb13" class="javax.swing.JEditorPane" binding="editorPane1" default-binding="true">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="150" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package com.github.nilstrieb.hunterlang.editor;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class EditorView {
|
||||||
|
private JEditorPane editorPane1;
|
||||||
|
private JPanel panel1;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.github.nilstrieb.hunterlang.lexer;
|
||||||
|
|
||||||
|
import com.github.nilstrieb.hunterlang.lib.ConsoleColors;
|
||||||
|
|
||||||
|
public class LexToken {
|
||||||
|
WordType key;
|
||||||
|
String value;
|
||||||
|
|
||||||
|
public LexToken(WordType key, String value) {
|
||||||
|
this.key = key;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return ConsoleColors.BLUE_BOLD + "{Key=" +
|
||||||
|
ConsoleColors.RED_BOLD_BRIGHT + key +
|
||||||
|
ConsoleColors.BLUE_BOLD + ", value=" +
|
||||||
|
ConsoleColors.YELLOW + value + ConsoleColors.BLUE_BOLD + "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.github.nilstrieb.hunterlang.lexer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class LexedList {
|
||||||
|
private ArrayList<ArrayList<LexToken>> list;
|
||||||
|
|
||||||
|
public LexedList() {
|
||||||
|
list = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void newLine(){
|
||||||
|
list.add(new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int line, WordType type, String value) {
|
||||||
|
list.get(line).add(new LexToken(type, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int line, WordType type){
|
||||||
|
add(line, type, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<LexToken> get(int i) {
|
||||||
|
return list.get(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
155
src/main/java/com/github/nilstrieb/hunterlang/lexer/Lexer.java
Normal file
155
src/main/java/com/github/nilstrieb/hunterlang/lexer/Lexer.java
Normal file
|
|
@ -0,0 +1,155 @@
|
||||||
|
package com.github.nilstrieb.hunterlang.lexer;
|
||||||
|
|
||||||
|
import com.github.nilstrieb.hunterlang.lib.ConsoleColors;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class Lexer {
|
||||||
|
|
||||||
|
public static final String COMMENT = "#";
|
||||||
|
|
||||||
|
private static final String MEMCALL = "killua";
|
||||||
|
public static final String ASSIGNMENT = "hunts";
|
||||||
|
public static final String IF = "Gon";
|
||||||
|
public static final String WANTS = "wants";
|
||||||
|
public static final String ELSE = "got";
|
||||||
|
public static final String BOPEN = "{";
|
||||||
|
public static final String BCLOSE = "}";
|
||||||
|
|
||||||
|
public static final String GTHAN = ">";
|
||||||
|
public static final String LTHAN = "<";
|
||||||
|
public static final String EQUALS = "=";
|
||||||
|
public static final String PLUS = "+";
|
||||||
|
public static final String MINUS = "-";
|
||||||
|
public static final String MULTIPLY = "*";
|
||||||
|
public static final String DIVIDE = "/";
|
||||||
|
public static final String MOD = "%";
|
||||||
|
|
||||||
|
public static final String LIBFUNCCALL_REGEX = "(\\w+) does (\\w+).*";
|
||||||
|
|
||||||
|
public static final String BOOL_REGEX = "(true|false).*";
|
||||||
|
public static final String STRING_REGEX = "^\"(.*)\".*";
|
||||||
|
public static final String NUMBER_REGEX = "^(-?\\d+.?\\d*).*";
|
||||||
|
|
||||||
|
private LexedList tokens;
|
||||||
|
|
||||||
|
public LexedList lex(String code) {
|
||||||
|
tokens = new LexedList();
|
||||||
|
ArrayList<LexToken> tempList = new ArrayList<>();
|
||||||
|
String[] lines = code.split("\\r\\n|\\n");
|
||||||
|
|
||||||
|
for (int i = 0; i < lines.length; i++) {
|
||||||
|
tokens.newLine();
|
||||||
|
String line = lines[i];
|
||||||
|
for (int j = 0; j < line.length(); j++) {
|
||||||
|
String sub = line.substring(j);
|
||||||
|
|
||||||
|
//COMMENT
|
||||||
|
|
||||||
|
if (sub.startsWith(COMMENT)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//FIXED KEYWORDS
|
||||||
|
|
||||||
|
else if (sub.startsWith(MEMCALL)) {
|
||||||
|
tokens.add(i, WordType.MEMCALL);
|
||||||
|
j += MEMCALL.length() - 1;
|
||||||
|
} else if (sub.startsWith(ASSIGNMENT)) {
|
||||||
|
tokens.add(i, WordType.ASSIGNMENT);
|
||||||
|
j += ASSIGNMENT.length() - 1;
|
||||||
|
} else if (sub.startsWith(IF)) {
|
||||||
|
tokens.add(i, WordType.IF);
|
||||||
|
j += IF.length() - 1;
|
||||||
|
} else if (sub.startsWith(WANTS)){
|
||||||
|
tokens.add(i, WordType.WANTS);
|
||||||
|
j += WANTS.length() - 1;
|
||||||
|
} else if (sub.startsWith(ELSE)){
|
||||||
|
tokens.add(i, WordType.ELSE);
|
||||||
|
j += ELSE.length() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//CONDITIONS
|
||||||
|
else if (sub.startsWith(GTHAN)){
|
||||||
|
tokens.add(i, WordType.GTHAN);
|
||||||
|
j += GTHAN.length() - 1;
|
||||||
|
} else if (sub.startsWith(LTHAN)){
|
||||||
|
tokens.add(i, WordType.LTHAN);
|
||||||
|
j += LTHAN.length() - 1;
|
||||||
|
} else if (sub.startsWith(EQUALS)){
|
||||||
|
tokens.add(i, WordType.EQUALS);
|
||||||
|
j += EQUALS.length() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//OPERATORS
|
||||||
|
else if (sub.startsWith(PLUS)){
|
||||||
|
tokens.add(i, WordType.PLUS);
|
||||||
|
} else if (sub.startsWith(MINUS)){
|
||||||
|
tokens.add(i, WordType.MINUS);
|
||||||
|
} else if (sub.startsWith(MULTIPLY)){
|
||||||
|
tokens.add(i, WordType.MULTIPLY);
|
||||||
|
}else if (sub.startsWith(DIVIDE)){
|
||||||
|
tokens.add(i, WordType.DIVIDE);
|
||||||
|
} else if (sub.startsWith(MOD)){
|
||||||
|
tokens.add(i, WordType.MOD);
|
||||||
|
}
|
||||||
|
|
||||||
|
// BRACKETS
|
||||||
|
else if (sub.startsWith(BOPEN)){
|
||||||
|
tokens.add(i, WordType.BOPEN);
|
||||||
|
} else if (sub.startsWith(BCLOSE)){
|
||||||
|
tokens.add(i, WordType.BCLOSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
//VALUES
|
||||||
|
else if (sub.matches(STRING_REGEX)) {
|
||||||
|
String string = sub.replaceAll(STRING_REGEX, "$1");
|
||||||
|
tokens.add(i, WordType.STRING, string);
|
||||||
|
j += string.length() + 1;
|
||||||
|
} else if (sub.matches(NUMBER_REGEX)) {
|
||||||
|
String number = sub.replaceAll(NUMBER_REGEX, "$1");
|
||||||
|
tokens.add(i, WordType.NUMBER, number);
|
||||||
|
j += number.length() - 1;
|
||||||
|
} else if (sub.matches(BOOL_REGEX)){
|
||||||
|
String bool = sub.replaceAll(BOOL_REGEX, "$1");
|
||||||
|
tokens.add(i, WordType.BOOL, bool);
|
||||||
|
j += bool.length() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Calls
|
||||||
|
else if(sub.matches(LIBFUNCCALL_REGEX)){
|
||||||
|
String libName = sub.replaceAll(LIBFUNCCALL_REGEX, "$1");
|
||||||
|
String funcName = sub.replaceAll(LIBFUNCCALL_REGEX, "$2");
|
||||||
|
tokens.add(i, WordType.LIB, libName);
|
||||||
|
tokens.add(i, WordType.FUNCCALL, funcName);
|
||||||
|
j += libName.length(); //lib name
|
||||||
|
j += 1 + 4 + 1; // space + does + space
|
||||||
|
j += funcName.length() - 1; //func name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println(ConsoleColors.GREEN_BOLD + line);
|
||||||
|
System.out.println(ConsoleColors.BLUE_BOLD + tokens.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Lexer l = new Lexer();
|
||||||
|
|
||||||
|
LexedList tokens = l.lex("""
|
||||||
|
killua0 hunts 3
|
||||||
|
killua0 hunts -3.4 #hunts nothing
|
||||||
|
killua0 hunts 4
|
||||||
|
killua1 hunts "hallo"
|
||||||
|
#comment
|
||||||
|
Gon wants false {
|
||||||
|
Leorio does say "false"
|
||||||
|
} wants killua0 > 3 {
|
||||||
|
Leorio does say "big killua"
|
||||||
|
} got {
|
||||||
|
Leorio does say "small killua"
|
||||||
|
}
|
||||||
|
""");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package com.github.nilstrieb.hunterlang.lexer;
|
||||||
|
|
||||||
|
public enum WordType {
|
||||||
|
ASSIGNMENT, MEMCALL, STRING, NUMBER, BOOL, IF, WANTS, ELSE, BOPEN, BCLOSE, GTHAN, LTHAN, EQUALS, FUNCNAME, FUNCARGS, FUNCRETURN, IOCALL, FUNCCALL, OPERATOR, LIB, MINUS, DEFAULT, PLUS, MULTIPLY, DIVIDE, MOD;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,76 @@
|
||||||
|
package com.github.nilstrieb.hunterlang.lib;
|
||||||
|
|
||||||
|
public class ConsoleColors {
|
||||||
|
// Reset
|
||||||
|
public static final String RESET = "\033[0m"; // Text Reset
|
||||||
|
|
||||||
|
// Regular Colors
|
||||||
|
public static final String BLACK = "\033[0;30m"; // BLACK
|
||||||
|
public static final String RED = "\033[0;31m"; // RED
|
||||||
|
public static final String GREEN = "\033[0;32m"; // GREEN
|
||||||
|
public static final String YELLOW = "\033[0;33m"; // YELLOW
|
||||||
|
public static final String BLUE = "\033[0;34m"; // BLUE
|
||||||
|
public static final String PURPLE = "\033[0;35m"; // PURPLE
|
||||||
|
public static final String CYAN = "\033[0;36m"; // CYAN
|
||||||
|
public static final String WHITE = "\033[0;37m"; // WHITE
|
||||||
|
|
||||||
|
// Bold
|
||||||
|
public static final String BLACK_BOLD = "\033[1;30m"; // BLACK
|
||||||
|
public static final String RED_BOLD = "\033[1;31m"; // RED
|
||||||
|
public static final String GREEN_BOLD = "\033[1;32m"; // GREEN
|
||||||
|
public static final String YELLOW_BOLD = "\033[1;33m"; // YELLOW
|
||||||
|
public static final String BLUE_BOLD = "\033[1;34m"; // BLUE
|
||||||
|
public static final String PURPLE_BOLD = "\033[1;35m"; // PURPLE
|
||||||
|
public static final String CYAN_BOLD = "\033[1;36m"; // CYAN
|
||||||
|
public static final String WHITE_BOLD = "\033[1;37m"; // WHITE
|
||||||
|
|
||||||
|
// Underline
|
||||||
|
public static final String BLACK_UNDERLINED = "\033[4;30m"; // BLACK
|
||||||
|
public static final String RED_UNDERLINED = "\033[4;31m"; // RED
|
||||||
|
public static final String GREEN_UNDERLINED = "\033[4;32m"; // GREEN
|
||||||
|
public static final String YELLOW_UNDERLINED = "\033[4;33m"; // YELLOW
|
||||||
|
public static final String BLUE_UNDERLINED = "\033[4;34m"; // BLUE
|
||||||
|
public static final String PURPLE_UNDERLINED = "\033[4;35m"; // PURPLE
|
||||||
|
public static final String CYAN_UNDERLINED = "\033[4;36m"; // CYAN
|
||||||
|
public static final String WHITE_UNDERLINED = "\033[4;37m"; // WHITE
|
||||||
|
|
||||||
|
// Background
|
||||||
|
public static final String BLACK_BACKGROUND = "\033[40m"; // BLACK
|
||||||
|
public static final String RED_BACKGROUND = "\033[41m"; // RED
|
||||||
|
public static final String GREEN_BACKGROUND = "\033[42m"; // GREEN
|
||||||
|
public static final String YELLOW_BACKGROUND = "\033[43m"; // YELLOW
|
||||||
|
public static final String BLUE_BACKGROUND = "\033[44m"; // BLUE
|
||||||
|
public static final String PURPLE_BACKGROUND = "\033[45m"; // PURPLE
|
||||||
|
public static final String CYAN_BACKGROUND = "\033[46m"; // CYAN
|
||||||
|
public static final String WHITE_BACKGROUND = "\033[47m"; // WHITE
|
||||||
|
|
||||||
|
// High Intensity
|
||||||
|
public static final String BLACK_BRIGHT = "\033[0;90m"; // BLACK
|
||||||
|
public static final String RED_BRIGHT = "\033[0;91m"; // RED
|
||||||
|
public static final String GREEN_BRIGHT = "\033[0;92m"; // GREEN
|
||||||
|
public static final String YELLOW_BRIGHT = "\033[0;93m"; // YELLOW
|
||||||
|
public static final String BLUE_BRIGHT = "\033[0;94m"; // BLUE
|
||||||
|
public static final String PURPLE_BRIGHT = "\033[0;95m"; // PURPLE
|
||||||
|
public static final String CYAN_BRIGHT = "\033[0;96m"; // CYAN
|
||||||
|
public static final String WHITE_BRIGHT = "\033[0;97m"; // WHITE
|
||||||
|
|
||||||
|
// Bold High Intensity
|
||||||
|
public static final String BLACK_BOLD_BRIGHT = "\033[1;90m"; // BLACK
|
||||||
|
public static final String RED_BOLD_BRIGHT = "\033[1;91m"; // RED
|
||||||
|
public static final String GREEN_BOLD_BRIGHT = "\033[1;92m"; // GREEN
|
||||||
|
public static final String YELLOW_BOLD_BRIGHT = "\033[1;93m";// YELLOW
|
||||||
|
public static final String BLUE_BOLD_BRIGHT = "\033[1;94m"; // BLUE
|
||||||
|
public static final String PURPLE_BOLD_BRIGHT = "\033[1;95m";// PURPLE
|
||||||
|
public static final String CYAN_BOLD_BRIGHT = "\033[1;96m"; // CYAN
|
||||||
|
public static final String WHITE_BOLD_BRIGHT = "\033[1;97m"; // WHITE
|
||||||
|
|
||||||
|
// High Intensity backgrounds
|
||||||
|
public static final String BLACK_BACKGROUND_BRIGHT = "\033[0;100m";// BLACK
|
||||||
|
public static final String RED_BACKGROUND_BRIGHT = "\033[0;101m";// RED
|
||||||
|
public static final String GREEN_BACKGROUND_BRIGHT = "\033[0;102m";// GREEN
|
||||||
|
public static final String YELLOW_BACKGROUND_BRIGHT = "\033[0;103m";// YELLOW
|
||||||
|
public static final String BLUE_BACKGROUND_BRIGHT = "\033[0;104m";// BLUE
|
||||||
|
public static final String PURPLE_BACKGROUND_BRIGHT = "\033[0;105m"; // PURPLE
|
||||||
|
public static final String CYAN_BACKGROUND_BRIGHT = "\033[0;106m"; // CYAN
|
||||||
|
public static final String WHITE_BACKGROUND_BRIGHT = "\033[0;107m"; // WHITE
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.github.nilstrieb.hunterlang.parser;
|
||||||
|
|
||||||
|
public class Parser {
|
||||||
|
}
|
||||||
|
|
||||||
|
class ParseTreeNode {
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue