Compiler/lexical analyzer: Difference between revisions

Line 1,675:
03 error-line pic zzzz9 value 0.
03 error-col pic zzzzzz9 value 0.
03 error-message pic x(6468) value spaces.
 
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 *> ' (highlighterworkaround issue ona Rosetta Code highlighter problem)
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'
string 'in lexer unresolved ambiguous "'evaluate previous-character '" at end of line'
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=TestCase4AllSymbols}}
<pre>prompt$ ./lexer <testcases/TestCase4testcase3
25 116 Keyword_print
25 40 6 LeftParenOp_subtract
26 16 7 Integer 42Keyword_putc
26 40 9 RightParenOp_less
27 1016 SemicolonKeyword_if
37 40 1 Keyword_printOp_greater
38 16 6 LeftParenKeyword_else
8 40 Op_lessequal
3 7 String "\nHello World\nGood Bye\nok\n"
39 3816 RightParenKeyword_while
39 3940 SemicolonOp_greaterequal
10 4 16 1 Keyword_printLeftBrace
10 4 40 6 LeftParenOp_equal
11 16 RightBrace
4 7 String "Print a slash n - \\n.\n"
11 4 40 33 RightParenOp_notequal
12 16 LeftParen
4 34 Semicolon
12 5 40 1 End_of_input</pre>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
18 3 740 String "\nHello World\nGoodString Bye\nok\nliteral"
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}}==
Anonymous user