Skip to content

Parser Specs

molarmanful edited this page Nov 4, 2023 · 8 revisions

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.

Spaces

Are necessary to separate consecutive NUMs or CMDs.

1 2.3"asdf""jkl;"++
=> NUM(1) NUM(2.3) STR(asdf) STR(jkl;) CMD(++)
2.3.4
=> NUM(2.3) NUM(.4)

Parentheses/Brackets

If a CMD consists entirely of the characters ()[]{}, then the CMD splits into individual characters.

{[]}
=> CMD({) CMD([) CMD(]) CMD(})

Dot

When not parsed as part of a number, . becomes a special form of CMD. Unlike other CMDs, . 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(.)