-
Notifications
You must be signed in to change notification settings - Fork 1
Parser Specs
At parse-time, sclin recognizes and parses 3 datatypes: NUM
, STR
, and CMD
.
For example:
1 2dup "test"++
Would parse to something like:
NUM(1) NUM(2) CMD(dup) STR(test) CMD(++)
Thanks to this super-simple syntax, sclin is able to parse code linearly - i.e. without backtracking - into a flat list instead of an AST tree. The simple syntax also eliminates any parsing errors, since such checks are instead delegated to runtime.
Are necessary to separate consecutive NUM
s or CMD
s.
1 2.3"asdf""jkl;"++
=> NUM(1) NUM(2.3) STR(asdf) STR(jkl;) CMD(++)
2.3.4
=> NUM(2.3) NUM(.4)
If a CMD
consists entirely of the characters ()[]{}
, then the CMD
splits
into individual characters.
{[]}
=> CMD({) CMD([) CMD(]) CMD(})
When not parsed as part of a number, .
becomes a special form of CMD
. Unlike
other CMD
s, .
does not need whitespace around it to parse as a CMD
. Note
that a trailing decimal after a NUM
is not parsed as part of the NUM
, but
rather as a separate CMD
.
1.2 .3 4.+ "asdf".
=> NUM(1.2) NUM(.3) NUM(4) CMD(.) CMD(+) STR(asdf) CMD(.)
Made with ❤️ by Ben Pang (@molarmanful).