Understanding Variables, Instance Variables, and Semantic Errors in Programming, Exams of Computer Science

An analysis of the abstract syntax tree (ast) of a programming code snippet, focusing on variables, instance variables, and semantic errors. It covers the structure of class variables, array variables, and instance variables, as well as common semantic errors such as type mismatches, structured variable errors, function and method errors, and access violation errors.

Typology: Exams

Pre 2010

Uploaded on 07/30/2009

koofers-user-7lp
koofers-user-7lp 🇺🇸

10 documents

1 / 201

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Compilers
CS414-2008-FR
Final Review
David Galles
Department of Computer Science
University of San Francisco
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Understanding Variables, Instance Variables, and Semantic Errors in Programming and more Exams Computer Science in PDF only on Docsity!

Compilers CS414-2008-FRFinal Review

David Galles Department of Computer ScienceUniversity of San Francisco

FR-0:

Deterministic Finite Automata Set of states Initial State Final State(s) Transitions

DFA for else, end, identifiersCombine DFA

FR-2:

Automatic Creation of DFAs

We’d like a tool:

Describe the tokens in the language Automatically create DFA for tokens Then, automatically create C code that implementsthe DFA We need a method for describing tokens

FR-3:

Formal Languages Alphabet

Σ: Set of all possible symbols

(characters) in the input file

Think of

Σ^

as the set of symbols on the

keyboard String

w: Sequence of symbols from an alphabet String length

|w

|^ Number of characters in a

string:

|car

|^ = 3,

|abba

|^ = 4

Empty String

ǫ: String of length 0:

|ǫ|

Formal Language

: Set of strings over an

alphabet Formal Language

6 =^

Programming language – Formal

Language is only a set of strings.

FR-5:

Language Concatenation Language Concatenation

Given two formal

languages

L^1

and

L^2

, the concatenation of

L^1

and

L,^2

L^1

L^2

=^ {

xy|

x^ ∈

L^1

, y^

∈^ L

For example:{fire, truck, car} {car, dog} ={firecar, firedog, truckcar, truckdog, carcar, cardog}

FR-6:

Kleene Closure

Given a formal language

L:

0 L

=^

{ǫ} (^1) L =^

L

2 L

=^

LL

3 L

=^

LLL

4 L

=^

LLLL∗^ L=

0 L

1 L

⋃^

2 L

⋃^

...^

⋃^

n^ L

⋃^

FR-8:

r.e. Precedence

From highest to Lowest:Kleene Closure *ConcatenationAlternation

ab*c

|e = (a(b*)c)

|^ e

FR-9:

Regular Expression Examples

(a|b)*

all strings over {a,b}

binary integers (with leading zeroes)

a(a

|b)*a

all strings over {a,b} thatbegin and end with a

(a|b)*aa(a

|b)*

all strings over {a,b} thatcontain aa

b(abb)*(a

|ǫ)^

all strings over {a,b} thatdo not contain aa

FR-11:

r.e. Shorthand Examples Regular Expression

Language if^ {if}

["a"-"z"]["0"-"9","a"-"z"]*

Set of legal identifiers

["0"-"9"]+

Set of integers (with leading zero

(["0"-"9"]+"."["0"-"9"]*)

|^ Set of real numbers

(["0"-"9"]*"."["0"-"9"]+)

FR-12:

Parsing Once we have broken an input file into a sequenceof tokens, the next step is to determine if thatsequence of tokens forms a syntactically correctprogram – parsing We will use a tool to create a parser – just like weused lex to create a parser We need a way to describe syntactically correctprograms^ Context-Free Grammars

FR-14:

Generating Strings with CFGs Start with the initial symbol Repeat:^ Pick any non-terminal in the string^ Replace that non-terminal with the right-handside of some rule that has that non-terminal asa left-hand sideUntil all elements in the string are terminals

FR-15:

CFG Example

E^ →

E^

+^ E

E^ →

E^

−^ E

E^ →

E^

∗^ E

E^ →

E/E

E^ →

num

FR-17:

Ambiguous Grammars A Grammar is

ambiguous

if there is at least one

string with more than one parse tree The expression grammar we’ve seen so far isambiguous E^ →

E^

+^ E

E^ →

E^

−^ E

E^ →

E^

∗^ E

E^ →

E/E

E^ →

num

FR-18:

Expression Grammar

E^ →

E^

+^ T

E^ →

E^

−^ T

E^ →

T

T^ →

T^

∗^ F

T^ →

T /F

T^ →

F

F^ →

num F^ →

(E