Compiler/lexical analyzer: Difference between revisions
Content added Content deleted
(Added another Nim example, using only system and a bit of strutils) |
(Fixed my Nim example) |
||
Line 5,145:
===Using nothing but system and strutils===
<lang nim>import strutils
type
Line 5,329 ⟶ 5,328:
when isMainModule:
var
lexer = initLexer(
token: Token
while true:
token = lexer.next()
stdout.write(token.ln, ' ', token.col, ' ', token.kind)
of tokInt: stdout.write(' ', token.intVal)
of tokChar: stdout.write(' ', token.charVal.ord)
of tokString: stdout.write(" \"", token.stringVal
.replace("\\", "\\\\")
.replace("\n", "\\n"), '"')
of tokIdent: stdout.write(' ', token.ident)
else: discard
stdout.write('\n')
if token.kind == tokEnd:
break</lang>
=={{header|Perl}}==
|