|
(* Formalism for ISO-7185:1990 "Pascal" Syntax *) |
|
(* These will be extended into an AST *) |
|
(* ISO Pascal is different from Delphi *) |
|
(* Please submit your comments to chubakbidpaa [at] riseup [dot] net *) |
|
|
|
type pas_kw = And | Array | Begin | Case | Const |
|
| Div | Do | Downto | Else | End |
|
| File | For | Function | Goto |
|
| If | In | Label | Mod | Nil |
|
| Not | Of | Or | Packed | Procedure |
|
| Program | Record | Repeat | Set |
|
| Then | To | Until | Var | While | With |
|
|
|
and pas_val = |
|
Number of float | CharString of string | Id of string |
|
|
|
and pas_type_val = |
|
| SimpleType of pas_simple_type |
|
| OrginalType of pas_ordinal_type |
|
| StructuredType of pas_structured_type * bool |
|
| PointerType of string |
|
| FuncType of pas_func_type |
|
| Alias of string |
|
|
|
and pas_simple_type = IntegerType | RealType | BoolType | CharType |
|
|
|
and pas_ordinal_type = |
|
| Enumerated of string list | Range of (int * int) list |
|
|
|
and pas_structured_type = |
|
| Array of pas_array_unit list |
|
| Record of { |
|
fixed_part: pas_rec_fixed_part list option; |
|
variant_part: pas_rec_variant_part list option; |
|
} |
|
| Set of pas_type_val |
|
| File of pas_type_val |
|
|
|
and pas_array_unit = |
|
{ index_type: pas_type_val; component_type: string; } |
|
|
|
and pas_rec_fixed_part = { names: string list; |
|
typs: pas_type_val list; } |
|
and pas_rec_variant_part = { selector: (string * string option); |
|
variants: (string list * pas_type_val) list; } |
|
|
|
and pas_func_type = { name: string; |
|
params: pas_param list; |
|
result_type: pas_type_val; } |
|
|
|
and pas_param = { name: string option; typ: pas_type_val; } |
|
|
|
and pas_block = LabelDecl of pas_label list |
|
| ConstDecl of pas_const list |
|
| TypeDecl of pas_type list |
|
| VarDecl of pas_var list |
|
| ProcDecl of pas_proc list |
|
| FuncDecl of pas_func list |
|
| StmtDecl of pas_stmt list |
|
|
|
and pas_label = { name: string; value: int } |
|
|
|
and pas_const = { name: string; value: pas_val; typ: pas_type_val; } |
|
|
|
and pas_var = | Basic of { name: string; points: bool; index: pas_val list; } |
|
| Long of pas_var list |
|
|
|
and pas_type = { name: string; value: pas_type_val; } |
|
|
|
and pas_proc = { name: string; params: pas_param list; body: pas_stmt list; } |
|
|
|
and pas_func = { typ: pas_func_type; body: pas_stmt list; } |
|
|
|
and pas_stmt = | BlockStmt of pas_block |
|
| Expression of pas_expr |
|
| Controlflow of pas_control |
|
| Assignment of pas_var * pas_expr |
|
|
|
and pas_expr = | Var of pas_var |
|
| Call of pas_var * pas_val list |
|
| Infix of { left: pas_expr list; |
|
right: pas_expr list; |
|
operator: pas_infixop; } |
|
| Prefix of pas_prefixop * pas_expr |
|
|
|
and pas_infixop = Add | Sub | Mul | Div | IDiv | Mod | Eq | Ne | Lt | Le |
|
| Gt | Ge | BitAnd | BitOr | Xor | And | Or | Union |
|
| Diff | Inter | SymDiff | Incl | Cat |
|
|
|
and pas_prefixop = UMin | UPos | BitNot | Deref | AddrOf |
|
|
|
and pas_control = | If of { cond: pas_expr; |
|
branches: (pas_expr * pas_block) list; |
|
clause: pas_block } |
|
| Case of { disc: pas_expr; |
|
clauses: (pas_expr * pas_block); |
|
default: pas_block; } |
|
| Loop of { starter: pas_stmt; |
|
ender: pas_stmt; |
|
ranger: pas_kw; |
|
block: pas_block; |
|
} |
|
| While of { cond: pas_expr; |
|
block: pas_block; } |
|
| RepeatUntil of { block: pas_block; cond: pas_expr; } |
|
| With of { var: pas_var; block: pas_block; } |
|
| Goto of string |
|
|
|
and pas_program = { name: string; blocks: pas_block list; } |