| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481 |
- COMPILER Pascal
- IGNORECASE
- CHARACTERS
- letter = 'A' .. 'Z' + 'a' .. 'z' .
- digit = '0' .. '9' .
- cr = '\r' .
- lf = '\n' .
- tab = '\t' .
- printable = '\x20' .. '\x7e' .
- all = '\x00' .. '\xff' .
- stringCh = printable - "'" .
- sign = '+-' .
- TOKENS
- identifier = letter { letter | digit } .
- characterString = "'" { stringCh | "''" } "'" .
- unsignedInteger = digit { digit } CONTEXT ( '..' ) .
- unsignedReal = digit { digit }
- ( '.' digit { digit } [ 'e' [ sign ] digit { digit } ]
- | 'e' [ sign ] digit { digit } ) .
- COMMENTS FROM '{' TO '}'
- IGNORE cr + lf + tab
- PRODUCTIONS
- Pascal =
- ProgramHeading ';' Block '.' .
- ProgramHeading =
- 'program' identifier [ ProgramParameterList ] .
- ProgramParameterList =
- '(' IdentifierList ')' .
- /*-----------------------------------------------------------------------*/
- Block =
- [ LabelDeclarationPart ]
- [ ConstantDefinitionPart ]
- [ TypeDefinitionPart ]
- [ VariableDeclarationPart ]
- { ProcedureAndFunctionDeclarationPart }
- StatementPart
- .
- LabelDeclarationPart =
- 'label' unsignedInteger { ',' unsignedInteger } ';' .
- ConstantDefinitionPart =
- 'const' ConstantDefinition ';' { ConstantDefinition ';' } .
- TypeDefinitionPart =
- 'type' TypeDefinition ';' { TypeDefinition ';' } .
- VariableDeclarationPart =
- 'var' VariableDeclaration ';' { VariableDeclaration ';' } .
- ProcedureAndFunctionDeclarationPart =
- ( ProcedureDeclaration | FunctionDeclaration ) ';' .
- StatementPart =
- CompoundStatement .
- ConstantDefinition =
- identifier '=' Constant .
- TypeDefinition =
- identifier '=' Type .
- VariableDeclaration =
- IdentifierList ':' Type .
- ProcedureDeclaration =
- ProcedureHeading ';' Block
- | ProcedureHeading ';' Directive
- | ProcedureIdentification ';' Block
- .
- FunctionDeclaration =
- FunctionHeading ';' Block
- | FunctionHeading ';' Directive
- | FunctionIdentification ';' Block
- .
- ProcedureHeading =
- 'procedure' identifier [ FormalParameterList ] .
- ProcedureIdentification =
- 'procedure' ProcedureIdentifier .
- FunctionHeading =
- 'function' identifier [ FormalParameterList ] ':' ResultType .
- FunctionIdentification =
- 'function' FunctionIdentifier.
- FormalParameterList =
- '(' FormalParameterSection { ';' FormalParameterSection } ')' .
- FormalParameterSection =
- ValueParameterSpecification
- | VariableParameterSpecification
- | ProceduralParameterSpecification
- | FunctionalParameterSpecification
- .
- /*-----------------------------------------------------------------*/
- ValueParameterSpecification =
- IdentifierList ':' ( TypeIdentifier | ConformantArraySchema ) .
- VariableParameterSpecification =
- 'var' IdentifierList ':' ( TypeIdentifier | ConformantArraySchema ) .
- ProceduralParameterSpecification =
- ProcedureHeading.
- FunctionalParameterSpecification =
- FunctionHeading .
- ConformantArraySchema =
- PackedConformantArraySchema
- | UnpackedConformantArraySchema .
- PackedConformantArraySchema =
- 'packed' 'array' '[' IndexTypeSpecification ']' 'of' TypeIdentifier .
- UnpackedConformantArraySchema =
- 'array' '[' IndexTypeSpecification ']' 'of'
- ( TypeIdentifier | ConformantArraySchema ) .
- IndexTypeSpecification =
- identifier '..' identifier ':' OrdinalTypeIdentifier .
- /*-----------------------------------------------------------------*/
- CompoundStatement =
- 'begin'
- StatementSequence
- 'end'
- .
- StatementSequence =
- Statement
- { ';' Statement }
- .
- Statement =
- [ Label ':' ] ( SimpleStatement | StructuredStatement ) .
- SimpleStatement =
- EmptyStatement
- | AssignmentStatement
- | ProcedureStatement
- | GotoStatement
- .
- StructuredStatement =
- CompoundStatement
- | ConditionalStatement
- | RepetitiveStatement
- | WithStatement
- .
- ConditionalStatement =
- IfStatement | CaseStatement .
- RepetitiveStatement =
- WhileStatement | RepeatStatement | ForStatement .
- EmptyStatement = .
- AssignmentStatement =
- ( Variable | FunctionIdentifier ) ':=' Expression .
- ProcedureStatement =
- ProcedureIdentifier [ ActualParameterList | WriteParameterList ] .
- GotoStatement =
- 'goto' Label .
- IfStatement =
- 'if' BooleanExpression 'then' Statement
- [ 'else' Statement ]
- .
- CaseStatement =
- 'case' CaseIndex 'of'
- Case { ';' Case } [ ';' ]
- 'end'
- .
- RepeatStatement =
- 'repeat'
- StatementSequence
- 'until' BooleanExpression
- .
- WhileStatement =
- 'while' BooleanExpression 'do'
- Statement
- .
- ForStatement =
- 'for' ControlVariable ':=' InitialValue ( 'to' | 'downto' ) FinalValue 'do'
- Statement
- .
- WithStatement =
- 'with' RecordVariableList 'do'
- Statement
- .
- RecordVariableList =
- RecordVariable { '.' RecordVariable } .
- CaseIndex =
- OrdinalExpression .
- Case =
- Constant { ',' Constant } ':'
- Statement
- .
- ControlVariable =
- VariableIdentifier .
- InitialValue =
- OrdinalExpression .
- FinalValue =
- OrdinalExpression .
- /*-----------------------------------------------------------------------*/
- Type =
- SimpleType | StructuredType | PointerType .
- SimpleType =
- OrdinalType | RealTypeIdentifier .
- StructuredType =
- { 'packed' } UnpackedStructuredType | StructuredTypeIdentifier .
- PointerType =
- '^' DomainType | PointerTypeIdentifier .
- OrdinalType =
- EnumeratedType | SubrangeType | OrdinalTypeIdentifier .
- UnpackedStructuredType =
- ArrayType | RecordType | SetType | FileType .
- DomainType =
- TypeIdentifier .
- EnumeratedType =
- '(' IdentifierList ')' .
- SubrangeType =
- Constant '..' Constant .
- ArrayType =
- 'array' '[' IndexType { ',' IndexType } ']' 'of' ComponentType .
- RecordType =
- 'record'
- FieldList
- 'end'
- .
- SetType =
- 'set' 'of' BaseType .
- FileType =
- 'file' 'of' ComponentType .
- IndexType =
- OrdinalType .
- ComponentType =
- Type.
- BaseType =
- OrdinalType .
- ResultType =
- OrdinalTypeIdentifier | RealTypeIdentifier | PointerTypeIdentifier .
- FieldList =
- [ ( FixedPart [ ':' VariantPart ] | VariantPart ) [';'] ] .
- FixedPart =
- RecordSection { ';' RecordSection } .
- VariantPart =
- 'case' VariantSelector 'of'
- Variant
- { ';' Variant }
- .
- RecordSection =
- IdentifierList ':' Type .
- VariantSelector =
- [ TagField ':' ] TagType .
- Variant =
- Constant { ',' Constant } ';' '(' FieldList ')' .
- TagType =
- OrdinalTypeIdentifier .
- TagField =
- identifier .
- /*--------------------------------------------------------------------*/
- Constant =
- [ Sign ] ( UnsignedNumber | ConstantIdentifier )
- | characterString .
- /*-------------------------------------------------------------------*/
- Expression =
- SimpleExpression [ RelationOperator SimpleExpression ] .
- SimpleExpression =
- [ Sign ] Term { AddingOperator Term } .
- Term =
- Factor { MultiplyingOperator Factor } .
- Factor =
- UnsignedConstant
- | BoundIdentifier
- | Variable
- | SetConstructor
- | FunctionDesignator
- | 'not' Factor
- | '(' Expression ')'
- .
- RelationOperator =
- '=' | '<>' | '<' | '<=' | '>' | '>=' | 'in' .
- AddingOperator =
- '+' | '-' | 'or' .
- MultiplyingOperator =
- '*' | '/' | 'div' | 'mod' | 'and' .
- UnsignedConstant =
- UnsignedNumber | characterString | ConstantIdentifier | 'nil' .
- FunctionDesignator =
- FunctionIdentifier [ ActualParameterList ] .
- Variable =
- EntireVariable | ComponentVariable | IdentifierVariable |
- BufferVariable .
- EntireVariable =
- VariableIdentifier .
- ComponentVariable =
- IndexedVariable | FieldDesignator .
- IdentifierVariable =
- PointerVariable '^' .
- BufferVariable =
- FileVariable '^' .
- IndexedVariable =
- ArrayVariable '[' Index { ',' Index } ']' .
- FieldDesignator =
- [ RecordVariable '.' ] FieldIdentifier .
- SetConstructor =
- '[' [ ElementDescription { ',' ElementDescription } ] ']' .
- ElementDescription =
- OrdinalExpression [ '..' OrdinalExpression ].
- ActualParameterList =
- '(' ActualParameter { ',' ActualParameter } ')' .
- ActualParameter =
- Expression | Variable | ProcedureIdentifier | FunctionIdentifier .
- WriteParameterList =
- '(' ( FileVariable | WriteParameter ) { ',' WriteParameter } ')' .
- WriteParameter =
- Expression [ ':' IntegerExpression [ ':' IntegerExpression ] ] .
- ArrayVariable =
- Variable .
- RecordVariable =
- Variable .
- FileVariable =
- Variable .
- PointerVariable =
- Variable .
- IntegerExpression =
- OrdinalExpression .
- BooleanExpression =
- OrdinalExpression .
- Index =
- OrdinalExpression .
- OrdinalExpression =
- Expression .
- PointerTypeIdentifier =
- TypeIdentifier .
- StructuredTypeIdentifier =
- TypeIdentifier .
- OrdinalTypeIdentifier =
- TypeIdentifier .
- RealTypeIdentifier =
- TypeIdentifier .
- ConstantIdentifier =
- identifier .
- TypeIdentifier =
- identifier .
- VariableIdentifier =
- identifier .
- FieldIdentifier =
- identifier .
- ProcedureIdentifier =
- identifier .
- FunctionIdentifier =
- identifier .
- BoundIdentifier =
- identifier .
- UnsignedNumber =
- unsignedInteger | unsignedReal .
- Sign =
- '+' | '-' .
- IdentifierList =
- identifier { ',' identifier } .
- Directive =
- identifier .
- Label =
- unsignedInteger .
- END Pascal.
|