CSC 231 Test 1 Review - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

CSC 231 Test 1 Review

Description:

Describe the merits of Fortran's implicit variable typing in terms of ' ... Fortran's Implicit Typing: 'If a variable is used without being declared, it is ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 22
Provided by: WakeF
Category:
Tags: csc | fortrans | review | test

less

Transcript and Presenter's Notes

Title: CSC 231 Test 1 Review


1
CSC 231 Test 1 Review
2
Test 1 Review
  • Show a derivation of the string below given this
    grammar. Assume assignment is the start symbol.
  • ltassignmentgt -gt ltidgt ltexpressiongt
  • ltexpressiongt -gt ltexpressiongt ltexpressiongt
  • ltexpressiongt ltexpressiongt
  • (ltexprgt)
  • ltidgt
  • ltidgt -gt A B C
  • String B (AC)

3
Test 1 Review
  • ltassignmentgt
  • ltidgt ltexpressiongt
  • B ltexpressiongt
  • B (ltexpressiongt)
  • B (ltexprgtltexprgt)
  • B (ltidgtltexprgt)
  • B (A ltexprgt)
  • B (A ltidgt)
  • B (A C)

4
Test 1 Review
  • The previous grammar is ambiguous.
  • Show this by finding two different parse trees
    using leftmost derivations for the word A B
    C A

5
Test 1 Review
  • A B C A
  • Derivation 1
  • ltassignmentgt
  • ltidgt ltexprgt
  • A ltexprgt ltexprgt
  • ltidgt ltexprgt lt exprgt
  • B ltidgt ltidgt
  • C A

6
Test 1 Review
  • A B C A
  • Derivation 2
  • ltassignmentgt
  • ltidgt ltexprgt
  • A ltexprgt ltexprgt
  • ltexprgt ltexprgt ltidgt
  • ltidgt ltidgt A
  • B C

Note the difficulty with resolving precedence..
vs.
7
Test 1 Review
  • Trace the execution of the following finite state
    machine on the given input words

0
0
1
1
1
0
S0
S1
S2
S3
S5
0
S4
Word 1 10100 Word 2 1010110
8
Test 1 Review
  • Trace the execution of the following finite state
    machine on the given input words

0
0
1
1
1
0
S0
S1
S2
S3
S5
0
S4
Word 1 10100 S0,S1,S2,S3,S2,S4 accept Word 2
1010110 S0,S1,S2,S3,S2,S3,S5,reject
9
Test 1 Review
  • What is a regular expression for the previous
    FSM?

0
0
1
1
1
0
S0
S1
S2
S3
S5
0
S4
10
Test 1 Review
  • What is a regular expression for the previous
    FSM?
  • 10 ((10)0 1(01) 1) or
  • 10 (10) (011)

0
0
1
1
1
0
S0
S1
S2
S3
S5
0
S4
11
Test 1 Review
  • A. Write a regular expression that generates, in
    binary, any multiple of 4 gt 4 (so 4, 8, 12, 16,
    20, 24, )
  • B. Write a regular expression that generates, in
    binary, any power of 4 gt 4 (so 41 4, 42 16,
    43 64, 44 256, 45 1024,)

12
Test 1 Review
  • A. Write a regular expression that generates, in
    binary, any multiple of 4 gt 4 (so 4, 8, 12, 16,
    20, 24, )
  • 4 100 8 1000 12 1100 16 10000 20 10100
    2411000 28 11100 32 100000 36 100100 40 101000
    gt 1(01)00
  • B. Write a regular expression that generates, in
    binary, any power of 4 gt 4 (so 41 4, 42 16,
    43 64, 44 256, 45 1024,)
  • 100, 10000, 1000000, 100000000 gt 100(00)

13
Test 1 Review
  • Build a finite state machine to recognize all
    powers of 4 gt 4 100(00)

14
Test 1 Review
  • Build a finite state machine to recognize all
    powers of 4 gt 4 100(00)

15
Test 1 Review
  • Convert the following NFA into a DFA

16
Test 1 Review
  • Convert the following NFA into a DFA

17
Test 1 Review
  • Convert the following NFA into a DFA

18
Test 1 Review
  • Compilation vs. Interpretation
  • From what you saw in lab2, state for what types
    of languages is it most common to see
    optimization? Why is that, given the processes
    that occur before execution?
  • Compilation is usually favored over
    interpretation for speed. Suggest two reasons
    that interpreted languages can sometimes be more
    appropriate than compiled languages?

19
Test 1 Review
  • Compilation vs. Interpretation
  • From what you saw in lab2, suggest for what types
    of languages it is most common to see
    optimization? Why is that, given the processes
    that occur for execution?
  • Compiled languages low level code that can be
    re-arranged. Ability to see flow of whole
    program before execution.
  • Compilation is usually favored over
    interpretation for efficiency reasons. Suggest
    reasons that interpreted languages can sometimes
    be more appropriate than compiled languages?
  • Portability
  • Interactive
  • Debugging (errors at high levels, not primitive
    instructions).

20
Test 1 Review
  • Describe the merits of Fortrans implicit
    variable typing in terms of programming
    language quality (readability, writability,
    verifiability, etc.)
  • Fortrans Implicit Typing If a variable is used
    without being declared, it is assumed to be an
    int if the variable name starts with I,J,K,L,M,
    or N otherwise its assumed to be a real

21
Test 1 Review
  • Readability Difficult to understand if not
    familiar with Fortran rules
  • Writability Minimal extra convenience provided
    to programmers
  • Reliability Compiler assumes a particular type,
    gives particular attributes to variable may not
    be able to catch subtle errors (ie wanting to use
    integer division instead of real division,
    mistyped variable so compiler thinks its a real)
Write a Comment
User Comments (0)
About PowerShow.com