RECURSIVE-DESCENT PARSER FOR PL/0 IN PSEUDO-CODE ------------------------------------------------ procedure PROGRAM; begin GET_TOKEN; BLOCK; if TOKEN <> "." then ERROR end; procedure BLOCK; begin if TOKEN = "const" then begin repeat GET_TOKEN; if TOKEN <> IDENT then ERROR; GET_TOKEN; if TOKEN <> "=" then ERROR; GET_TOKEN; if TOKEN <> NUMBER then ERROR; GET_TOKEN until TOKEN <> ","; if TOKEN <> ";" then ERROR; GET_TOKEN end; if TOKEN = "var" then begin repeat GET_TOKEN; if TOKEN <> IDENT then ERROR; GET_TOKEN until TOKEN <> ","; if TOKEN <> ";" then ERROR; GET_TOKEN end; while TOKEN = "procedure" do begin GET_TOKEN; if TOKEN <> IDENT then ERROR; GET_TOKEN; if TOKEN <> ";" then ERROR; GET_TOKEN; BLOCK; if TOKEN <> ";" then ERROR; GET_TOKEN end; STATEMENT end; procedure STATEMENT; begin if TOKEN = IDENT then begin GET_TOKEN; if TOKEN <> ":=" then ERROR; GET_TOKEN; EXPRESSION end else if TOKEN = "call" then begin GET_TOKEN; if TOKEN <> IDENT then ERROR; GET_TOKEN end else if TOKEN = "begin" then begin GET TOKEN; STATEMENT; while TOKEN = ";" do begin GET_TOKEN; STATEMENT end; if TOKEN <> "end" then ERROR; GET_TOKEN end else if TOKEN = "if" then begin GET_TOKEN; CONDITION; if TOKEN <> "then" then ERROR; GET_TOKEN; STATEMENT end else if TOKEN = "while" then begin GET_TOKEN; CONDITION; if TOKEN <> "do" then ERROR; GET_TOKEN; STATEMENT end end; procedure CONDITION; begin if TOKEN = "odd" then begin GET_TOKEN; EXPRESSION else begin EXPRESSION; if TOKEN <> RELATION then ERROR; GET_TOKEN; EXPRESSION end end; procedure EXPRESSION; begin if TOKEN = ADDING_OPERATOR then GET_TOKEN; TERM; while TOKEN = ADDING_OPERATOR do begin GET_TOKEN; TERM end end; procedure TERM; begin FACTOR; while TOKEN = MULTIPLYING_OPERATOR do begin GET_TOKEN; FACTOR end end; procedure FACTOR; begin if TOKEN = IDENTIFIER then GET_TOKEN else if TOKEN = NUMBER then GET_TOKEN else if TOKEN = "(" then begin GET_TOKEN; EXPRESSION; if TOKEN <> ")" then ERROR; GET_TOKEN end else ERROR end;