diff --git a/sqlTranslate/.idea/compiler.xml b/sqlTranslate/.idea/compiler.xml
new file mode 100644
index 00000000..8e6776c3
--- /dev/null
+++ b/sqlTranslate/.idea/compiler.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sqlTranslate/.idea/encodings.xml b/sqlTranslate/.idea/encodings.xml
new file mode 100644
index 00000000..aa00ffab
--- /dev/null
+++ b/sqlTranslate/.idea/encodings.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sqlTranslate/.idea/jarRepositories.xml b/sqlTranslate/.idea/jarRepositories.xml
new file mode 100644
index 00000000..712ab9d9
--- /dev/null
+++ b/sqlTranslate/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sqlTranslate/.idea/workspace.xml b/sqlTranslate/.idea/workspace.xml
index 8a06abb0..67d9ae73 100644
--- a/sqlTranslate/.idea/workspace.xml
+++ b/sqlTranslate/.idea/workspace.xml
@@ -4,14 +4,32 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -20,6 +38,9 @@
+
+
+
@@ -27,10 +48,11 @@
-
+
@@ -44,9 +66,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -59,6 +106,29 @@
1723106789329
+
+ 1723106890550
+
+
+
+ 1723106890550
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sqlTranslate/src/main/java/Lexer/OracleLexer.java b/sqlTranslate/src/main/java/Lexer/OracleLexer.java
new file mode 100644
index 00000000..005e683b
--- /dev/null
+++ b/sqlTranslate/src/main/java/Lexer/OracleLexer.java
@@ -0,0 +1,79 @@
+package Lexer;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+
+public class OracleLexer {
+ public static final String[] keywords = {"SELECT", "FROM", "WHERE", "AND", "OR", "INSERT", "UPDATE", "DELETE", "now()"};
+ private static final Pattern TOKEN_PATTERN = Pattern.compile(
+ "(now\\(\\))|" + // now() function
+ "(\\b[A-Za-z_][A-Za-z0-9_]*\\b)|" + // Keywords and identifiers
+ "(\\d+\\.?\\d*)|" + // Numbers (integer or decimal)
+ "(\"[^\"]*\")|" + // Double-quoted strings
+ "('([^']|\\\\')*)'|" + // Single-quoted strings
+ "([;,()])|" + // Symbols: ;, (, ), ,
+ "([=<>+\\-*/<<>>])|" + // Operators, including shift operators
+ "(\\s+)" // Whitespace
+ );
+
+ private final List tokens = new ArrayList<>();
+ private final String input;
+ private int position = 0;
+
+ public OracleLexer(String input) {
+ this.input = input;
+ }
+
+ public List tokenize() {
+ Matcher matcher = TOKEN_PATTERN.matcher(input);
+ while (matcher.find()) {
+ String tokenValue = matcher.group();
+ Token token = createToken(tokenValue);
+ if (token != null) { // Skip whitespace
+ tokens.add(token);
+ // Update position based on the length of the matched group
+ position += tokenValue.length();
+ } else {
+ // If the token is null, we skip it (whitespace)
+ position += tokenValue.length();
+ }
+ }
+ tokens.add(new Token(Token.TokenType.EOF, ""));
+ return tokens;
+ }
+
+ private Token createToken(String tokenValue) {
+ if (tokenValue.matches("\\d+(\\.\\d+)?")) {
+ return new Token(Token.TokenType.NUMBER, tokenValue);
+ } else if (tokenValue.matches("\"[^\"]*\"")) {
+ return new Token(Token.TokenType.STRING, tokenValue);
+ } else if (tokenValue.matches("'([^']|\\\\')*'")) {
+ return new Token(Token.TokenType.STRING, tokenValue);
+ } else if (tokenValue.matches("([;(),])")) {
+ return new Token(Token.TokenType.SYMBOL, tokenValue);
+ } else if (tokenValue.matches("[=<>+\\-*/<<>>]")) {
+ return new Token(Token.TokenType.OPERATOR, tokenValue);
+ } else if (tokenValue.matches("now\\(\\)")) {
+ // Handle the now() function as a single token
+ return new Token(Token.TokenType.KEYWORD, tokenValue);
+ } else if (isKeyword(tokenValue)) {
+ return new Token(Token.TokenType.KEYWORD, tokenValue);
+ } else if (tokenValue.matches("[a-zA-Z_][a-zA-Z0-9_]*")) {
+ return new Token(Token.TokenType.IDENTIFIER, tokenValue);
+ }
+ return null;
+ }
+
+ private boolean isKeyword(String tokenValue) {
+ for (String keyword : keywords) {
+ if (keyword.equalsIgnoreCase(tokenValue)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/sqlTranslate/src/main/java/Lexer/Token.java b/sqlTranslate/src/main/java/Lexer/Token.java
new file mode 100644
index 00000000..b8319f0d
--- /dev/null
+++ b/sqlTranslate/src/main/java/Lexer/Token.java
@@ -0,0 +1,31 @@
+package Lexer;
+
+public class Token {
+ public enum TokenType {
+ KEYWORD, IDENTIFIER, NUMBER, OPERATOR, STRING, SYMBOL, EOF
+ }
+
+ private final TokenType type;
+ private final String value;
+
+ public Token(TokenType type, String value) {
+ this.type = type;
+ this.value = value;
+ }
+
+ public TokenType getType() {
+ return type;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ return "Token{" +
+ "type=" + type +
+ ", value='" + value + '\'' +
+ '}';
+ }
+}
diff --git a/sqlTranslate/src/main/java/Main.java b/sqlTranslate/src/main/java/Main.java
new file mode 100644
index 00000000..b68a4f3d
--- /dev/null
+++ b/sqlTranslate/src/main/java/Main.java
@@ -0,0 +1,16 @@
+import Lexer.OracleLexer;
+import Lexer.Token;
+
+import java.util.List;
+
+public class Main {
+ public static void main(String[] args) {
+ String sql = "SELECT now() FROM table WHERE name = 'John Doe';";
+ OracleLexer lexer = new OracleLexer(sql);
+ List tokens = lexer.tokenize();
+
+ for (Token token : tokens) {
+ System.out.println(token);
+ }
+ }
+}
diff --git a/sqlTranslate/src/main/java/org/example/App.java b/sqlTranslate/src/main/java/org/example/App.java
deleted file mode 100644
index e803e22b..00000000
--- a/sqlTranslate/src/main/java/org/example/App.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.example;
-
-public class App {
- public static void main(String[] args) {
- System.out.println("Hello World!");
- }
-}
diff --git a/sqlTranslate/src/test/java/org/example/AppTest.java b/sqlTranslate/src/test/java/org/example/AppTest.java
deleted file mode 100644
index 6fb6e67d..00000000
--- a/sqlTranslate/src/test/java/org/example/AppTest.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package org.example;
-
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-public class AppTest {
-
- @Test
- public void shouldAnswerWithTrue() {
- assertTrue(true);
- }
-}