-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathex1.nim
More file actions
33 lines (30 loc) · 762 Bytes
/
ex1.nim
File metadata and controls
33 lines (30 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
discard """
output: '''
an identifier the##
something else ##
an integer 0909##
something else ##
an ELSE
something else ##
an identifier input##
something else ##
an ELIF
something else ##
an identifier elseo##
something else ##
an END'''
"""
import lexim
proc main =
var input = "the 0909 else input elif elseo end"
var pos = 0
while pos < input.len:
let oldPos = pos
match input, pos:
of r"\d+": echo "an integer ", input.substr(oldPos, pos-1), "##"
of "else": echo "an ELSE"
of "elif": echo "an ELIF"
of "end": echo "an END"
of r"[a-zA-Z_]\w+": echo "an identifier ", input.substr(oldPos, pos-1), "##"
of r".": echo "something else ", input.substr(oldPos, pos-1), "##"
main()