Compiler/lexical analyzer: Difference between revisions
Content added Content deleted
Line 1,675: | Line 1,675: | ||
03 error-line pic zzzz9 value 0. |
03 error-line pic zzzz9 value 0. |
||
03 error-col pic zzzzzz9 value 0. |
03 error-col pic zzzzzz9 value 0. |
||
03 error-message pic x( |
03 error-message pic x(68) value spaces. |
||
01 scan-state pic x(16) value spaces. |
01 scan-state pic x(16) value spaces. |
||
Line 1,781: | Line 1,781: | ||
move 10 to out-integer |
move 10 to out-integer |
||
when out-value(1:2) = '\\' |
when out-value(1:2) = '\\' |
||
subtract 1 from ord('\') giving out-integer *> ' ( |
subtract 1 from ord('\') giving out-integer *> ' (workaround a Rosetta Code highlighter problem) |
||
when other |
when other |
||
string 'in lexer unknown escape sequence ' out-value(1:2) |
string 'in lexer unknown escape sequence ' out-value(1:2) |
||
Line 1,852: | Line 1,852: | ||
when other |
when other |
||
display input-record |
|||
string 'in lexer ' trim(scan-state) |
string 'in lexer ' trim(scan-state) |
||
' unknown character "' current-character '"' |
' unknown character "' current-character '"' |
||
Line 1,929: | Line 1,930: | ||
end-perform |
end-perform |
||
if scan-state = 'ambiguous' |
if scan-state = 'ambiguous' |
||
evaluate previous-character |
|||
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 |
into error-message |
||
perform report-error |
perform report-error |
||
end-evaluate |
|||
end-if |
end-if |
||
perform read-input-file |
perform read-input-file |
||
Line 2,009: | Line 2,034: | ||
end program lexer.</lang> |
end program lexer.</lang> |
||
{{out|case= |
{{out|case=AllSymbols}} |
||
<pre>prompt$ ./lexer < |
<pre>prompt$ ./lexer <testcase3 |
||
5 16 Keyword_print |
|||
5 40 Op_subtract |
|||
6 16 Keyword_putc |
|||
6 40 Op_less |
|||
7 16 Keyword_if |
|||
7 40 Op_greater |
|||
8 16 Keyword_else |
|||
8 40 Op_lessequal |
|||
⚫ | |||
9 16 Keyword_while |
|||
9 40 Op_greaterequal |
|||
10 16 LeftBrace |
|||
10 40 Op_equal |
|||
11 16 RightBrace |
|||
4 7 String "Print a slash n - \\n.\n" |
|||
11 40 Op_notequal |
|||
12 16 LeftParen |
|||
4 34 Semicolon |
|||
12 40 Op_and |
|||
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}}== |
=={{header|Common Lisp}}== |