Analysis 4 code generation lex syn

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ular Expressions • (visual- based) Deterministic Finite Automaton 3. Regular Expressions (review) To create a regular expression there is needed an alphabet, and then a way to integrate the characters on the alphabet (operations). There are four operations to know when working with regular expressions: Union or alternation Concatenation Zero or more (Kleene operator) One or more (+) Example 1. Imagine that we are defining the patterns for a language P1 = {5} P2 = {0 - 9} = {0, 1, …, 9} Using these patterns we can review the following words and try to find their type. 5 – this is a token that follows pattern P1 8 – this is a token that follows pattern P2 80 – according with the previous patterns (P1 and P2) it is not a token Now if we modify P2 and add P3 as follows: P1 = {5} P2 = {0, 1, …, 9} + P3 = {a, b, c, d} + 5 – still follows P1 8 – still follows P2 80 – now this is a token that follows pattern P2 ab – is a token that follows pattern P3 abba – is a token that follows pattern P3 4. Deterministic Finite Automaton (review) Patterns could be expressed using regular expressions or using a Deterministic Finite Automaton (DFA). The P1 pattern above would look as follow if expressed using a DFA. P1. Remember that in a DFA the “Star” label shows the starting point, the double- lined circle represents the final state, and the values on the arrows represent the value that needs to be as input to move from one state to another. So for P1 = {5} the DFA will be: Start P1 5 When using a DFA to evaluate if a word follows a valid pattern, when all the characters in the word are processed you need to get into the final state (double- circled state). Now if we want to define the pattern for integer numbers. The regular expression is: 0 | (1- 9)(0- 9)* And the DFA will be: 0 Start 1- 9 0- 9...
View Full Document

This note was uploaded on 09/29/2013 for the course CSE 340 taught by Professor Richa during the Spring '13 term at Arizona State University.

Ask a homework question - tutors are online