String manipulation in Javalette By Daniel Boström and Sebastian Salman http://www.dtek.chalmers.se/~salman/javalette/
Adding String Manipulation to Javalette ● Original version of Javalette lacked string handling. ● Only support for strings was using the hardcoded printString(“...”) function. ● No support for comparing strings or manipulating them.
New String features ● Variables of type String can now be declared. ● Functions can accept parameters of the type String. ● Strings can be compared to each other (!= == < <= > >=). ● Strings can be compared to integers (will compare with the length of the string).
More features ● Possible to look for a matching sub string with the / operator: boolean b = (“x” / “xyz”); ● Strings can be added like: String s = “aoeu”+”htns”;
Regular Expressions ● How to interpret and check the regex? ● Using Non-deterministic Finite Automata. ● Run the NFA with the string as input.
The NFA ● Three basic building blocks – Concatenation ● ab – Alternation ● a|b – Star (Kleen closure) ● a* ● Using these, other rules can be formed – a+ => aa*
Examples int main() { printBool( regex_matches(“aab”, “aab”) ); //true printBool( regex_matches(“a*b”, “b”) ); //true printBool( regex_matches(“a+b”, “b”) ); //false return 0; }
Recommend
More recommend