PL Grammar
From Ben's Writing
Out of shear laziness, I scanned the grammar for the PL language from the Hansen text. If there are any errors they are most-likely my own, or my scanner's.
Program = Block "." .
Block = "begin" DefinitionPart StatementPart "end" .
DefinitionPart = { Definition ";" } .
Definition = ConstantDefinition | VariableDefinition | ProcedureDefinition .
ConstantDefinition = "const" ConstantName "=" Constant .
VariableDefinition = TypeSymbol VariableList | \
TypeSymbol "array" VariableList "[" Constant "]" .
TypeSymbol = "integer" | "Boolean" .
VariableList = VariableName { "," VariableName } .
ProcedureDefinition = "proc" ProcedureName Block .
StatementPart = { Statement ";" } .
Statement = EmptyStatement | ReadStatement | WriteStatement | \
AssignmentStatement | ProcedureStatement | IfStatement | \
DoStatement .
EmptyStatement = "skip" .
ReadStatement = "read" VariableAccessList .
VariableAccessList = VariableAccess { "," VariableAccess } .
WriteStatement = "write" ExpressionList .
ExpressionList = Expression { "," Expression } .
AssignmentStatement = VariableAccessList ":=" ExpressionList .
ProcedureStatement = "call" ProcedureName .
IfStatement = "if" GuardedCommandList "fi" .
DoStatement = "do" GuardedCommandList "od" .
GuardedCommandList = GuardedCommand { "[]" GuardedCommand } .
GuardedCommand = Expression "->" StatementPart .
Expression = PrimaryExpression { PrimaryOperator PrimaryExpression }
PrimaryOperator = "&" | "|" .
PrimaryExpression = SimpleExpression [ RelationalOperator SimpleExpression ] .
RelationalOperator = "<" | "=" | ">" .
SimpleExpression = [ "-" ] Term { AddingOperator Term } .
AddingOperator = "+" | "-" .
Term = Factor { MultiplyingOperator Factor } .
MultiplyingOperator = "*" | "/" | "\" .
Factor = Constant | VariableAccess | "(" Expression ")" | "~" Factor .
VariableAccess = VariableName [ IndexedSelector ] .
IndexedSelector = "[" Expression "]" .
Constant = Numeral | BooleanSymbol | ConstantName .
Numeral = Digit { Digit } .
BooleanSymbol = "false" | "true" .
Name = Letter { Letter | Digit | "_" } .
Note taken verbatim from:
Hansen, B. (1985). Brinch Hansen On Pascal Compilers, Prentice-Hall, Inc., Englewood Cliffs, New Jersey 07632
Modification
Program = Block "." .
Block = "begin" DefinitionPart StatementPart "end" .
DefinitionPart = { Definition ";" } .
Definition = ConstantDefinition | VariableDefinition | ProcedureDefinition .
ConstantDefinition = "const" ConstantName "=" Constant .
VariableDefinition1 = TypeSymbol VariableDefinition2 .
VariableDefinition2 = VariableList | "array" VariableList "[" Constant "]" .
TypeSymbol = "integer" | "Boolean" .
VariableList = VariableName { "," VariableName } .
ProcedureDefinition = "proc" ProcedureName Block .
StatementPart = { Statement ";" } .
Statement = EmptyStatement | ReadStatement | WriteStatement | \
AssignmentStatement | ProcedureStatement | IfStatement | \
DoStatement .
EmptyStatement = "skip" .
ReadStatement = "read" VariableAccessList .
VariableAccessList = VariableAccess { "," VariableAccess } .
WriteStatement = "write" ExpressionList .
ExpressionList = Expression { "," Expression } .
AssignmentStatement = VariableAccessList ":=" ExpressionList .
ProcedureStatement = "call" ProcedureName .
IfStatement = "if" GuardedCommandList "fi" .
DoStatement = "do" GuardedCommandList "od" .
GuardedCommandList = GuardedCommand { "[]" GuardedCommand } .
GuardedCommand = Expression "->" StatementPart .
Expression = PrimaryExpression { PrimaryOperator PrimaryExpression }
PrimaryOperator = "&" | "|" .
PrimaryExpression = SimpleExpression [ RelationalOperator SimpleExpression ] .
RelationalOperator = "<" | "=" | ">" .
SimpleExpression = [ "-" ] Term { AddingOperator Term } .
AddingOperator = "+" | "-" .
Term = Factor { MultiplyingOperator Factor } .
MultiplyingOperator = "*" | "/" | "\" .
Factor = Constant | VariableAccess | "(" Expression ")" | "~" Factor .
VariableAccess = VariableName [ IndexedSelector ] .
IndexedSelector = "[" Expression "]" .
Constant = Numeral | BooleanSymbol | ConstantName .
Numeral = Digit { Digit } .
BooleanSymbol = "false" | "true" .
Name = Letter { Letter | Digit | "_" } .