-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathLLVM_Pascal.bnf
156 lines (156 loc) · 7.55 KB
/
LLVM_Pascal.bnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
Goal : (Program | Unit | Library | Package).
Program : 'PROGRAM' Ident ['(' IdentList ')'] ';' ProgramBlock '.'.
Unit : 'UNIT' Ident ';'
InterfaceSection
ImplementationSection
InitSection '.'.
Library : 'LIBRARY' Ident ';'
ProgramBlock '.'.
Package : 'PACKAGE' Ident ';'
[RequiresClause]
[ContainsClause]
'END' '.'.
ProgramBlock : [UsesClause]
Block.
UsesClause : 'USES' IdentList ';'.
InterfaceSection : 'INTERFACE'
[UsesClause]
[InterfaceDecl]*.
InterfaceDecl : (ConstSection | TypeSection | VarSection | ExportedHeading).
ExportedHeading : (ProcedureHeading ';' DirectiveList | FunctionHeading ';' DirectiveList).
ImplementationSection : 'IMPLEMENTATION'
[UsesClause]
[DeclSection]*.
Block : [DeclSection]
CompoundStmt.
DeclSection : (ConstSection | TypeSection | VarSection | ProcedureDeclSection | LabelDeclSection)*.
LabelDeclSection : 'LABEL' LabelId.
ConstSection : 'CONST' (ConstantDecl ';')*.
ConstantDecl : Ident ('=' ConstExpr | ':' TypeId '=' TypedConstant).
TypeSection : 'TYPE' (TypeDecl ';')*.
TypeDecl : Ident '=' (Type | RestrictedType).
TypedConstant : (ConstExpr | ArrayConstant | RecordConstant).
ArrayConstant : '(' (TypedConstant ','/)* ')'.
RecordConstant : '(' (RecordFieldConstant';'/)* ')'.
RecordFieldConstant : Ident ':' TypedConstant.
Type : (TypeId | SimpleType | StrucType | PointerType | StringType
| ProcedureType | ClassRefType).
RestrictedType : (ObjectType | ClassType | InterfaceType).
ClassRefType : 'CLASS' 'OF' TypeId.
SimpleType : (OrdinalType | RealType).
// Real48 abolido
RealType : ('REAL' | 'SINGLE' | 'DOUBLE' | 'EXTENDED' | 'CURRENCY' | 'COMP').
OrdinalType : (SubrangeType | EnumeratedType | OrdIdent).
// Acresentado Cardinal e UInt64
OrdIdent : ('INTEGER' | 'CHAR' | 'BOOLEAN' | 'BYTE' | 'WORD' | 'CARDINAL' | 'LONGINT' | 'INT64' | 'UINT64' |
'WIDECHAR' | 'LONGWORD' | 'SHORTINT' | 'SMALLINT' | 'PCHAR').
// Variant abolido
SubrangeType : ConstExpr '..' ConstExpr.
EnumeratedType : '(' IdentList ')'.
// Ansistring abolido
StringType : ('STRING' | 'WIDESTRING' | 'STRING' '[' ConstExpr ']').
StrucType : ['PACKED'] (ArrayType | SetType | FileType | RecType).
ArrayType : 'ARRAY' ['[' (OrdinalType ','/)* ']'] 'OF' Type.
RecType : 'RECORD' [FieldList] 'END'.
FieldList : (FieldDecl ';'/)* [VariantSection] [';'].
FieldDecl : IdentList ':' Type.
VariantSection : 'CASE' [Ident ':'] TypeId 'OF' (RecVariant ';'/)*.
RecVariant : (ConstExpr ','/)* ':' '(' [FieldList] ')'.
// set com até 2G
SetType : 'SET' 'OF' OrdinalType.
// Acrescentado TEXT e untyped File
FileType : ('FILE' ['OF' TypeId] | 'TEXT').
PointerType : '^' TypeId.
ProcedureType : (ProcedureHeading | FunctionHeading) ['OF' 'OBJECT'].
VarSection : 'VAR' (VarDecl ';')*.
// Absolute em endereços fixos abolido
VarDecl : IdentList ':' Type [('ABSOLUTE' Ident) | '=' ConstExpr].
Expression : SimpleExpression [RelOp SimpleExpression]*.
SimpleExpression : ['+' | '-'] Term [AddOp Term]*.
Term : Factor [MulOp Factor]*.
Factor : (Designator ['(' ExprList ')'] | '' Designator | Number | String | 'NIL' |
'(' Expression ')' | 'NOT' Factor | SetConstructor | TypeId '(' Expression ')').
RelOp : ('>' | '<' | '<=' | '>=' | '<>' | 'IN' | 'IS' | 'AS').
AddOp : ('+' | '-' | 'OR' | 'XOR').
//Acrescido **
MulOp : ('*' | '/' | 'DIV' | 'MOD' | 'AND' | 'SHL' | 'SHR' | '**').
Designator : QualId ['.' Ident | '[' ExprList ']' | '^']*.
SetConstructor : '[' [SetElement ','/]* ']'.
SetElement : Expression ['..' Expression].
ExprList : (Expression ','/)*.
Statement : [LabelId ':'] [SimpleStatement | StructStmt].
StmtList : (Statement [';'])*.
// Depois do inherited pode vir um designator gramática errada!
SimpleStatement : (Designator ['(' ExprList ')'] | '' Designator ':=' Expression | 'INHERITED' | 'GOTO' LabelId).
// Acrescentado Asm
StructStmt : (CompoundStmt | ConditionalStmt | LoopStmt | WithStmt | AsmStmt).
CompoundStmt : 'BEGIN' StmtList 'END'.
AsmStmt : 'ASM' AsmList 'END'.
ConditionalStmt : (IfStmt | CaseStmt).
IfStmt : 'IF' Expression 'THEN' Statement ['ELSE' Statement].
// Case aceitando qualquer expressão
CaseStmt : 'CASE' Expression 'OF' (CaseSelector ';')* ['ELSE' Statement [';']] 'END'.
CaseSelector : (CaseLabel ','/)* ':' Statement.
CaseLabel : ConstExpr ['..' ConstExpr].
LoopStmt : (RepeatStmt | WhileStmt | ForStmt).
RepeatStmt : 'REPEAT' Statement 'UNTIL' Expression.
WhileStmt : 'WHILE' Expression 'DO' Statement.
ForStmt : 'FOR' QualId ':=' Expression ('TO' | 'DOWNTO') Expression 'DO' Statement.
WithStmt : 'WITH' IdentList 'DO' Statement.
ProcedureDeclSection : (ProcedureDecl | FunctionDecl).
//Corrigido só aceitava uma diretiva e sem ; no final
ProcedureDecl : ProcedureHeading ';' DirectiveList Block ';'.
FunctionDecl : FunctionHeading ';' DirectiveList Block ';'.
// Trocado SimpleType por TypeId
FunctionHeading : 'FUNCTION' Ident [FormalParameters] ':' (TypeId | 'STRING').
ProcedureHeading : 'PROCEDURE' Ident [FormalParameters].
FormalParameters : '(' (FormalParm ';'/)* ')'.
FormalParm : ['VAR' | 'CONST' | 'OUT'] Parameter.
// Acrescentado array of const e trocado SimpleType por TypeId
Parameter : (IdentList [':' (TypeId | 'STRING' | 'FILE' | 'ARRAY' 'OF' ('CONST' | TypeId)] )] |
Ident ':' TypeId '=' ConstExpr).
Directive : ('CDECL' | 'REGISTER' | 'DYNAMIC' | 'VIRTUAL' | 'EXPORT' | 'EXTERNAL' | 'FAR' | 'FORWARD' | 'MESSAGE' |
'OVERRIDE' | 'OVERLOAD' | 'PASCAL' | 'REINTRODUCE' | 'SAFECALL' | 'STDCALL').
DirectiveList : [Directive ';']*
ObjectType : 'OBJECT' [ObjHeritage] [ObjFieldList] [MethodList] 'END'.
ObjHeritage : '(' QualId ')'.
// Só aceitava a diretiva virtual e tinha erro no ;
MethodList : (MethodHeading ';' DirectiveList)*.
MethodHeading : (ProcedureHeading | FunctionHeading | ConstructorHeading | DestructorHeading).
ConstructorHeading : 'CONSTRUCTOR' Ident [FormalParameters].
DestructorHeading : 'DESTRUCTOR' Ident [FormalParameters].
// erro no ;
ObjFieldList : (IdentList ':' Type ';')*.
InitSection : ('INITIALIZATION' StmtList ['FINALIZATION' StmtList] | ['BEGIN' StmtList]) 'END'.
ClassType : 'CLASS' [ClassHeritage]
[ClassFieldList]
[ClassMethodList]
[ClassPropertyList]
'END'.
ClassHeritage : '(' IdentList ')'.
// Acrescentado Automated
ClassVisibility : ['PUBLIC' | 'PROTECTED' | 'PRIVATE' | 'PUBLISHED' | 'AUTOMATED'].
ClassFieldList : (ClassVisibility ObjFieldList)*.
ClassMethodList : (ClassVisibility MethodList)*.
ClassPropertyList : (ClassVisibility PropertyList)*.
PropertyList : ('PROPERTY' Ident [PropertyInterface] PropertySpecifiers)*.
PropertyInterface : [PropertyParameterList] ':' Ident.
PropertyParameterList : '[' (IdentList ':' TypeId ';')* ']'.
PropertySpecifiers : ['INDEX' ConstExpr] ['READ' Ident] ['WRITE' Ident] ['STORED' (Ident | Constant)]
['DEFAULT' ConstExpr | 'NODEFAULT'] ['IMPLEMENTS' TypeId]
// Trocado classmethodlist e classpropertylist por methodlist e propertylist
InterfaceType : 'INTERFACE' [InterfaceHeritage]
[MethodList]
[PropertyList]
'END'.
InterfaceHeritage : '(' IdentList ')'.
RequiresClause : ['REQUIRES' IdentList ';'].
ContainsClause : ['CONTAINS' IdentList ';'].
IdentList : (Ident ','/)*.
QualId : [UnitId '.'] Ident.
TypeId : [UnitId '.'] <TypeIdentifier>.
Ident : <Identifier>.
ConstExpr : <ConstantExpression>.
UnitId : <UnitIdentifier>.
Number : <Number>.
String : <StringConstant>.