RosettaCodeData/Task/Compiler-lexical-analyzer/Phix/compiler-lexical-analyzer-5.phix
2026-02-01 16:33:20 -08:00

24 lines
674 B
Text

-- demo\rosetta\Compiler\lex.exw
with javascript_semantics
include lex.e
procedure main(sequence cl)
open_files(cl)
sequence toks = lex()
integer tok
object v
for i=1 to length(toks) do
{tok_line,tok_col,tok,v} = toks[i]
switch tok do
case tk_Identifier: v = sprintf(" %s",v)
case tk_Integer: v = sprintf(" %5d",v)
case tk_String: v = sprintf(" %s",enquote(v))
else v = ""
end switch
printf(output_file, "%5d %5d %-10s%s\n", {tok_line,tok_col,tkNames[tok],v})
end for
close_files()
end procedure
--main(command_line())
main({0,0,"test4.c"})