Anonymous user
Compiler/lexical analyzer: Difference between revisions
→{{header|COBOL}} Updated to use the commonly listed test case 3
Line 1,675:
03 error-line pic zzzz9 value 0.
03 error-col pic zzzzzz9 value 0.
03 error-message pic x(
01 scan-state pic x(16) value spaces.
Line 1,781:
move 10 to out-integer
when out-value(1:2) = '\\'
subtract 1 from ord('\') giving out-integer *> ' (
when other
string 'in lexer unknown escape sequence ' out-value(1:2)
Line 1,852:
when other
display input-record
string 'in lexer ' trim(scan-state)
' unknown character "' current-character '"'
Line 1,929 ⟶ 1,930:
end-perform
if scan-state = 'ambiguous'
when '/'
move 'Op_divide' to token
perform process-token
when '='
move 'Op_assign' to token
perform process-token
when '<'
move 'Op_less' to token
perform process-token
when '>'
move 'Op_greater' to token
perform process-token
when '!'
move 'Op_not' to token
perform process-token
when other
string 'in lexer unresolved ambiguous
"' previous-character '" at end of line'
into error-message
perform report-error
end-evaluate
end-if
perform read-input-file
Line 2,009 ⟶ 2,034:
end program lexer.</lang>
{{out|case=
<pre>prompt$ ./lexer <
8 40 Op_lessequal
3 7 String "\nHello World\nGood Bye\nok\n"▼
10
10
11 16 RightBrace
11
12 16 LeftParen
12
13 16 RightParen
13 40 Op_or
14 16 Op_subtract
14 40 Semicolon
15 16 Op_not
15 40 Comma
16 16 Op_multiply
16 40 Op_assign
17 16 Op_divide
17 40 Integer 42
18 16 Op_mod
19 16 Op_add
19 40 Identifier variable_name
20 26 Integer 10
21 26 Integer 92
22 26 Integer 32
23 1 End_of_input</pre>
=={{header|Common Lisp}}==
|