YAL grammar

advertisement
CS 5300
Compiler Design
Fall 2006
Initial YAL language grammer:
program
title
block
vars
varlist
vardef
-->
-->
-->
-->
-->
-->
bnl
nlist
procs
proclist
procdef
ptitle
code
para
stmt
assign
expr
term
fac
val
ids
vallist
it
cond
bop
loop
input
output
-->
-->
-->
-->
-->
-->
-->
-->
-->
-->
-->
-->
-->
-->
-->
-->
-->
-->
-->
-->
-->
-->
title ; block
_PROGRAM _ID
vars _ENDVARS procs _ENDPROCS code
_VARIABLES varlist ; | _NOVARIABLES
varlist ; vardef | vardef
_ID : _INTEGER | _ID : _REAL | _ID : _INTEGER bnl
| _ID : STRING
[ nlist ]
nlist , _ICONST | _ICONST
_PROCEDURES proclist | _NOPROCEDURES
proclist ; procdef | procdef
ptitle ; block
_PROCEDURE _ID ( varlist ) | _PROCEDURE _ID ( )
_BEGIN para _END | ;
para ; stmt | stmt
assign | cond | loop | input | output | code
ids := expr
expr + term | expr - term | term
term * fac | term / fac | fac
val | ( expr )
ids | _ID ( vallist ) | _ICONST | _RCONST
_ID | _ID [ vallist ]
vallist , it | it
_ID | _ICONST
_IF expr bop expr _THEN stmt _ELSE stmt
= | < | > | <= | >= | <>
_FOR assign _TO expr _DO stmt
_READ ( _ID )
_WRITE ( _ID ) | _WRITE ( LITERAL )
This is only the initial grammar for YAL -- enhancements may be made as the class progresses. Note that
this syntax definition does not specify run-time semantic definitions. The definitions for _LITERAL, _RCONST,
_ICONST, and _ID have previously been given as regular expressions. This BNF uses the shorthand notation of
specific token symbols rather than token names. For example, the left paren is just ‘(‘ rather than _LPAREN.
Several peculiarities may be noted in YAL; the placing of the semicolon for example, is not standard and no
unary minus is allowed. The semantics of these productions will be defined later.
Download