require'format/printf' tkref=: tokenize 'End_of_input*/%+--<<=>>===!=!&&||print=print(if{else}while;,putc)a""0' tkref,. (tknames)=: tknames=:;: {{)n End_of_input Op_multiply Op_divide Op_mod Op_add Op_subtract Op_negate Op_less Op_lessequal Op_greater Op_greaterequal Op_equal Op_notequal Op_not Op_and Op_or Keyword_print Op_assign Keyword_print LeftParen Keyword_if LeftBrace Keyword_else RightBrace Keyword_while Semicolon Comma Keyword_putc RightParen Identifier String Integer }}-.LF tkV=: 2 (tkref i.tokenize '*/%+-<<=>>===!=&&||')} (#tktyp)#0 tkV=: 1 (1 0+tkref i.tokenize '-!')} tkV tkPrec=: 13 13 13 12 12 10 10 10 10 9 9 5 4 (tkref i.tokenize'*/%+-<<=>>==!=&&||')} tkV<._1 tkPrec=: 14 (1 0+tkref i.tokenize'-!')} tkPrec NB. proofread |:(<"1 tkV,.tkPrec),tkref,:tknames tkref,.(ndDisp)=: ndDisp=:;:{{)n Sequence Multiply Divide Mod Add Subtract Negate Less LessEqual Greater GreaterEqual Equal NotEqual Not And Or Prts Assign Prti x If x x x While x x Prtc x Identifier String Integer }}-.LF NB. proofread |:tkref,:ndDisp gettoken=: {{ 'tok_ln tok_col'=: (0;ndx){::x 'tok_name tok_value'=: (1;ndx){::x if. 'Error'-:tok_name do. error 'invalid word ',":tok_value end. ind=. tknames i.:y do. q=. 1+tok_precedence [ op=. node_display NB. no right associative operators gettok'' node=. expr q e=. op make_node e node end. e }} expect=: {{ if.y-:tok_name do. gettok'' return.end. error '%s: Expecting "%s", found "%s"'sprintf x;(tkref{::~tknames i.