



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Week 3 – Lexical Analysis
i = i + 1 ; e n d EOF
if forward at end of first half then begin reload second half; forward := forward + 1 end else if forward at end of second half then begin reload first half; move forward to beginning of first half end else forward := forward +
Sentinels: reduce two comparisons to on e.
i = i + 1 ; EOF e n d EOF
forward := forward + if *forward = EOF then begin if forward at end of first half then begin reload second half; forward := forward + 1 end else if forward at end of second half then begin reload first half; move forward to beginning of first half end else terminate lexical analysis
end
(add Line 41 and 42 to recognize names and numbers where digit = {0, 1, 2, …, 9} and letter = {A, B,…, Z, a, b, …, z}) Numeral -> digit+
A technique for separating word symbols and names is to initialize a symbol table with word symbols.
} endif; end;
Procedure nextToken() begin skipSeparator(); switch (ch) {
start (^) [ (^) ]
other
delimiter
return(Bar,BAR)
return(LeftSquare, LSQUARE)
other
case letter: scanWord(); case digit: scanNumeral(); case ‘+’: scanPlus(); … case EOF: return(EOF); end;
procedure skipSeparator() begin while ch in delimiter and ‘{‘ do switch (ch) { case space: nextChar(); case newLine: lineNo++; nextChar(); case tab: nextChar(); case ‘{‘: comment(); } } end;
procedure comment() begin nextChar(); while ch != ‘}’ do if ch = ‘{‘ then comment(); else if ch = newLine then lineNo++; nextChar(); if ch = ‘}’ then nextChar(); else error(“comment”); end;
Searching Linear search Letter indexing Hashing Direct chaining Linear Probing