The following is the Java code for a compiler for a pseudocode-like language called pl0. The code is based on that given in "Algorithms Plus Data Structures = Programs" by Niklaus Wirth. Wirth developed the much more complex language Pascal in a similar way to the development of the pl0 language. It can be seen that the pl0 language is a very simplified Pascal or pseudocode.
Chapter 5.7 of the above text should be consulted to see
the stages of the development work. The code plus test programs
are to be found on the computer in:
/usr/units/cp502/Pl0.java
/usr/units/cp502/test1.pl0, etc
The alternative would be for you to grab the source code
(via ) and compile it on your machine.
Pl0.java
test1.pl0
test2.pl0
test3.pl0
pl0examples
import local.units.sdsu.io.*;
import local.units.Var.*;
import java.lang.*;
import java.util.*;
import java.io.*;
class Symset
{
BitSet thisSet;
public Symset()
{
thisSet = new BitSet();
}
public Symset(BitSet b)
{
thisSet = b;
}
public Symset(int element)
{
thisSet = new BitSet();
thisSet.set(element);
}
void add(int element)
{
thisSet.set(element);
}
Symset plus(Symset s)
{
BitSet s1 = (BitSet)thisSet.clone();
s1.or(s.thisSet);
return (new Symset(s1));
}
Symset plus(int element)
{
BitSet s1 = (BitSet)thisSet.clone();
s1.set(element);
return (new Symset(s1));
}
boolean contains(int sym)
{
return (thisSet.get(sym));
}
}
class Symbol
{
final static int nul = 0; final static int ident = 1;
final static int number = 2; final static int plus = 3;
final static int minus = 4; final static int times = 5;
final static int slash = 6; final static int oddsym = 7;
final static int eql = 8; final static int neq = 9;
final static int lss = 10; final static int leq = 11;
final static int gtr = 12; final static int geq = 13;
final static int lparen = 14; final static int rparen = 15;
final static int comma = 16; final static int semicolon = 17;
final static int period = 18; final static int becomes = 19;
final static int beginsym = 20; final static int endsym = 21;
final static int ifsym = 22; final static int thensym = 23;
final static int whilesym = 24; final static int dosym = 25;
final static int callsym = 26; final static int constsym = 27;
final static int varsym = 28; final static int procsym = 29;
}
class Instruction
{
final static int lit = 0; final static int opr = 1;
final static int lod = 2; final static int sto = 3;
final static int cal = 4; final static int Int = 5;
final static int jmp = 6; final static int jpc = 7;
int f; /* Function Code. */
int L; /* Level. */
int a; /* Displace Address. */
}
class Pl0Object
{
final static int constant = 0;
final static int variable = 1;
final static int proced = 2;
}
class Table
{
String name;
int kind;
int val;
int level,size,adr;
}
public class Pl0
{
// Mainline Variable Declarations
static PrintStream output = System.out;
static FileInputStream in_stream ;
static ASCIIInputStream input ;
final static int norw = 11; /*no of reserved words*/
final static int txmax = 100; /*length of identifier table*/
final static int nmax = 14; /*max. no of digits in numbers*/
final static int al = 8; /*length of identifier*/
final static int amax = 2047; /*max address*/
final static int levmax = 3; /*max depth of block nesting*/
final static int cxmax = 200; /*size of code array*/
final static int stacksize = 500; /*size of stack in procedure interpret. */
final static String errmess[] =
{
/* errmess[0] */ "Dummy error message -Part of conversion from Pascal",
/* errmess[1] */ "Use = instead of =",
/* errmess[2] */ "= must be followed by a number",
/* errmess[3] */ "Identifier must be followed by =",
/* errmess[4] */ "Const,var,proced must be followed by an identifier",
/* errmess[5] */ "Semicolon or comma missing",
/* errmess[6] */ "Incorrect symbol after proced declaration",
/* errmess[7] */ "Statement expected",
/* errmess[8] */ "Incorrect symbol after statement part in block",
/* errmess[9] */ "Period expected",
/* errmess[10]*/ "Semicolon between statements is missing",
/* errmess[11]*/ "Undeclared identifier",
/* errmess[12]*/ "Assignment to constant or void is not allowed",
/* errmess[13]*/ "Assignment operator := expected",
/* errmess[14]*/ "Call must be followed by an identifier",
/* errmess[15]*/ "Call of a constant or variable is meaningless",
/* errmess[16]*/ ") expected",
/* errmess[17]*/ "Semicolon or } expected",
/* errmess[18]*/ "do expected",
/* errmess[19]*/ "Incorrect symbol following statement",
/* errmess[20]*/ "Relational operator expected",
/* errmess[21]*/ "Expression must not contain a void identifier",
/* errmess[22]*/ "Right parenthesis missing",
/* errmess[23]*/ "The proceding factor cannot be followed by this symbol",
/* errmess[24]*/ "An expression cannot { with this symbol",
/* errmess[25]*/ "This number is too large",
/* errmess[26]*/ "Max. no. of digits in a number is 14",
/* errmess[27]*/ "Max level of nesting is 3"
};
static Instruction code[] = new Instruction[cxmax];
static char ch; /*last character read*/
static int sym; /*last symbol read*/
static String id; /*last identifier read*/
static int num; /*last number read*/
static int cc; /*character count*/
static int ll; /*line length*/
static int kk, err;
static int ttx;
static int cx; /*code allocation index*/
static Table table[] = new Table[txmax];
final static String mnemonic[] =
{
"lit ",
"opr ",
"lod ",
"sto ",
"cal ",
"int ",
"jmp ",
"jpc "
};
static int ssym[] = new int[256];
static int wsym[] = new int[norw];
static String word[] = new String[norw];
static char a[] = new char[al];
static char line[] = new char[82];
static Symset declbegsys = new Symset();
static Symset statbegsys = new Symset();
static Symset facbegsys = new Symset();
static int globalTx;
static int globalDx;
static int globalLev;
static void error(int n)
{
int i;
Format.print(output,"%25s"," ****");
for(i=0;i<cc-1;i++)
Format.print(output," ");
Format.print(output,"^ %d\n",n);
Format.print(output,"%10s"," ****");
Format.print(output, "%s\n",errmess[n]);
err++;
} /*error*/
static void printab()
{
int i;
Format.print(output,"\n Symbol Table\n");
Format.print(output," Name Kind Value Level\n");
for(i=1; i<=ttx; i++)
{
Format.print(output," %-8s",table[i].name);
switch(table[i].kind)
{
case Pl0Object.constant:
Format.print(output,"Constant "); break;
case Pl0Object.variable:
Format.print(output,"Variable "); break;
case Pl0Object.proced:
Format.print(output,"Procedure"); break;
};
Format.print(output,"%10d",table[i].val);
Format.print(output,"%13d\n",table[i].level);
}
} /* printab */
static void listcode(int cx0)
{ /*list code generated for this block*/
int i;
Format.print(output,"\n Generated Code.\n");
Format.print(output," Code Address Instruction Level Value\n");
for (i = cx0 ;i<= cx - 1; i++ )
{
Format.print(output,"%10d",i);
Format.print(output,"%13s"," ");
Format.print(output,"%6s",mnemonic[code[i].f]);
Format.print(output,"%6s"," ");
Format.print(output,"%3d",code[i].L);
Format.print(output,"%6s"," ");
Format.print(output,"%3d\n",code[i].a);
}
Format.print(output,"\n");
} /*listcode*/
static void gen(int x, int y, int z)
{
if ( cx > cxmax )
{
Format.print(output,"Program too long.\n");
System.exit(-1);
}
code[cx].f = x; code[cx].L = y; code[cx].a = z;
cx ++; /*gen*/
}
static void test(Symset s1,Symset s2, int n)
{
Symset s3;
if ( !s1.contains(sym) )
{
error(n); s3 = s1.plus(s2);
while (! s3.contains(sym) )
getsym();
}
} /* test */
static void getch()
{
if ( cc == ll )
{
ll = -1; cc = -1; Format.print(output,"%25d ",cx);
ch = ' ';
while ( ch != '\n')
{
ll++;
try {
ch = input.readChar();
} catch (IOException e) ;
if ( input.eof() )
{
Format.print(output,"Program incomplete.\n");
System.exit(-1);
}
Format.print(output,"%c",ch); line[ll] = ch;
}
line[ll]= ' ';
}
cc++ ; ch = line[cc]; /*getch*/
}
static void getsym()
{ /*getsym continued from previous page.*/
int i, j, k;
while ( ch == ' ' ) getch();
if ( Character.isUpperCase(ch) || Character.isLowerCase(ch) )
{ /*identifier or reserved word*/
k = -1;
do
{
if ( k < al-1 )
{
k++; a[k] = ch;
}
getch();
} while ( Character.isUpperCase(ch) || Character.isLowerCase(ch)
|| Character.isDigit(ch) );
id = new String(a,0,k+1); i = 0; j = norw-1;
do
{
int result ;
k = (i + j) / 2;
result = id.compareTo(word[k]);
if ( result <= 0 ) j = k - 1;
if ( result >= 0 ) i = k + 1;
} while ( i <= j);
if ( i - 1 > j ) sym = wsym[k];
else sym = Symbol.ident;
}
else if ( Character.isDigit(ch) )
{ /*number*/
k = 0; num = 0; sym = Symbol.number;
do
{
num = 10 * num + (ch - '0');
k++; getch();
} while ( Character.isDigit(ch) );
if ( k > nmax ) error(25);
}
else if ( ch == ':' )
{
getch();
if ( ch == '=' )
{
sym = Symbol.becomes; getch();
}
else sym = Symbol.nul;
}
else
{
sym = ssym[ch]; getch();
}
} /* getsym */
static void enter(int k)
{ /*enter object into table*/
globalTx ++ ; ttx = globalTx;
table[globalTx].name = new String(id); table[globalTx].kind = k;
switch (k)
{
case Pl0Object.constant:
if ( num > amax )
{
error(26); num = 0;
}
table[globalTx].val = num;
break;
case Pl0Object.variable:
table[globalTx].level = globalLev;
table[globalTx].adr = globalDx; globalDx ++;
break;
case Pl0Object.proced :
table[globalTx].level = globalLev;
break;
}
} /*enter*/
static int position(String id)
{ /*find identifier id in table*/
int i;
i = globalTx;
table[0].name = id;
while ( table[i].name.compareTo(id) != 0)
i--;
return(i);
} /*position*/
static void constdeclaration()
{
if ( sym == Symbol.ident )
{
getsym();
if ( (sym == Symbol.eql) || (sym == Symbol.becomes) )
{
if ( sym == Symbol.becomes ) error(1);
getsym();
if ( sym == Symbol.number )
{
enter(Pl0Object.constant); getsym();
}
else error(2);
}
else error(3);
} else error(4);
} /*constdeclaration*/
static void vardeclaration()
{
if ( sym == Symbol.ident )
{
enter(Pl0Object.variable); getsym();
}
else error(4);
} /*vardclaration*/
static void factor(Symset fsys)
{
int i;
test(facbegsys, fsys, 24);
while ( facbegsys.contains(sym))
{
if ( sym == Symbol.ident )
{
i = position(id);
if ( i == 0 ) error(11);
else
switch(table[i].kind)
{
case Pl0Object.constant:
gen(Instruction.lit, 0, table[i].val);
break;
case Pl0Object.variable:
gen(Instruction.lod,globalLev-table[i].level,table[i].adr);
break;
case Pl0Object.proced :
error(21);
break;
}
getsym();
}
else if ( sym == Symbol.number )
{
if ( num > amax )
{
error(26); num = 0;
}
gen(Instruction.lit, 0, num); getsym();
}
else if ( sym == Symbol.lparen )
{
getsym(); expression(fsys.plus(Symbol.rparen));
if ( sym == Symbol.rparen ) getsym();
else error(22);
}
test(fsys, new Symset(Symbol.lparen), 23);
}
} /*factor*/
static void term(Symset fsys)
{
int mulop;
factor(fsys.plus(Symbol.times).plus(Symbol.slash));
while ( (sym == Symbol.times) || (sym == Symbol.slash))
{
mulop = sym; getsym();
factor(fsys.plus(Symbol.times).plus(Symbol.slash));
if ( mulop == Symbol.times ) gen(Instruction.opr, 0, 4);
else gen(Instruction.opr, 0, 5);
}
} /*term*/
static void expression(Symset fsys)
{
int addop;
if ( (sym == Symbol.plus) || (sym == Symbol.minus) )
{
addop = sym; getsym();
term(fsys.plus(Symbol.plus).plus(Symbol.minus));
if ( addop == Symbol.minus ) gen(Instruction.opr, 0, 1);
}
else
term(fsys.plus(Symbol.plus).plus(Symbol.minus));
while ( (sym == Symbol.plus) || (sym == Symbol.minus))
{
addop = sym; getsym();
term(fsys.plus(Symbol.plus).plus(Symbol.minus));
if ( addop == Symbol.plus ) gen(Instruction.opr, 0, 2);
else gen(Instruction.opr, 0, 3);
}
} /*expression*/
static void condition(Symset fsys)
{
int relop;
if ( sym == Symbol.oddsym )
{
getsym(); expression(fsys); gen(Instruction.opr, 0, 6);
}
else
{
expression(fsys.plus(Symbol.eql).plus(Symbol.neq).plus(Symbol.lss)
.plus(Symbol.gtr) .plus(Symbol.leq).plus(Symbol.geq));
if ( (sym == Symbol.eql) || (sym == Symbol.neq) ||
(sym == Symbol.lss) || (sym == Symbol.leq) ||
(sym == Symbol.gtr) || (sym == Symbol.geq) )
{
relop = sym; getsym(); expression(fsys);
switch(relop)
{
case Symbol.eql: gen(Instruction.opr, 0, 8); break;
case Symbol.neq: gen(Instruction.opr, 0, 9); break;
case Symbol.lss: gen(Instruction.opr, 0, 10); break;
case Symbol.geq: gen(Instruction.opr, 0, 11); break;
case Symbol.gtr: gen(Instruction.opr, 0, 12); break;
case Symbol.leq: gen(Instruction.opr, 0, 13); break;
}
}
else
error(20);
}
} /*condition*/
static void statement(Symset fsys)
{
int i, cx1, cx2;
if ( sym == Symbol.ident )
{
i = position(id);
if ( i == 0 ) error(11);
else if ( table[i].kind != Pl0Object.variable )
{
error(12); i = 0; /*assignment to non-variable*/
}
getsym();
if ( sym == Symbol.becomes ) getsym();
else error(13);
expression(fsys);
if ( i != 0 )
gen(Instruction.sto,globalLev-table[i].level,table[i].adr);
}
else if ( sym == Symbol.callsym )
{
getsym();
if ( sym != Symbol.ident ) error(14);
else
{
i = position(id);
if ( i == 0 ) error(11);
else
if ( table[i].kind == Pl0Object.proced )
gen(Instruction.cal,
globalLev - table[i].level, table[i].adr);
else error(15);
getsym();
}
}
else if ( sym == Symbol.ifsym )
{
getsym();
condition(fsys.plus(Symbol.thensym).plus(Symbol.dosym));
if ( sym == Symbol.thensym ) getsym();
else error(16);
cx1 = cx; gen(Instruction.jpc, 0, 0);
statement(fsys); code[cx1].a = cx;
}
else if ( sym == Symbol.beginsym )
{
getsym();
statement(fsys.plus(Symbol.semicolon).plus(Symbol.endsym));
while ( statbegsys.plus(Symbol.semicolon).contains(sym) )
{
if ( sym == Symbol.semicolon ) getsym();
else error(10);
statement(fsys.plus(Symbol.semicolon).plus(Symbol.endsym));
}
if ( sym == Symbol.endsym ) getsym();
else error(17);
}
else if ( sym == Symbol.whilesym )
{
cx1 = cx; getsym();
condition(fsys.plus(Symbol.dosym));
cx2 = cx; gen(Instruction.jpc, 0, 0);
if ( sym == Symbol.dosym ) getsym();
else error(18);
statement(fsys);
gen(Instruction.jmp, 0, cx1); code[cx2].a = cx;
}
test(fsys, new Symset(), 19);
} /*statement*/
static void block(int lev,int tx, Symset fsys)
{
int dx,tx0,cx0 ; /*data,table and code index*/
int localDx;
int localLev;
int localTx;
/*block*/
dx = 3;
globalTx = tx;
globalDx = dx;
globalLev= lev;
tx0 = globalTx; table[globalTx].adr = cx;
gen(Instruction.jmp, 0, 0);
if ( globalLev > levmax ) error(27);
do
{
if ( sym == Symbol.constsym )
{
getsym();
do
{
constdeclaration();
while ( sym == Symbol.comma )
{
getsym();
constdeclaration();
}
if ( sym == Symbol.semicolon ) getsym();
else error(5);
} while ( sym == Symbol.ident);
}
if ( sym == Symbol.varsym )
{
getsym();
do
{
vardeclaration();
while ( sym == Symbol.comma )
{
getsym();
vardeclaration();
}
if ( sym == Symbol.semicolon ) getsym();
else error(5);
} while (sym == Symbol.ident);
}
while ( sym == Symbol.procsym )
{
getsym();
if ( sym == Symbol.ident )
{
enter(Pl0Object.proced);
getsym();
}
else
error(4);
if ( sym == Symbol.semicolon ) getsym();
else error(5);
localDx=globalDx;localLev = globalLev;localTx = globalTx;
block(globalLev + 1, globalTx, fsys.plus(Symbol.semicolon));
globalDx= localDx; globalLev=localLev; globalTx = localTx;
if ( sym == Symbol.semicolon )
{
getsym();
test(statbegsys.plus(Symbol.ident).plus(Symbol.procsym),
fsys, 6);
}
else error(5);
}
test(statbegsys.plus(Symbol.ident), declbegsys, 7);
} while (declbegsys.contains(sym));
code[table[tx0].adr].a = cx;
/* code start addr,data segment size */
table[tx0].adr = cx; table[tx0].size = globalDx;
cx0 = cx; gen(Instruction.Int, 0, globalDx);
statement(fsys.plus(Symbol.semicolon).plus(Symbol.endsym));
gen(Instruction.opr, 0, 0); /*return*/
test(fsys, new Symset(), 8);
if ( err == 0 ) listcode(cx0);
} /*block*/
static int base(int s[],int b, int l )
{
int bb=b;
while ( l > 0 ) /*find base l levels down*/
{
bb = s[bb]; l--;
}
return( bb ) ;
} /* base */
static void interpret() /*code generation*/
{
int p, b, t; /*program,base,topstack-registers*/
Instruction i; /*Instruction register*/
int s[] = new int[stacksize] ; /*datastore*/
Format.print(output,"\n Interpretation of your program begins:\n");
t = -1; b = 0; p = 0;
s[0] = 0; s[1] = 0; s[2] = 0;
do
{
i = code[p]; p++;
switch (i.f)
{
case Instruction.lit:
t ++; s[t] = i.a;
break;
case Instruction.lod:
t ++; s[t] = s[base(s,b,i.L) + i.a];
break;
case Instruction.Int:
t = t + i.a;
break;
case Instruction.jmp:
p = i.a;
break;
case Instruction.sto:
s[base(s,b,i.L) + i.a] = s[t];
Format.print(output,"%d\n",s[t]); t --;
break;
case Instruction.cal: /*generate new block mark*/
s[t + 1] = base(s,b,i.L); s[t + 2] = b;
s[t + 3] = p; b = t + 1; p = i.a;
break;
case Instruction.jpc:
if ( s[t] == 0 ) p = i.a;
t--;
break;
case Instruction.opr:
{
switch (i.a) /*operators*/
{
case 0: /*return*/
t = b - 1; p = s[t + 3]; b = s[t + 2];
break;
case 1:
s[t] = -s[t];
break;
case 2:
t --; s[t] = s[t] + s[t + 1];
break;
case 3:
t --; s[t] = s[t] - s[t + 1];
break;
case 4:
t --; s[t] = s[t] * s[t + 1];
break;
case 5:
t --; s[t] = s[t] / s[t + 1];
break;
case 6:
s[t] = ( (s[t]%2 ==1)?1:0 );
break;
case 8:
t --; s[t] = ( (s[t] == s[t + 1])?1:0);
break;
case 9:
t --; s[t] = ( (s[t] != s[t + 1])?1:0);
break;
case 10:
t --; s[t] = ( (s[t] < s[t + 1])?1:0);
break;
case 11:
t --; s[t] = ( (s[t] >= s[t + 1])?1:0);
break;
case 12:
t --; s[t] = ( (s[t] > s[t + 1])?1:0);
break;
case 13:
t --; s[t] = ( (s[t] <= s[t + 1])?1:0);
break;
}
break;
}
}
} while ( p != 0 ) ;
Format.print(output," End of Interpretation.\n"); /*interpret*/
} /* interpret */
static void init()
{
int i;
for(i=0; i<cxmax; i++)
code[i] = new Instruction();
for(i=0; i<txmax; i++)
table[i] = new Table();
for(i=0; i<norw; i++)
word[i] = new String();
}
static void writehead()
{
Format.print(output," Pl0 interpreter by N. Wirth \n");
Format.print(output," Converted to Java by A. Marriott.\n");
Format.print(output,"Use %% for >=, $ for <=, PROCED for procedure\n");
Format.print(output,"and # for <>\n");
Format.print(output,"\n\n\n\n");
} /*writehead*/
public static void main(String argv[]) throws IOException
{
try
{
// Get a FileInputStream file with name on command line.
in_stream = new FileInputStream(argv[0]);
}
catch (FileNotFoundException e)
{
Format.print(output,
"The file %s could not be found." +
" Please check and try again.\n",
argv[0]);
System.exit(-1);
}
input = new ASCIIInputStream(in_stream);
init();writehead();
for (ch = 'a' ; ch <= ';'; ch++)
ssym[ch] = Symbol.nul;
word[0] = "BEGIN"; word[1] = "CALL"; word[2] = "CONST";
word[3] = "DO"; word[4] = "END"; word[5] = "IF";
word[6] = "ODD"; word[7] = "PROCED"; word[8] = "THEN";
word[9] = "VAR"; word[10] = "WHILE";
wsym[0] = Symbol.beginsym; wsym[1] = Symbol.callsym;
wsym[2] = Symbol.constsym; wsym[3] = Symbol.dosym;
wsym[4] = Symbol.endsym; wsym[5] = Symbol.ifsym;
wsym[6] = Symbol.oddsym; wsym[7] = Symbol.procsym;
wsym[8] = Symbol.thensym; wsym[9] = Symbol.varsym;
wsym[10] = Symbol.whilesym;
ssym['+']=Symbol.plus; ssym['-']=Symbol.minus;
ssym['*']=Symbol.times; ssym['/']=Symbol.slash;
ssym['(']=Symbol.lparen; ssym[')']=Symbol.rparen;
ssym['=']=Symbol.eql; ssym[',']=Symbol.comma;
ssym['.']=Symbol.period; ssym['#']=Symbol.neq;
ssym['<']=Symbol.lss; ssym['>']=Symbol.gtr;
ssym['$']=Symbol.leq; ssym['%']=Symbol.geq;
ssym[';']=Symbol.semicolon;
declbegsys.add(Symbol.constsym); declbegsys.add(Symbol.varsym);
declbegsys.add(Symbol.procsym);
statbegsys.add(Symbol.beginsym); statbegsys.add(Symbol.callsym);
statbegsys.add(Symbol.ifsym); statbegsys.add(Symbol.whilesym);
facbegsys.add(Symbol.ident); facbegsys.add(Symbol.number);
facbegsys.add(Symbol.lparen);
err = 0; cc = 0; cx = 0;
ll = 0; ch = ' '; kk = al;
getsym();
block(0, 0, statbegsys.plus(Symbol.period).plus(declbegsys));
if ( err == 0 ) printab();
if ( sym != Symbol.period ) error(9);
if ( err == 0 ) interpret();
else Format.print(output,"Error in PL0 program\n");
Format.print(output,"\n"); /*****End of compiler***/
}
}
CONST m=7,n=85;
VAR x,y,z,q,r;
PROCED multiply;
VAR a,b;
BEGIN
a:=x;b:=y;z:=0;
WHILE b>0 DO
BEGIN
IF ODD b THEN z:=z+a;
a:=2*a;b:=b/2;
END
END;
PROCED divide;
VAR w;
BEGIN
r:=x;q:=0;w:=y;
WHILE w$r DO w:=2*w;
WHILE w>y DO
BEGIN
q:=2*q;w:=w/2;
IF w$r THEN
BEGIN
r:=r-w;q:=q+1;
END
END
END;
PROCED gcd;
VAR f,g;
BEGIN
f:=x;g:=y;
WHILE f#g DO
BEGIN
IF f<g THEN g:=g-f;
IF g<f THEN f:=f-g;
END;
z:=f;
END;
BEGIN
x:=m; y:=n; CALL multiply;
x:=25; y:=3; CALL divide;
x:=84;y:=36; CALL gcd;
END.
VAR x;
BEGIN
x:=0;
END.
VAR x;
BEGIN
WHILE 2>1 DO
x:=99;
END.
![]()
Fig. 7.1 : Syntax diagram for Pl0 program
![]()
Fig. 7.2 : Syntax diagram for Pl0 block
![]()
Fig. 7.3 : Syntax diagram for Pl0 statement
![]()
Fig. 7.4 : Syntax diagram for Pl0 expression
![]()
Fig. 7.5 : Syntax diagram for Pl0 condition
![]()
Fig. 7.6 : Syntax diagram for Pl0 term
![]()
Fig. 7.7 : Syntax diagram for Pl0 factor