CS 441G Fall 2018 Exam 1 Matching: match the best term from the following list to its definition by writing the LETTER of the term in the blank to the left of the definition. All 31 definitions are given on this practice exam. It will probably be reduced to 20 definitions but with all 31 terms to match on the actual exam. A Accepts L Lexeme W Rejects B Assembly M Lexical X Scanner C Code Generator N Linear Bounded Y Source D Compiler O Machine Code Z String Table E Constrainer P Non-Deterministic AA Symbol Table F Deterministic Q Non-Terminals AB Target G Finite State R Optimization AC Terminal H Goal (or Start) S Parser AD Token I Grammar T Phrase/Structure AE Turing Machine J High Level Language U Productions K Interpreter V Push Down D 1. software that translates a program written in a source file into a program stored in a target file, reporting errors when found. Y 2. program written in a High Level Language AB 3. program translated into a Low Level Language, usually Assembly, Machine Code or Virtual Machine Code. K 4. software that translates statements of a source (usually) one statement at a time into Machine Code, then executes the translated statement before translating/executing the next. O 5. binary representation simple commands - differs by CPU model knowledge of the CPU/HW required to program in this language. B 6. text representation simple commands (usually 1:1 with Machine Code) - differs by CPU model - knowledge of the CPU/HW required to program in this language. J 7. has more-complex commands translates 1:many Machine Code instructions same language across CPU models and Operating Systems (with some minor differences) in depth knowledge of the CPU/HW not required to program in these languages. X 8. reads a source, character by character, extracting lexemes that are then represented by tokens. S 9. extracts tokens from the Scanner and builds an Abstract Syntax Tree of the tokens, based on the rules of the language. E 10. adds context-sensitive and other information to the tokens of the AST produced by the Parser, producing a Decorated Abstract Syntax Tree. This DAST represents the full meaning (Semantics) of the source program being translated.
C 11. given the DAST produced by the Constrainer, writes code in the Target Language with the same meaning (semantics) as the source program. Z 12. stores the exact spelling of identifiers and literals discovered by the scanner. AA 13. stores semantic information on tokens. L 14. the string representation of a single word or symbol extracted from the source. AD 15. simplified (integer) representation of a Lexeme. It may be an object/structure containing members/fields describing a single word or symbol from the source. R 16. changes to the DAST and/or Target Code generated to make the Target program more efficient. I 17. defines the correct forms of sentences (programs) of a language. M 18. Grammar defines the correct forms for Lexemes in terms of characters. T 19. Grammar that defines the correct formation of tokens into sentences (programs) for the language. AC 20. individual word/symbol/character that can be used to create sentences (programs) in a language (Alphabet) Q 21. a symbols that represent possible combinations of words/symbols/characters in a language U 22. a set of rules where each rule specifies a string of terminals/non-terminals that can substitute for another set of terminals/non-terminals H 23. a special Non-Terminal that represents all possible valid sentences (programs) in a language. F 24. describes a grammar where, for any given situation, only one production may be chosen as a substitution. P 25. describes a grammar where, for at least one situation, two or more productions may be chosen as a substitution. A 26. Action of a grammar when a derivation can be found for a sentence W 27. Action of a grammar when a derivation can NOT be found for a sentence AE 28. automata that has an infinite tape, can read/write/advance/rewind its tape, and uses an Unrestricted grammar.
N 29. automata that has a finite tape, can read/write/advance/rewind its tape, and uses a Context Sensitive grammar. V 30. automata that has a finite tape, can only read its tape, and only one time, and uses a Stack to implement a Context Free Grammar. G 31. automata that has a finite tape, can only read its tape, and only one time, and uses a Regular Grammar 32. Draw and label the Structure of a Compiler Diagram, including - The four major components (label with their name) - The input/output files (label with their name) - The two major data structures (tables) (label with their name) - Arrows showing the flow of information (label with the information transferred) Answer: 33. Draw a diagramof the results of inserting items into a Hash Table as coded for Proj. 2. - items consist of only digits - hash function: sums the digits and mods by 10. Ex: hash(441441) = 4+4+1+4+4+1 = 18; 18 mod 10 = 8 - the hash table is an array of 10 buckets, indexed 0-9. - each bucket is a linked list of nodes - collisions are attached at the end of the linked list. Insert in order: 441441 12345 54321 007 99 102 430 Note: a slightly different hash function may be used on the exam Answer to the right
34. Complete the following table of the Chomsky Hierarchy, where Class 0 is the least restrictive classification. For the Production column, give an example of a grammar production for the class that would not satisfy the requirements of a higher class. Use lower-case letters for terminals and upper-case letters for non-terminals. (do not answer with an empty production, even though that would be correct in some cases). Level Grammar Recognizer Production Example 0 Unrestricted Turing Machine abcxy d 1 Context Sensitive Linear Bounded Automata axb cdyzef 2 Context Free Push Down Automata X ayczd 3 Regular Finite State Automata X ay 35. List and describe the four elements of the formal definition of a General Grammar: - set of terminals (alphabet) N set of non-terminals P set of productions S Goal Symbol S N 35. Draw an FSA (graphical form) for string literals in C/C++ (simplified). The rules are: - must start and end with a double quote - may contain \ to represent the quote character, and \\ to represent the \ character. - \<anything else> is considered invalid (an error) - must not contain an EOF character. - use to represent all characters other than EOF, double quote, and backslash - you may use empty productions if you wish Answer:
36. Given the following graphical FSA, write the formal/mathematical definition of the language. Use the (N,t) = N format to write the productions. Answer: = { a, b, c, d, e, f } Q = { S, X, Y, Z } = { (S,a) = X, (X,b) = X, (X,e) = X (X,d) = Z, (X,c) = Y, (Y,c) = Y (Y,f) = Z } q0 = S F = { Z } 37. Given the FSA in #36, rewrite the productions using LHS RHS format. S ax or, removing Z S ax X bx X bx X ex X ex X dz X d X cy X cy Y cy Y cy Y fz Y f Z 38. Using the productions in #37, draw or write a derivation showing the sentence abbccf is accepted by the language. S Start ax S ax abx X bx abbx X bx abbcy X cy abbccy Y cy abbccfz Y fz or Y f and drop the last step abbccf Z 39. Given the FSA in #36, express the FSA in Table Form. Mark halt states with * a b c d e f S X X X Y Z X Y Y Z Z*
40. Using the FSA in #36, write a Regular Expression to define the language. Use only the formal metasymbols used in class do not use symbols from computing languages, etc. Alternative correct answers (there are others): a(b e) * (d c + f) a(b e) * (d (cc * f)) cc * is equivalent to c + a(b e) * (d (c + f)) concatenation of c + f overrides the, but adding parens is OK 41. Write the Algorithm for implementing an FSA. Assume productions and halt states are somehow identified. Use readchar() to represent reading the next character from the input file, and that it returns an EOF character at the end of file. state = start c = readchar() while c!=eof and state!= error { state = get production based on state and c to get the next state if no production found state = error else c = readchar() } if c==eof and state is a halt state ACCEPT else REJECT