IS -> "::=" OR -> "|" OB -> "(" CB -> ")" OS -> "[" CS -> "]" OC -> "{" CC -> "}" ## IDENT -> ([a-z]|[A-Z])([a-z]|([A-Z]|[0-9]))* STR -> \" ([a-z]|([A-Z]|[0-9]))* \" NL -> \n ## ## EOL -> \r SPACE -> \s|\t ## start -> { global stack line; line.clear; global stack finsihed; finsihed.clear; global int next; next:=0; global stack tokens; tokens.clear; global stack lexemes; lexemes.clear; } syntax { while (!(isempty (tokens))) do begin print pop(tokens); print " -> "; print pop(lexemes); print ; end; print "##"; print ; print "##"; print ; print "EOL -> \\n|\\r"; print ; print "SPACE -> \\s|\\t"; print ; print "##"; print ; print "##"; print ; while (!(isempty (finsihed))) do begin print pop(finsihed); print ; end; } syntax -> rule {} syntax syntax -> EMPTY rule -> {line.push((lexeme)+(" -> "));} {} expression expression -> term { finsihed.push(pop(line)); } expression ->{local string temp; temp:=pop(line); line.push(temp); line.push(temp); } term { finsihed.push(pop(line)); } expression term -> factor term term -> factor factor -> {line.push(pop(line) + " " + lexeme);} factor -> {line.push(pop(line) + " <" + toident(lexeme) + ">"); tokens.push(toident(lexeme)); lexemes.push(lexeme);} factor -> {line.push(pop(line) + " this" +string(next)); line.push(("this")+(string(next))+(" -> ")); next:=next+1;} expression {} factor -> {finsihed.push("this"+string(next)+" -> EMPTY"); line.push(pop(line) + " this" +string(next)); line.push(("this")+(string(next))+(" -> ")); next:=next+1;} expression {} factor -> { finsihed.push("this"+string(next)+" -> this"+string(next+1)); finsihed.push("this"+string(next)+" -> this"+string(next+1) + " this"+string(next) ); line.push(pop(line) + " this" +string(next)); line.push(("this")+(string(next+1))+(" -> ")); next:=next+2; }expression {}