Thomas W. Christopher | Consulting in High Performance Computing. Training in Concurrency, Networking, and Parallelism, especially in Python and Java. |
[ Internet Explorer may havea problem with the Applet. If so, you will need to download and install j2re Java plug-in from http://java.sun.com/ .]
This applet demonstrates look-ahead. The BACKUP symbols cause the parser to back up the input before continuing.
Try typing into the "input line," followed by ENTER:
A:B=1;
L:K:if e then if f then A:b else C;
fiducials: ";" then else. start = labeled_statement . labeled_statement = label statement STMT! . label = NULL_LABEL! { id ":" LABEL!}. statement = v "=" e ";" ASGN! . statement = e ";" EXPRSTMT! . statement = if e then labeled_statement IFTHEN! . statement = if e then labeled_statement else labeled_statement IFTHENELSE! . e = e "+" t ADD! . e = e "-" t SUB!. e = t . t = f "*" t MPY!. t = f "/" t DIV!. t = f "%" t MOD!. t = f . f = v FETCH! . f = num CVTNUM!. f = "(" e ")" PARENS!. f = id "(" e ")" CALL!. f = "-" f NEG!. v = id LOOKUPID!. v = v "[" e "]" SUBSCR!. v = v "." id FIELD!.
e = t "e:101". "e:101" = "+" t ADD "e:101". "e:101" = "-" t SUB "e:101". "e:101" =. f = id "f:103". f = "f:105". "f:103" = "(" e ")" CALL. "f:103" = LOOKUPID "v:102" FETCH. "f:105" = num CVTNUM. "f:105" = "(" e ")" PARENS. "f:105" = "-" f NEG. label = NULL_LABEL "label_6_21:109". "label_6_21:109" = id "label_6_21:110". "label_6_21:109" = "(" BACKUP. "label_6_21:109" = "-" BACKUP. "label_6_21:109" = num BACKUP. "label_6_21:109" = if BACKUP. "label_6_21:110" = "%" "label_6_21:111". "label_6_21:110" = "(" "label_6_21:111". "label_6_21:110" = ";" "label_6_21:111". "label_6_21:110" = "=" "label_6_21:111". "label_6_21:110" = "*" "label_6_21:111". "label_6_21:110" = ":" "label_6_21:112". "label_6_21:110" = "-" "label_6_21:111". "label_6_21:110" = "." "label_6_21:111". "label_6_21:110" = "+" "label_6_21:111". "label_6_21:110" = "/" "label_6_21:111". "label_6_21:110" = "[" "label_6_21:111". "label_6_21:111" = BACKUP BACKUP. "label_6_21:112" = LABEL "label_6_21:109". labeled_statement = label statement STMT. start = labeled_statement. statement = "f:105" "t:104" "e:101" ";" EXPRSTMT. statement = id "statement:106". statement = if e then labeled_statement "statement:107". "statement:106" = "(" e ")" CALL "t:104" "e:101" ";" EXPRSTMT. "statement:106" = LOOKUPID "v:102" "statement:108". "statement:107" = IFTHEN. "statement:107" = else labeled_statement IFTHENELSE. "statement:108" = "=" e ";" ASGN. "statement:108" = FETCH "t:104" "e:101" ";" EXPRSTMT. t = f "t:104". "t:104" = "*" t MPY. "t:104" = "/" t DIV. "t:104" = "%" t MOD. "t:104" =. "v:102" = "[" e "]" SUBSCR "v:102". "v:102" = "." id FIELD "v:102". "v:102" =.