diff options
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | Sil/Parse.icl | 6 | ||||
-rw-r--r-- | examples/fib.sil | 5 | ||||
-rw-r--r-- | vim/syntax/sil.vim | 5 |
4 files changed, 22 insertions, 1 deletions
@@ -14,7 +14,9 @@ or can be interpreted with the [ABCMachine][abc-github] project. <CodeBlock> ::= <Initialisation>-list <Statement>-list -<Initialisation> ::= <Type> <Name>-clist ';' +<Initialisation> ::= <Type> <InitName>-clist ';' + +<InitName> ::= <Name> [':=' <Expression>] <Statement> ::= [<Name> ':='] <Expression> ';' | 'return' [<Expression>] ';' @@ -41,6 +43,9 @@ or can be interpreted with the [ABCMachine][abc-github] project. <Int> ::= <Digit>-list ``` +Comments (single-line `//`, multi-line `/* ... */`) are not included in the +grammar above. + ## Dependencies You need a working Clean installation to build the compiler and at least `clm` diff --git a/Sil/Parse.icl b/Sil/Parse.icl index d5c97ef..b5e0114 100644 --- a/Sil/Parse.icl +++ b/Sil/Parse.icl @@ -68,6 +68,12 @@ tokenise cs = reverse <$> tks cs [] where tks :: [Char] [Token] -> MaybeError ParseError [Token] tks [] t = pure t + tks ['/':'/':r] t = tks (dropWhile ((<>) '\n') r) t + tks ['/':'*':r] t = tks (skipUntilEndOfComment r) t + where + skipUntilEndOfComment [] = [] + skipUntilEndOfComment ['*':'/':r] = r + skipUntilEndOfComment [_:r] = skipUntilEndOfComment r tks [':':'=':r] t = tks r [TAssign :t] tks ['=':'=':r] t = tks r [TDoubleEquals :t] tks ['|':'|':r] t = tks r [TDoubleBar :t] diff --git a/examples/fib.sil b/examples/fib.sil index db66783..4a218ed 100644 --- a/examples/fib.sil +++ b/examples/fib.sil @@ -1,8 +1,13 @@ +/** + * The Fibonacci function + */ Int fib(Int n) { + // Base cases if (n == 1) { return 1; } else if (n == 2) { return 1; + // Recursive case } else { return fib(n - 1) + fib(n - 2); } diff --git a/vim/syntax/sil.vim b/vim/syntax/sil.vim index 7797177..8ccb92a 100644 --- a/vim/syntax/sil.vim +++ b/vim/syntax/sil.vim @@ -22,6 +22,9 @@ syn keyword silBool True False syn match silABC "|\~.*$" contains=@ABC transparent +syn region silComment start="//" end="$" contains=@Spell oneline display +syn region cleanComment start="/\*" end="\*/" contains=@Spell fold keepend extend + hi def link silConditional Conditional hi def link silStatement Statement hi def link silType Type @@ -31,6 +34,8 @@ hi def link silOperator Operator hi def link silInteger Number hi def link silBool Boolean +hi def link silComment Comment + let b:current_syntax = 'sil' let &cpo = s:cpo_save |