home *** CD-ROM | disk | FTP | other *** search
/ cs.rhul.ac.uk / www.cs.rhul.ac.uk.zip / www.cs.rhul.ac.uk / pub / rdp / rdp_cs3470.tar / pascal.bnf < prev    next >
Text File  |  1998-05-07  |  4KB  |  82 lines

  1. (*****************************************************************************
  2. *
  3. * RDP release 1.50 by Adrian Johnstone (A.Johnstone@rhbnc.ac.uk) 20 December 1997
  4. *
  5. * pascal.bnf - standard pascal grammar with some extensions for Turbo-Pascal
  6. *
  7. * This file may be freely distributed. Please mail improvements to the author.
  8. *
  9. *****************************************************************************)
  10. TITLE("Pascal parser V1.50 (c) Adrian Johnstone 1997")
  11. SUFFIX("pas") 
  12. SHOW_SKIPS
  13. CASE_INSENSITIVE
  14. EPSILON_TREE
  15.  
  16. prog           ::= 'program' ID [ '(' (ID)@',' ')' ] ';' block '.'.
  17. block          ::= { declaration } 'begin' statement {';' statement} 'end'.
  18. declaration    ::= label_dcl_part | const_dcl_part | type_dcl_part |
  19.                    var_dcl_part | proc_dcl_part.
  20. label_dcl_part ::= 'label' (INTEGER)@',' ';'.
  21. const_dcl_part ::= 'const' {ID '=' constant ';'}.
  22. constant       ::= ['+' | '-'] (unsigned_num | ID) | STRING('\'').
  23. unsigned_num   ::= INTEGER | REAL.
  24. type_dcl_part  ::= 'type' {ID '=' type ';'}.
  25. type           ::= simple_type | ['packed'] struct_type | '^' ID.
  26. simple_type    ::= '(' (ID)@',' ')' | constant ['..' constant].
  27. struct_type    ::= 'array' '[' (simple_type)@',' ']' 'of' type |
  28.                    'record' (*consider this a scope*) field_list 'end' |
  29.                    'set' 'of' simple_type |
  30.                    'file' 'of' type.
  31. field_list     ::= fixed_part [';' variant_part] | variant_part.
  32. fixed_part     ::= ([ (ID)@',' ':' type ])@';'.
  33. variant_part   ::= 'case' ID [':' ID] 'of' variants.
  34. variants       ::= ([ (case_label)@',' ':' '(' field_list ')' ])@';'.
  35. var_dcl_part   ::= 'var' { (ID)@',' ':' type ';'}.
  36. proc_dcl_part  ::= (proc_heading | func_heading) ';' body ';'.
  37. proc_heading   ::= 'procedure' ID formal_params .
  38. func_heading   ::= 'function' ID [ formal_params ':' ID ].
  39. body           ::= block | 'forward'.
  40. formal_params  ::= [ '(' (formal_p_sect)@';' ')' ] .
  41. formal_p_sect  ::= param_group | 'var' param_group | proc_heading | func_heading.
  42. param_group    ::= (ID)@',' ':' paramtype.
  43. paramtype      ::= ID |
  44.                    'array' '[' (index_spec)@';' ']' 'of' paramtype |
  45.                    'packed' 'array' '[' (index_spec)@';' ']' 'of' ID.
  46. index_spec     ::= ID '..' ID ':' ID.
  47. statement      ::= [ INTEGER ':' statement |
  48.                      'begin' (statement)@';' 'end' |
  49.                      variable (* call *) [':=' expression] |
  50.                      'goto' INTEGER |
  51.                      'if' expression 'then' statement [ 'else' statement ] |
  52.                      'case' expression 'of' (case_list_elem)@';'
  53.                        [ ('else' | 'default') statement ] {';'} 'end' |
  54.                      'while' expression 'do' statement |
  55.                      'repeat' (statement)@';' 'until' expression |
  56.                      'for' ID ':=' expression ( 'to' | 'downto' ) expression
  57.                        'do' statement |
  58.                      'with' (variable)@',' 'do' statement
  59.                    ].
  60. case_list_elem ::= [ (case_label)@',' ':' statement ].
  61. case_label     ::= constant ['..' constant].
  62. expression     ::= simple_expr {relational_op simple_expr}.
  63. relational_op  ::= '=' | '<' | '>' | '<=' | '>=' | '<>' | 'in'.
  64. simple_expr    ::= (term | '+' term | '-' term ) { add_op term}.
  65. add_op         ::= '+' | '-' | 'or'.
  66. term           ::= factor {mult_op factor}.
  67. mult_op        ::= '*' | '/' | 'div' | 'mod' | 'and'.
  68. factor         ::= variable (* ID or function *) |
  69.                    unsigned_lit |
  70.                    '(' expression ')' |
  71.                    '[' [ (expression ['..' expression])@',' ] ']' (*set*) |
  72.                    'not' factor.
  73. unsigned_lit   ::= unsigned_num | STRING('\'') | 'nil'.
  74. variable       ::= ID [actual_params]
  75.                    {'[' (expression)@',' ']'
  76.                    | '.' ID
  77.                    | '^'}.
  78. actual_params  ::= '(' (expression [':' expression [':' expression]])@',' ')'.
  79. comment        ::= COMMENT( '{' '}' ) COMMENT( '(*' '*)' ) .
  80.  
  81. (* End of pascal.bnf *)
  82.