Skip to content

Commit 8586696

Browse files
committed
Updated lexer to support prefix notation for integer literals
1 parent a2ab137 commit 8586696

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

compiler/src/Lexer.x

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ import Control.Monad.Except
1616
import Data.Char (isSpace, toLower)
1717
import Data.List (dropWhileEnd)
1818
import Data.Char ( chr )
19-
import Numeric ( readDec )
19+
import Numeric ( readDec, readBin )
2020
import Control.Monad (when)
2121
}
2222

2323
%wrapper "monadUserState"
2424

25+
$bindigit = [01]
26+
$octdigit = 0-7
27+
$hexdigit = [0-9A-Fa-f]
2528
$digit = 0-9
2629
$alpha = [a-zA-Z]
2730
$alpha_ = [$alpha \_]
@@ -110,6 +113,9 @@ tokens:-
110113
<state_dclabel> "#null-confidentiality" { mkL TokenDCNullConf }
111114
<state_dclabel> "#null-integrity" { mkL TokenDCNullInteg }
112115
<0> $digit+ { mkLs (\s -> TokenNum (read s)) }
116+
<0> 0[bB]$bindigit+ { mkLs (\s -> TokenNum (fst (head (readBin (drop 2 s))))) }
117+
<0> 0[oO]$octdigit+ { mkLs (\s -> TokenNum (fst (head (readOct (drop 2 s))))) }
118+
<0> 0[xX]$hexdigit+ { mkLs (\s -> TokenNum (fst (head (readHex (drop 2 s))))) }
113119
<0> [\<][\<] { mkL TokenBinShiftLeft }
114120
<0> [\>][\>] { mkL TokenBinShiftRight }
115121
<0> [\~][\>][\>] { mkL TokenBinZeroShiftRight }

0 commit comments

Comments
 (0)