I am trying to create a lexical analyzer for a given language. Can't write grammar rules correctly. My task is
The input language contains conditional statements
if ... then ... else
andif ... then
, separated by a symbol;
(semicolon). Condition statements contain identifiers, comparison signs<,>, =
, hexadecimal numbers, sign assignments (:=
). Consider the sequence as hexadecimal numbers digits and symbolsa, b, c, d, e, f
starting with a digit (for example, 89, 45ac, 0abc )
I got these rules:
S -> if E then S else S; S | if E then S; S | if E then S else S | if E then S | I := E
E -> H | E > H | E < H | E = H
I -> LLL
H -> DHL | DL | DH |D
L -> a | b | c | d | e | f
D -> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Is the rule (H -> DHL | DL | D | DH
) for determining hexadecimal numbers set correctly? Are the rest of the rules correct?