From 715d3d48f962d17575ff9de0034f2ac89b59f975 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Wed, 26 Sep 2018 15:29:17 +0300 Subject: Goodbye C compiler, hello colm compiler --- src/compiler/types.lm | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/compiler/types.lm (limited to 'src/compiler/types.lm') diff --git a/src/compiler/types.lm b/src/compiler/types.lm new file mode 100644 index 0000000..34a9026 --- /dev/null +++ b/src/compiler/types.lm @@ -0,0 +1,55 @@ +context number + context unsigned + literal `true `false + token OCT / '0'[0-7]+ / + token DEC / [0-9]+ / + token HEX / '0x' xdigit+ / + int strtoull(a:str, b:int) = c_strtoull + + def type + value:int + [`false] { lhs.value = 0 } + | [`true] { lhs.value = 1 } + | [OCT] { lhs.value = strtoull($r1, 8) } + | [DEC] { lhs.value = strtoull($r1, 10) } + | [HEX] { lhs.value = strtoull($r1, 16) } + end + + lex + ignore / space+ / + literal `+ `- + end + + def type + value:int + [unsigned::type] { lhs.value = r1.value } + | [`- type] { lhs.value = r2.value - (r2.value * 2) } + | [`+ type] { lhs.value = r2.value } +end + +context string + rl ESC / '\\' / + token ESC_CHR / ESC [abfnrtv\\'"e] / + token ESC_HEX / ESC 'x' xdigit{2} / + token ESC_OCT / ESC [0-7]{1,3} / + token CHAR / ^cntrl - ['"] - ESC / + literal `' `" + + def raw + [ESC_CHR] # TODO: how to output raw bytes? + | [ESC_HEX] # TODO: how to output raw bytes? + | [ESC_OCT] # TODO: how to output raw bytes? + | [CHAR] + + def type + length:int + [`' raw:raw* `'] { i:int = 0 for s:raw in r2 i = i + 1 lhs.length = i } + | [`" raw:raw* `"] { i:int = 0 for s:raw in r2 i = i + 1 lhs.length = i } +end + +context name + token NAME / [a-zA-Z_][a-zA-Z_0-9]* / + + def type + [NAME] +end -- cgit v1.2.3