parsing primitive | PASM syntax | comment | |||
define a parsing rule | = xxx | followed by parsing rules ; parsing rules consist of the PASM syntax shown below | |||
define a parsing predicate | - <xxx> | followed by parsing rules ; must return ^ok or ^fail | |||
accept a character | 'c’ | ||||
lookahead one character | ?’c’ | ||||
accept a token | KIND | Token kind (class) in upper case | |||
accept a token with given string as its text | KIND/str | Token kind in upper case, token text verbatim (case matters) as str | |||
accept any token | . | ||||
lookahead one token | ?KIND | ||||
lookahead one token with given string as its text | ?KIND/str | ||||
call a parsing rule | @<xxx> | ||||
call a parsing predicate | &<xxx> | ||||
call an external mechanism (function) | <xxx> | ||||
cycle | { | ||||
exit cycle | > | ||||
return success from a parsing predicate | >> ^ok | ||||
return failure from a parsing predicate | >> ^fail | ||||
return from a parsing rule (no value) | >> | ||||
begin choice | [ | followed by a parsing predicate then parsing rules ; the first choice which returns ^ok is evaluated | |||
choice alternate | | | ||||
end choice | ] | ||||
always succeed | * | usually used as ‘otherwise’ in a choice | |||
call filter | ~<xxx> | filter operation - call rule <xxx> for every input token, if ‘accepted-token’ and ‘next-token’ are the same as before the filter operation, accept once (thereby advancing the stream), else save the newly accepted token onto a list of new tokens ==> i.e. filter the token stream, using a rule that creates one accepted token at a time, throw away tokens that were not accepted (see example of rmspaces in dsl0.pasm https://github.com/bmfbp/bmfbp/blob/v2emitter/build_process/esa-transpiler/dsl0.pasm (which removes ( / filters out) whitespace tokens)) | |||
N.B. parser has one character in lookahead position and one in accepted position | |||||
N.B. see https://github.com/guitarvydas/parsing-assembler for an implementation (the name means “assembly language for parsing”) | |||||
see | |||||
https://en.wikipedia.org/wiki/S/SL_programming_language
| |||||
source code https://research.cs.queensu.ca/home/cordy/pub/downloads/ssl/ | |||||