COP 4555 Lecture 1: COP4555 HW1 Solutions

471 views4 pages
Published on 4 Jun 2015
School
Course
Professor
Problem1(5points)(Basicknowledgeofprogrammingerrors)Exercise1.1onPage
36.
Errorsinacomputerprogramcanbeclassifiedaccordingtowhentheyaredetectedand,if
theyaredetectedatcompiletime,whatpartofthecompilerdetectsthem.Usingyourfavorite
imperativelanguage,giveanexampleofeachofthefollowing.
InJava:
(a)Alexicalerror,detectedbythescanner
Whetheratokenispermitedornot.
Anexampleofalexicalerrorinjavacouldbeusinganinvalididentifier(e.g.intvar*)
(b)Asyntaxerror,detectedbytheparser
Themissingofasemicolon(;)attheendofastatement
(c)Astaticsemanticerror,detectedbysemanticanalysis
Useafloatasanindexofanarray.
(d)Adynamicsemanticerror,detectedbycodegeneratedbythecompiler
Gettingindexoutofboundonanarray
(e)Anerrorthatthecompilercanneithercatchnoreasilygeneratecodetocatch(thisshould
beaviolationofthelanguagedefinition,notjustaprogrambug)
Usethenameofamethodasavariable
Problem2(5points)(Regularexpressionandscanning)Exercise2.1(f)onPage103.
Writeregularexpressionstocapture:
FinancialquantitiesinAmericannotation.Thesehavealeadingdollarsign($),anoptional
stringofasterisks(*—usedoncheckstodiscouragefraud),astringofdecimaldigits,andan
optionalfractionalpartconsistingofadecimalpoint(.)andtwodecimaldigits.Thestringof
digitstotheleftofthedecimalpointmayconsistofasinglezero(0).Otherwiseitmustnot
startwithazero.Iftherearemorethanthreedigitstotheleftofthedecimalpoint,groupsof
three(countingfrom
theright)mustbeseparatedbycommas(,).Example:$**2,345.67.(Feelfreetouse
“productions”todefineabbreviations,solongasthelanguageremainsregular.)
digitwithoutzero→1|2|3|4|5|6|7|8|9
digit→0|digitwithoutzero
groupofthree→,digitdigitdigit
number→$**(0|digitwithoutzero( |digit|digitdigit)groupofthree*)( |.digitdigit)ε ε
number→$**(0|digitwithoutzero( |digit|digitdigit)(,digitdigitdigit)*)( |.digitε ε
digit)
Unlock document

This preview shows page 1 of the document.
Unlock all 4 pages and 3 million more documents.

Already have an account? Log in

Get OneClass Grade+

Unlimited access to all notes and study guides.

YearlyMost Popular
75% OFF
$9.98/m
Monthly
$39.98/m
Single doc
$39.98

or

You will be charged $119.76 upfront and auto renewed at the end of each cycle. You may cancel anytime under Payment Settings. For more information, see our Terms and Privacy.
Payments are encrypted using 256-bit SSL. Powered by Stripe.