Codes that perform various tasks I learnt in theory of computation course
This class can be used to create a grammar object.
constructor(variables, rules, startVariable) {
this.variables = variables;
this.rules = rules;
this.startVariable = startVariable;
}
variables
-> Array of characters that are variablesrules
-> Object of the form{variable: "variables_and_terminals"}
startVariable
-> The variable that is to be used to generate strings
checkForVariables(str);
str
-> The string to check variables in- Returns
true
if the string contains a variable else returnsfalse
getVariables(str);
str
-> The string to get variables from- Returns a list of all variables the string contains
canDecrease(arr);
arr
-> An array containing variables- Returns
true
if any of the variables can be reduced to an empty string else returnsfalse
This class is used to generate a language object
constructor(grammar) {
this.grammar = grammar;
}
grammar
-> A grammar object
generateStringbyLength(n, (currString = null));
n
-> The length of the string- Prints out the strings that satisfy the conditions