menu
  Home  ==>  papers  ==>  compilers  ==>  pascal_s_grammar   

Pascal S Grammar - Felix John COLIBRI.

  • abstract : the Pascals ebnf grammar
  • key words : ebnf, iebnf, compiler, pascal
  • software used : Windows XP, Delphi 6
  • hardware used : Pentium 1.400Mhz, 256 M memory, 140 G hard disc
  • scope : Delphi 1 to 8 for Windows, Kylix
  • level : Delphi developer
  • plan :


1 - Introduction

We simply provide here the Pascal S language grammar.

This language was uses as a testbed for small compilers.




2 - The grammar

To quickly describe the language, we can compare it to the full-blown WIRTH P4 Pascal. The Pascal S does not contain:
  • enumeration
  • SET
  • files
  • pointers
  • variant records
  • procedural types or conformant arrays
  • GOTO
  • WITH


Here is the grammar:

 
programprogram_heading block '..
  identifier_listNAME { ',NAME } .
  program_headingPROGRAM NAME '(identifier_list ')' ';.

  blockdeclaration_part statement_part .

    constant= [ '+' | '-' ] ( CONSTANT_NAME | NUMBER ) | STRING .

    typesimple_type | structured_type | TYPE_NAME .
      simple_typeconstant '..constant.
      structured_typearray_type | record_type .
        array_typeARRAY '[index_type { ',index_type } ']OF
            element_type .
          index_typesimple_type .
          element_typetype .
        record_typeRECORD field_list END .
          field_listrecord_section { ';record_section } .
            record_sectionidentifier_list ':type .

    declaration_part= [ constant_definition_part ]
        [ type_definition_part ] [ variable_declaration_part ]
        procedure_and_function_declaration_part .
      constant_definition_partCONST constant_definition ';'
          { constant_definition ';' } .
        constant_definitionNAME '=constant .
      type_definition_partTYPE type_definition ';' { type_definition ';' } .
        type_definitionNAME '=type .
      variable_declaration_partVAR variable_declaration ';'
          { variable_declaration ';' } .
        variable_declarationidentifier_list ':type .
      procedure_and_function_declaration_part=
          { ( procedure_declaration | function_declaration ) ';' } .
        formal_parameter_list= '(formal_parameter_section
            { ';formal_parameter_section } ').
          formal_parameter_section= [ VAR ]identifier_list ':parameter_type .
            parameter_typeTYPE_NAME .
        procedure_headingPROCEDURE NAME [ formal_parameter_list ] .
        function_headingFUNCTION NAME [ formal_parameter_list ] ':result_type .
          result_typeTYPE_NAME .

        procedure_declarationprocedure_heading ';block.
        function_declarationfunction_heading ';'  block  .

    statement_partBEGIN statement_sequence END .
      statement_sequencestatement { ';statement } .

        expressionF .
        expression_listexpression { ',expression } .

        variable_accessACCESS_NAME { end_access } .
          end_access= { array_access | record_access | function_parameters } .
            array_access= '[expression_list '].
            record_access= '.variable_access .
            function_parameters= '(' [ expression_list ] ').

        actual_parameter_list= '(expression { ',expression } ').

        expressionsimple_expression [ relational_operator simple_expression ] .
          relational_operator= '=' | '<>' | '<' | '<=' | '>' | '>=.
          simple_expression= [ '+' | '-' ] term { addition_operator term } .
            addition_operator= '+' | '-' | OR .
            termfactor { multiplication_operator factor } .
              multiplication_operator= '*' | '/' | DIV | MOD | AND .
              factorNUMBER | STRING | CONSTANT_NAME
                  | variable_access | function_designator
                  | '(expression ')' | NOT factor .
                function_designatorFUNCTION_NAME [ actual_parameter_list ] .

        statement= ( simple_statement | structured_statement ) .
          simple_statement= [ assignment_statement | procedure_statement ] .
            assignment_statement= ( variable_access | FUNCTION_NAME ) ':=expression .
            procedure_statementPROCEDURE_NAME [ actual_parameter_list ] .
          structured_statementcompound_statement | repetitive_statement
              | conditional_statement .
            compound_statementBEGIN statement_sequence END .
            repetitive_statementwhile_statement | repeat_statement
                | for_statement .
              while_statementWHILE expression DO statement .
              repeat_statementREPEAT statement_sequence UNTIL expression .
              for_statementFOR VARIABLE_NAME ':=initial_expression
                  ( TO | DOWNTO ) final_expression DO statement .
                initial_expressionexpression .
                final_expressionexpression .
            conditional_statementif_statement | case_statement .
              if_statementIF expression THEN statement [ ELSE statement ] .
              case_statementCASE expression OF
                  case_element { ';case_element } [ ';' ] END .
                case_elementcase_label_list ':statement .
                  case_label_listconstant { ',constant } .
.




3 - Comments



As usual:
  • please tell us at fcolibri@felix-colibri.com if you found some errors, mistakes, bugs, broken links or had some problem downloading the file. Resulting corrections will be helpful for other readers
  • we welcome any comment, criticism, enhancement, other sources or reference suggestion. Just send an e-mail to fcolibri@felix-colibri.com.
  • or more simply, enter your (anonymous or with your e-mail if you want an answer) comments below and clic the "send" button
    Name :
    E-mail :
    Comments * :
     

  • and if you liked this article, talk about this site to your fellow developpers, add a link to your links page ou mention our articles in your blog or newsgroup posts when relevant. That's the way we operate: the more traffic and Google references we get, the more articles we will write.



4 - The author

Felix John COLIBRI works at the Pascal Institute. Starting with Pascal in 1979, he then became involved with Object Oriented Programming, Delphi, Sql, Tcp/Ip, Html, UML. Currently, he is mainly active in the area of custom software development (new projects, maintenance, audits, BDE migration, Delphi Xe_n migrations, refactoring), Delphi Consulting and Delph training. His web site features tutorials, technical papers about programming with full downloadable source code, and the description and calendar of forthcoming Delphi, FireBird, Tcp/IP, Web Services, OOP  /  UML, Design Patterns, Unit Testing training sessions.
Created: nov-04. Last updated: jul-15 - 98 articles, 131 .ZIP sources, 1012 figures
Copyright © Felix J. Colibri   http://www.felix-colibri.com 2004 - 2015. All rigths reserved
Back:    Home  Papers  Training  Delphi developments  Links  Download
the Pascal Institute

Felix J COLIBRI

+ Home
  + articles_with_sources
    + database
    + web_internet_sockets
    + oop_components
    + uml_design_patterns
    + debug_and_test
    + graphic
    + controls
    + colibri_utilities
    + colibri_helpers
    + delphi
    + firemonkey
    + compilers
      – pl0_grammar
      – pascal_s_grammar
      – pascal_grammar
      – delphi_5_grammar
  + delphi_training
  + delphi_developments
  + sweet_home
  – download_zip_sources
  + links
Contacts
Site Map
– search :

RSS feed  
Blog