CSC 330 Lecture Notes Week 1
Intro to the Course; Some Programming Language History;
The Syntax of Programming Languages
as a Java or C programming language statement versusx = y
as a mathematical statement.x = y
as a program versusx = y; x = z;
as a mathematical statement.x = y and x = z
Figure 1: Generational history of programming languages.
non-terminal symbol -> list of zero or more terminals or non- terminalsThis rule can be read as ``the non-terminal on the left-hand side (LHS) of the rule is comprised of the list of constituents on the right-hand side (RHS) of the rule''
sentence -> subject predicate . subject -> Mary predicate -> verb object verb -> greets object -> John
object -> John | Alfred
subject -> Mary | John object -> Mary | John
sentence -> subject predicate . subject -> noun predicate -> verb object verb -> greets object -> noun noun -> John | Mary
object -> John | John again | John again and again | ...
object -> John | John repeat_factor repeat_factor -> again | again and repeat_factor
expr -> expr op expr | var op -> + | - | * | / var -> a | b | c | ...
expr -> simple_expr | expr rel_op simple_expr simple_expr -> term | simple_expr add_op term term -> factor | term mult_op factor factor -> var | integer rel_op -> < | > | == | <= | >= | != add_op -> + | - mult_op -> * | / var -> a | b | c | ... integer -> digit | integer digit digit -> 0 | ... | 9
means a number is comprised of zero or more digits.number -> { digit }*
Note the empty alternative at the beginning of the RHS; this allows for the zero case.number -> | digit | number digit
means that a signed number is a number preceded with a plus or minus sign.signed number -> [ + | - ] number
means that a signed_number is a number preceded with an optional plus or minus sign, i.e., by a plus sign, a minus sign, or neither.signed_number -> [ + | - ]opt number
Figure 2: Syntax graph for expression grammar on Page 6.
stmt -> assignment_stmt | procedure_stmt | if_stmt | ... if_stmt -> if bool expr then stmt [ else stmt ]opt
versus the Pascaleseif (t) { s1; s2 } else { s3; s4 }
if t then s1; s2 else s3 ; s4 endif;