[Skip Navigation] [CSUSB] / [CNS] / [CSE] / [R J Botting] / [Samples] / pascal.syntax
[Index] [Contents] [Source Text] [About] [Notation] [Copyright] [Comment/Contact] [Search ]
Fri Apr 15 09:39:05 PDT 2011

Contents


    Syntax of the Pascal Programming Language

    [ ASCII ]
  1. ASCII::= See http://cse.csusb.edu/dick/samples/comp.text.ASCII.html.

    [ LEXEMES ]

  2. LEXEMES::= See http://cse.csusb.edu/dick/samples/pascal.lexicon.html.

    SYNTAX

      Programs and Blocks

    1. program::= program_heading semicolon program_block,
       	program hi(out); begin writeln('Hello, World!'); end.
    2. program_heading::="program" identifier ("(" O( program_parameters) ")" |),
       	program merge(infile1, infile2, mergedfile);
    3. program_block::= block ".",
       	begin writeln('Hi'); writeln('there!'); end .
    4. block::= label_declarations constant_definitions type_definitions variable_declarations procedure_function_declarations statement_part,
       	const n=1; m=2; begin writeln(m+n); end
    5. program_parameters::= List(identifier),
       	in,out,waveItAllAbout

      Declarations and Definitions

      1. label_declarations::= O("label" List(label) semicolon ),
      2. label::= digit_sequence,
         	label 1,2,3,911;
      3. constant_definitions::= O("const" S(constant_definition) semicolon),
      4. constant_definition::= identifier "=" constant,

      5. type_definitions::= O("type" type_definition semicolon #(type_definition semicolon) ),
      6. type_definition::= identifier "=" type_denoter,

      7. variable_declarations::= O("var" variable_declaration semicolon #(variable_declaration semicolon) ),
      8. variable_declaration::= identifier_list ":" type_denoter,

      9. procedure_function_declarations::= #( procedure_declaration | function_declaration ) semicolon,

        Subprogram Declarations

        1. subprogram_declaration::=procedure_declaration | function_declaration.

          Procedure Declarations

        2. procedure_declaration::= procedure_heading semicolon directive | procedure_identification semicolon procedure_block | procedure_heading semicolon procedure_block,
        3. procedure_heading::= "procedure" identifier O(formal_parameter_list),
        4. procedure_identification::= "procedure" procedure_identifier,
        5. procedure_block::= block,
        6. procedure_identifier::= identifier,

        7. directive::= letter #(letter | digit),
        8. type_denoter::= type_identifier | new_type,

          Function Declarations

        9. function_declaration::= function_heading semicolon directive | function_identification semicolon function_block | function_heading semicolon function_block,
        10. function_heading::= "function" identifier (formal_parameter_list |) ":" result_type,
        11. function_block::= block.

          Formal Parameters and Arguments

        12. formal_parameter_list::= formal_parameter_section #( semicolon formal_parameter_section),
        13. formal_parameter_section::= value_parameter_specification | variable_parameter_specification | procedural_parameter_specification | functional_parameter_specification | conformant_array_parameter_specification,

        14. value_parameter_specification::= identifier_list ":" type_identifier,
        15. variable_parameter_specification::= "var" identifier_list ":" type_identifier,
        16. procedural_parameter_specification::= procedure_heading,
        17. functional_parameter_specification::= function_heading,

        18. conformant_array_parameter_specification::= value_conformant_array_specification | variable_conformant_array_specification,
        19. value_conformant_array_specification::= identifier_list ":" conformant_array_schema,
        20. variable_conformant_array_specification::= "var" identifier_list ":" conformant_array_schema,
        21. conformant_array_schema::= packed_conformant_array_schema | unpacked_conformant_array_schema,
        22. packed_conformant_array_schema::= "packed" "array" O(index_type_specification ) "of" type_identifier,
        23. unpacked_conformant_array_schema::= "array" O(index_type_specification #(semicolon index_type_specification) ) "of" type_identifier | conformant_array_schema,
        24. index_type_specfication::= identifier ".." identifier ":" ordinal_type_identifier,

      Constants

    6. constant::= signed_number | constant_identifier | character_string,
    7. unsigned_constant::= unsigned_number | character_string | constant_identifier | "nil",
    8. unsigned_number::= unsigned_integer | unsigned_real,
    9. constant_identifier::= identifier,

      Types

    10. type_identifier::= identifier,
    11. new_type::= new_ordinal_type | new_structured_type | new_pointer_type,

    12. result_type::= simple_type_identifier | pointer_type_identifier,

    13. new_ordinal_type::= enumerated_type | subrange_type,

    14. new_structured_type::= O("packed") unpacked_structured_type,

    15. new_pointer_type::= "^" domain_type,

    16. simple_type_identifier::= type_identifier,

    17. pointer_type_identifier::= type_identifier,

    18. enumerated_type::= identifier_list,

    19. subrange_type::= constant ".." constant,

    20. unpacked_structured_type::= array_type | record_type | set_type | file_type,

    21. domain_type::= type_identifier,

    22. array_type::= "array" #(index_type #("," index_type) ) "of" component_type,

    23. set_type::= "set of" base_type,

    24. file_type::= "file of" component_type,

    25. index_type::= ordinal_type,

    26. component_type::= type_denoter,

    27. base_type::= ordinal_type,
    28. ordinal_type::= new_ordinal_type | ordinal_type_identifier,
    29. ordinal_type_identifier::= type_identifier,

    30. record_type::= "record" field_list "end",
    31. record_section::= identifier_list ":" type_denoter,
    32. field_list::= O( fixed_part #( semicolon variant_part ) ,
    33. fixed_part::= record_section #( semicolon record_section),
    34. variant_part::= "case" variant_selector "of" variant #( semicolon variant),
    35. variant_selector::= O( tag_field ":" ) tag_type,
    36. variant::= case_constant_list ":" field_list,
    37. tag_field::= identifier,
    38. tag_type::= ordinal_type_identifier,
    39. case_constant_list::= case_constant #( "," case_constant),
    40. case_constant::= constant,

      Statements

    41. procedure_statement::= procedure_identifier O(actual_parameter_list ) | IO_procedure_statement,
    42. IO_procedure_statement::= "read" read_parameter_list | "readln" readln_parameter_list | "write" write_parameter_list | "writeln" writeln_parameter_list,
    43. actual_parameter_list::= actual_parameter #( "," actual_parameter),
    44. optional_file::=O(file_variable ","),
    45. read_parameter_list::= optional_file variable_access #( "," variable_access),
    46. readln_parameter_list::= O( optional_file variable_access #( "," variable_access) ),
    47. write_parameter_list::= optional_file write_parameter #( "," write_parameter),
    48. writeln_parameter_list::= O(optional_file write_parameter #( "," write_parameter) ),
    49. actual_parameter::= expression | variable_access | procedure_identifier | function_identifier,
    50. file_variable::= variable_access,
    51. variable_access::= entire_variable | component_variable | identified_variable | buffer_varible,
    52. write_parameter::= expression O( ":" O(":" expression ) ),
    53. statement_part::= compound_statement,
    54. compound_statement::= "begin" statement_sequence "end",
    55. statement_sequence::= statement #(semicolon statement),
    56. statement::= O( label ":" ) (simple_statement | structured_statement),
    57. simple_statement::= empty_statement | assignment_statement | procedure_statement | goto_statement,
    58. structured_statement::= compound_statement | conditional_statement | repetitive_statement | with_statement,
    59. empty_statement::=,
    60. assignment_statement::= variable_access | function_identifier ":=" expression,
    61. goto_statement::= "goto" label,
    62. conditional_statement::= if_statement | case_statement,
    63. repetitive_statement::= repeat_statement | while_statement | for_statement,
    64. loop::= repeat_statement | while_statement | for_statement,
    65. with_statement::= "with" record_variable_list "do" statement,
    66. if_statement::= "if" boolean_expression "then" statement O(else_part ),
    67. case_statement::= "case" case_index "of" case_list_element #(semicolon case_list_element) O(semicolon |) "end",
    68. repeat_statement::= "repeat" statement_sequence "until" boolean_expression,
    69. while_statement::= "while" boolean_expression "do" statement,
    70. for_statement::= "for" control_variable ":=" initial_value ("to" | "downto") final_value "do" statement,
    71. record_variable_list::= record_variable #("," record_variable),
    72. boolean_expression::= expression,
    73. else_part::= "else" statement,
    74. case_index::= expression,
    75. case_list_element::= case_constant_list ":" statement,
    76. control_variable::= entire_variable,
    77. initial_value::= expression,
    78. final_value::= expression,

      Expressions and Variables

    79. expression::= simple_expression #(relational_operator simple_expression ),
    80. function_identifier::= identifier,
    81. entire_variable::= variable_identifier,
    82. component_variable::= indexed_variable | field_designator,
    83. identified_variable::= pointer_variable "^",
    84. buffer_variable::= file_variable "^",
    85. simple_expression::= O(sign) term #(adding_operator term),
    86. variable_identifier::= identifier,
    87. indexed_variable::= array_variable "[" O(index_expression #("," index_expression) ) "]" ,
    88. field_designator::= record_variable "." field_specifier | field_designator_identifier,
    89. pointer_variable::= variable_access,
    90. term::= factor #(multiplying_operator factor),
    91. array_variable::= variable_access,
    92. index_expression::= expression,
    93. record_variable::= variable_access,
    94. field_specifier::= field_identifier,
    95. field_designator_identifier::= identifier,
    96. factor::= variable_access | unsigned_constant | function_designator | set_constructor | expression | "not" factor, | bound_identifier,
    97. field_identifier::= identifier,
    98. set_constructor::= O( #(member_designator #("," member_designator)) ),
    99. bound_identifier::= identifier,
    100. member_designator::= expression #(".." expression),
    101. function_identification::= "function" function_identifier,
    102. function_designator::= function_identifier O(actual_parameter_list ),

    . . . . . . . . . ( end of section SYNTAX) <<Contents | End>>

    Notation

    O(X)::= empty | X.
  3. #(X)::= any number of X.
  4. S(X)::= X #(";" X).
  5. List(X)::= X #("," X).

    Semantics and UML Model

    [ Pascal.png?root=atlantic-zoos ]

End