lex start2 { ignore /space+/ literal '#', '{', '}' token id2 /[a-zA-Z_]+/ } def item2 [id2] | ['{' item2* '}'] def start2 [item2*] context ctx { lex start { ignore /space+/ literal '*', '(', ')', '!', ';\n' token id /[a-zA-Z_0-9]+/ token ddd /'...'/ { print('translating\n') input.pull( match_length ) input.push( make_token( typeid id "dot" ) ) input.push( make_token( typeid id "dot" ) ) input.push( make_token( typeid id "dot" ) ) } } def item [id] | ['(' item* ')'] def A [] { print( 'A\n' ) } def B [] { print( 'B\n' ) } def start [A item* '!'] | [B item* ';\n'] } CTX: ctx = cons ctx [] Input: ctx::start = parse ctx::start( CTX stdin ) print( Input )