Compiler/lexical analyzer: Difference between revisions

Added missing “next()” for operators with two characters (<=, >=, ==, !=, &&, ||).
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() == '=': result = Token(kind: tokGreaterEq)
else: result = Token(kind: tokGreatertokGreaterEq)
next()
else:
result = Token(kind: tokGreater)
of '=':
next()
if current() == '=': result = Token(kind: tokEq)
else: result = Token(kind: tokAssigntokEq)
next()
else:
result = Token(kind: tokAssign)
of '!':
next()
if current() == '=': result = Token(kind: tokNotEq)
else: result = Token(kind: tokNottokNotEq)
next()
else:
result = Token(kind: tokNot)
of '&':
next()
if current() == '&': result = Token(kind: tokAnd)
result = Token(kind: tokAnd)
else: lexer.error("'&&' expected")
next()
else:
else: lexer.error("'&&' expected")
of '|':
next()
if current() == '|': result = Token(kind: tokOr)
result = Token(kind: tokOr)
else: lexer.error("'||' expected")
next()
else:
else: lexer.error("'||' expected")
of '(': result = Token(kind: tokLPar); next()
of ')': result = Token(kind: tokRPar); next()
Anonymous user