lab 3/4, no report yet
This commit is contained in:
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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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>
|
||||||
@@ -16,7 +16,6 @@ public class ChomskyChecker {
|
|||||||
return "Unrestricted";
|
return "Unrestricted";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
|
|||||||
102
src/Lexer.java
Normal file
102
src/Lexer.java
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
|
public class Lexer {
|
||||||
|
public enum TokenType {
|
||||||
|
NUMBER,
|
||||||
|
OPERATOR,
|
||||||
|
LPAREN,
|
||||||
|
RPAREN,
|
||||||
|
FUNCTION,
|
||||||
|
COMMA,
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Token {
|
||||||
|
public TokenType type;
|
||||||
|
public String value;
|
||||||
|
|
||||||
|
public Token(TokenType type, String value) {
|
||||||
|
this.type = type;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Token> tokenize(String input) {
|
||||||
|
List<Token> tokens = new ArrayList<>();
|
||||||
|
input = input.replaceAll("\\s", "");
|
||||||
|
int i = 0;
|
||||||
|
while (i < input.length()) {
|
||||||
|
char ch = input.charAt(i);
|
||||||
|
if (Character.isDigit(ch)) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
while (i < input.length() && (Character.isDigit(input.charAt(i)) || input.charAt(i) == '.')) {
|
||||||
|
sb.append(input.charAt(i));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
tokens.add(new Token(TokenType.NUMBER, sb.toString()));
|
||||||
|
} else if (Character.isLetter(ch)) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
while (i < input.length() && Character.isLetter(input.charAt(i))) {
|
||||||
|
sb.append(input.charAt(i));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
tokens.add(new Token(TokenType.FUNCTION, sb.toString()));
|
||||||
|
} else {
|
||||||
|
switch (ch) {
|
||||||
|
case '(':
|
||||||
|
tokens.add(new Token(TokenType.LPAREN, "("));
|
||||||
|
i++;
|
||||||
|
break;
|
||||||
|
case ')':
|
||||||
|
tokens.add(new Token(TokenType.RPAREN, ")"));
|
||||||
|
i++;
|
||||||
|
break;
|
||||||
|
case ',':
|
||||||
|
tokens.add(new Token(TokenType.COMMA, ","));
|
||||||
|
i++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
tokens.add(new Token(TokenType.OPERATOR, String.valueOf(ch)));
|
||||||
|
i++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tokens.add(new Token(TokenType.EOF, ""));
|
||||||
|
|
||||||
|
if (!areParenthesesBalanced(tokens)) {
|
||||||
|
throw new RuntimeException("Parentheses are not balanced.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean areParenthesesBalanced(List<Token> tokens) {
|
||||||
|
Stack<TokenType> stack = new Stack<>();
|
||||||
|
for (Token token : tokens) {
|
||||||
|
if (token.type == TokenType.LPAREN) {
|
||||||
|
stack.push(TokenType.LPAREN);
|
||||||
|
} else if (token.type == TokenType.RPAREN) {
|
||||||
|
if (stack.isEmpty() || stack.pop() != TokenType.LPAREN) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stack.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String input = "(3 + 5) * sqrt(16)";
|
||||||
|
try {
|
||||||
|
List<Token> tokens = tokenize(input);
|
||||||
|
for (Token token : tokens) {
|
||||||
|
System.out.println(token.type + " : " + token.value);
|
||||||
|
}
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
System.err.println(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
149
src/RegexGenerator.java
Normal file
149
src/RegexGenerator.java
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class RegexGenerator {
|
||||||
|
public static String[] generateRandomNr1(int numStrings) {
|
||||||
|
String[] randomStrings = new String[numStrings];
|
||||||
|
Random random = new Random();
|
||||||
|
|
||||||
|
System.out.println("=========================");
|
||||||
|
|
||||||
|
for (int i = 0; i < numStrings; i++) {
|
||||||
|
System.out.println("String Nr. " + (i+1));
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
sb.append("O");
|
||||||
|
System.out.println(sb);
|
||||||
|
|
||||||
|
int length = random.nextInt(1,5);
|
||||||
|
for (int j = 0; j < length; j++) {
|
||||||
|
sb.append(randomChar("PQR"));
|
||||||
|
System.out.println(sb);
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append("2");
|
||||||
|
System.out.println(sb);
|
||||||
|
|
||||||
|
sb.append(randomChar("34"));
|
||||||
|
System.out.println(sb);
|
||||||
|
|
||||||
|
randomStrings[i] = sb.toString();
|
||||||
|
System.out.println("=========================");
|
||||||
|
}
|
||||||
|
|
||||||
|
return randomStrings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] generateRandomNr2(int numStrings) {
|
||||||
|
String[] randomStrings = new String[numStrings];
|
||||||
|
Random random = new Random();
|
||||||
|
|
||||||
|
System.out.println("=========================");
|
||||||
|
|
||||||
|
for (int i = 0; i < numStrings; i++) {
|
||||||
|
System.out.println("String Nr. " + (i+1));
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
int length1 = random.nextInt(6);
|
||||||
|
for (int j = 0; j < length1; j++) {
|
||||||
|
sb.append(randomChar("A"));
|
||||||
|
System.out.println(sb);
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append("B");
|
||||||
|
System.out.println(sb);
|
||||||
|
|
||||||
|
sb.append(randomChar("CDE"));
|
||||||
|
System.out.println(sb);
|
||||||
|
|
||||||
|
sb.append("F");
|
||||||
|
System.out.println(sb);
|
||||||
|
|
||||||
|
char chr = randomChar("GHI");
|
||||||
|
sb.append(chr);
|
||||||
|
System.out.println(sb);
|
||||||
|
|
||||||
|
sb.append(chr);
|
||||||
|
System.out.println(sb);
|
||||||
|
|
||||||
|
randomStrings[i] = sb.toString();
|
||||||
|
System.out.println("=========================");
|
||||||
|
}
|
||||||
|
|
||||||
|
return randomStrings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] generateRandomNr3(int numStrings) {
|
||||||
|
String[] randomStrings = new String[numStrings];
|
||||||
|
Random random = new Random();
|
||||||
|
|
||||||
|
System.out.println("=========================");
|
||||||
|
|
||||||
|
for (int i = 0; i < numStrings; i++) {
|
||||||
|
System.out.println("String Nr. " + (i+1));
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
int length1 = random.nextInt(1,6);
|
||||||
|
for (int j = 0; j < length1; j++) {
|
||||||
|
sb.append("J");
|
||||||
|
System.out.println(sb);
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append("K");
|
||||||
|
System.out.println(sb);
|
||||||
|
|
||||||
|
length1 = random.nextInt(6);
|
||||||
|
for (int j = 0; j < length1; j++) {
|
||||||
|
sb.append(randomChar("LMN"));
|
||||||
|
System.out.println(sb);
|
||||||
|
}
|
||||||
|
|
||||||
|
length1 = random.nextInt(2);
|
||||||
|
for (int j = 0; j < length1; j++) {
|
||||||
|
sb.append("O");
|
||||||
|
System.out.println(sb);
|
||||||
|
}
|
||||||
|
|
||||||
|
length1 = 3;
|
||||||
|
char chr = randomChar("PQ");
|
||||||
|
for (int j = 0; j < length1; j++) {
|
||||||
|
sb.append(chr);
|
||||||
|
System.out.println(sb);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
randomStrings[i] = sb.toString();
|
||||||
|
System.out.println("=========================");
|
||||||
|
}
|
||||||
|
|
||||||
|
return randomStrings;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static char randomChar(String characters) {
|
||||||
|
Random random = new Random();
|
||||||
|
int index = random.nextInt(characters.length());
|
||||||
|
return characters.charAt(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String[] randomStrings1 = generateRandomNr1(5);
|
||||||
|
System.out.println("All Strings Nr1: ");
|
||||||
|
for (String str : randomStrings1) {
|
||||||
|
System.out.println(str);
|
||||||
|
}
|
||||||
|
System.out.println("=========================");
|
||||||
|
|
||||||
|
String[] randomStrings2 = generateRandomNr2(5);
|
||||||
|
System.out.println("All Strings Nr2: ");
|
||||||
|
for (String str : randomStrings2) {
|
||||||
|
System.out.println(str);
|
||||||
|
}
|
||||||
|
System.out.println("=========================");
|
||||||
|
|
||||||
|
String[] randomStrings3 = generateRandomNr3(5);
|
||||||
|
System.out.println("All Strings Nr3: ");
|
||||||
|
for (String str : randomStrings3) {
|
||||||
|
System.out.println(str);
|
||||||
|
}
|
||||||
|
System.out.println("=========================");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user