npc

nanohard parser compiler
git clone git://git.kocotian.pl/npc.git
Log | Files | Refs

commit f35994746aca26b413f463de36253eebe95085ee
Author: kocotian <kocotian@kocotian.pl>
Date:   Fri,  9 Apr 2021 21:07:26 +0200

npc syntax prototype wrote in npc prototype file

Diffstat:
Anpc.npc | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 81 insertions(+), 0 deletions(-)

diff --git a/npc.npc b/npc.npc @@ -0,0 +1,81 @@ +;; npc syntax file, version 0.1 + +;; >>> Functions <<< + +define function char(c) => condition: $ichr == c; +define function charFrom(c) => condition: $ichr >= c; +define function charTo(c) => condition: $ichr <= c; +define function charAny() => condition: $ichr; +define function charBetween(c1, c2) => condition: @charFrom(c1) && @charTo(c2); + +;; >>> Tokens <<< + +;; Literals + +define token Number + match until true charBetween('0', '9'); + +define token Identifier + match (charBetween('a', 'z') or charBetween('A', 'Z')) then until true + (charBetween('a', 'z') or charBetween('A', 'Z') or charBetween('0', '9')); + +define token Character + match char(''') then charAny() then char('''); + +define token String + match char('"') then until false char('"'); + +;; Operators + +define token Assignment + match char('=') then { + define token LogicalEqual match char('='); + }; + +define token Plus + match char('+') then { + define token PlusEqual match char('='); + define token Increment match char('+'); + }; + +define token Minus + match char('-') then { + define token MinusEqual match char('='); + define token Decrement match char('-'); + }; + +define token Or + match char('|') then { + define token LogicalOr match char('|'); + }; + +define token And + match char('&') then { + define token LogicalAnd match char('&'); + }; + +define token Exclamation + match char('!') then { + define token LogicalNotEqual match char('='); + }; + +define token Semicolon + match char(';') then { + define token Comment match char(';'); + }; + +;; Brackets + +define token OpeningParenthesis match char('('); +define token ClosingParenthesis match char(')'); +define token OpeningBracket match char('['); +define token ClosingBracket match char(']'); +define token OpeningBrace match char('{'); +define token ClosingBrace match char('}'); + +;; Other tokens + +define token Colon match char(':'); +define token Comma match char(','); +define token At match char('@'); +define token Dollar match char('$');