Compiler/lexical analyzer: Difference between revisions
Content added Content deleted
m (→{{header|C++}}: fix warning) |
(Added missing “next()” for operators with two characters (<=, >=, ==, !=, &&, ||).) |
||
Line 6,322:
type
TokenKind* = enum
tokMult = "Op_multiply", tokDiv = "Op_divide", tokMod = "Op_mod",
Line 6,337 ⟶ 6,338:
tokString = "String"
tokEnd = "End_of_input"
Token* = object
ln*, col*: int
Line 6,345 ⟶ 6,347:
of tokString: stringVal*: string
else: discard
Lexer* = object
input: string
pos: int
ln, col: int
LexicalError* = object of CatchableError
ln*, col*: int
Line 6,420 ⟶ 6,424:
of '>':
next()
if current() == '=':
next()
else:
result = Token(kind: tokGreater)
of '=':
next()
if current() == '=':
next()
else:
result = Token(kind: tokAssign)
of '!':
next()
if current() == '=':
next()
else:
result = Token(kind: tokNot)
of '&':
next()
if current() == '&':
result = Token(kind: tokAnd)
else: lexer.error("'&&' expected")▼
next()
else:
of '|':
next()
if current() == '|':
result = Token(kind: tokOr)
else: lexer.error("'||' expected")▼
next()
else:
of '(': result = Token(kind: tokLPar); next()
of ')': result = Token(kind: tokRPar); next()
|