{"id":18879311,"url":"https://github.com/vtereshkov/xdp","last_synced_at":"2026-01-27T16:32:27.236Z","repository":{"id":110319571,"uuid":"195298026","full_name":"vtereshkov/xdp","owner":"vtereshkov","description":"XD Pascal: A small Pascal compiler for MS-DOS","archived":false,"fork":false,"pushed_at":"2019-07-06T09:32:03.000Z","size":125,"stargazers_count":46,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-31T06:23:03.131Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Pascal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vtereshkov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-04T20:30:28.000Z","updated_at":"2025-05-14T19:16:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"8d20ac51-4af5-4cb6-b1e8-82c63bd408f0","html_url":"https://github.com/vtereshkov/xdp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vtereshkov/xdp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vtereshkov%2Fxdp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vtereshkov%2Fxdp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vtereshkov%2Fxdp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vtereshkov%2Fxdp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vtereshkov","download_url":"https://codeload.github.com/vtereshkov/xdp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vtereshkov%2Fxdp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28816563,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T12:25:15.069Z","status":"ssl_error","status_checked_at":"2026-01-27T12:25:05.297Z","response_time":168,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T06:35:12.209Z","updated_at":"2026-01-27T16:32:27.221Z","avatar_url":"https://github.com/vtereshkov.png","language":"Pascal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XD Pascal Compiler\n\n## Summary\nXD Pascal is a small educational compiler for a subset of the Pascal language. A native x86 machine code generator directly emits COM executables for MS-DOS. The compiler supports VGA graphics, floating-point arithmetic, etc. 32-bit Pascal source is provided.\n\n### Features\n* Fast recursive descent parsing\n* Native x86 code generation (COM executables)\n* No external assembler or linker\n* Source file inclusion facility\n* Single-precision floating-point arithmetic (using the x87 FPU)\n* VGA graphics support\n* Compiler source for both Windows (Delphi) and DOS (TMT Pascal)\n\n## Detailed description\n### Preamble\nThe software is in the public domain. It comes with absolutely no warranty.\nAny comments, suggestions, or bug reports are VERY MUCH appreciated. \nFeel free to contact me via e-mail. \nEnjoy.\n\n### Usage\nType in the command prompt:\n```\nxdp \u003cfile.pas\u003e [/n]\n```\nOption: `/n` - disable code optimization.\nThe source file should be specified with its extension (.pas).\n \n### Language\n\n#### Overview\nXD Pascal is a dialect of Pascal programming language that resembles\nTurbo Pascal v. 3.0 with the following differences and limitations:\n* There are no labels, \"goto\" and \"with\" statements. \n* Unsigned integers, sets, enumerations, and variant records are not supported.\n* Strings are null-terminated arrays of characters (C style). String \n  manipulation routines should be used instead of direct concatenation\n  or comparison.\n* The only file type is Text. It can be used for both text and untyped files.\n* Structured parameters cannot be passed to subroutines by value.\n* The predefined Result variable can be used instead of function \n  name in assignments (Delphi style).\n* Single-line comments (\"//\") are supported (Delphi style).  \n\n#### Formal grammar\n```\nProgram = \"program\" Ident \";\" Block \".\" .\n\nBlock = { [ \"const\" Ident \"=\" ConstExpression \";\"\n                   {Ident \"=\" ConstExpression \";\"} ]\n          [ \"type\" Ident \"=\" Type \";\" {Ident \"=\" Type \";\"} ]\n          [ \"var\" IdentList \":\" Type \";\" {IdentList \":\" Type \";\"} ]\n          [ \"procedure\" Ident [FormalParam] \";\" \n                        (Block | \"forward\") \";\" ]\n          [ \"function\"  Ident [FormalParam] [\":\" TypeIdent] \";\" \n                        (Block | \"forward\") \";\" ] }\n             CompoundStatement .\n\nActualParam = \"(\" (Expression | Designator) |\n             {\",\" (Expression | Designator)} \")\" .\n\nFormalParam = \"(\" [\"const\" | \"var\"] IdentList \":\" TypeIdent \n             {\";\" [\"const\" | \"var\"] IdentList \":\" TypeIdent} \")\" .\n\nIdentList = Ident {\",\" Ident} .\n\nType = \"^\" TypeIdent |\n       \"array\" \"[\" Type {\",\" Type} \"]\" \"of\" Type |\n       \"record\" IdentList \":\" Type {\";\" IdentList \":\" Type} [\";\"] \"end\" |\n       ConstExpression \"..\" ConstExpression |\n       TypeIdent .\n\nDesignator = Ident {\"^\" | (\"[\" Expression {\",\" Expression} \"]\") | (\".\" Ident)} .\n\nStatement = [ (Designator | Ident) \":=\" Expression | \n              Ident [ActualParam] |\n              CompoundStatement |\n              \"if\" Expression \"then\" Statement [\"else\" Statement] |\n              \"case\" Expression \"of\" CaseElement {\";\" CaseElement} \n                    [\"else\" StatementList] [\";\"] \"end\" |\n              \"while\" Expression \"do\" Statement |\n              \"repeat\" StatementList \"until\" Expression | \n              \"for\" Ident \":=\" Expression (\"to\" | \"downto\") Expression \"do\"\n                    Statement ].\n\nStatementList = Statement {\";\" Statement} .\n\nCompoundStatement = \"begin\" StatementList \"end\" .\n \nCaseElement = CaseLabel {\",\" CaseLabel} \":\" Statement .\n\nCaseLabel = ConstExpression [\"..\" ConstExpression] .\n\nConstExpression = Expression .\n\nExpression = SimpleExpression [(\"=\"|\"\u003c\u003e\"|\"\u003c\"|\"\u003c=\"|\"\u003e\"|\"\u003e=\") SimpleExpression] .\n\nSimpleExpression = [\"+\"|\"-\"] Term {(\"+\"|\"-\"|\"or\"|\"xor\") Term}.\n\nTerm = Factor {(\"*\"|\"/\"|\"div\"|\"mod\"|\"shl\"|\"shr\"|\"and\") Factor}.\n\nFactor = Ident [ActualParam] |\n         Designator |\n         \"@\" Designator | \n         Number | \n         CharLiteral |\n         StringLiteral |  \n         \"(\" Expression \")\" | \n         \"not\" Factor |\n         \"nil\" |\n         TypeIdent \"(\" Expression \")\" .\n\nTypeIdent = Ident .\n\nIdent = (Letter | \"_\") {Letter | \"_\" | Digit}.\n\nNumber = \"$\" HexDigit {HexDigit} | \n         Digit {Digit} [\".\" {Digit}] [\"e\" [\"+\" | \"-\"] Digit {Digit}] .\n\nCharLiteral = \"'\" (Character | \"'\" \"'\") \"'\" | \n              \"#\" Number .\n\nStringLiteral = \"'\" {Character | \"'\" \"'\"} \"'\".\n```\n\n#### Predefined identifiers\nThe following identifiers are implemented as a part of the compiler. Their names\nare not reserved words and can be locally redefined by the user.\n\nConstants:\n```pascal\nTRUE\nFALSE\n```\nTypes:\n```pascal\nInteger\nSmallInt\nShortInt\nChar\nBoolean\nReal\nPointer\nText\nString\n```\nProcedures (inlined):\n```pascal\nprocedure Inc(var x: Integer)\nprocedure Dec(var x: Integer)\nprocedure Read([F: Text;] var x1 {; var xi})\nprocedure Write([F: Text;] x1 {; xi})\nprocedure ReadLn([F: Text;] var x1 {; var xi})\nprocedure WriteLn([F: Text;] x1 {; xi})\nprocedure InP(port: Integer; var x: Char)\nprocedure OutP(port: Integer; x: Char)\nprocedure New(var P: Pointer)\nprocedure Dispose(var P: Pointer)\nprocedure Halt[(const error: Integer)]\nprocedure Intr(const number: Integer; regs: ^TRegisters)\n```\nFunctions (inlined):\n```pascal\nfunction SizeOf(var x | T): Integer\nfunction Ord(x: T): Integer\nfunction Chr(x: Integer): Char\nfunction Pred(x: T): T\nfunction Succ(x: T): T\nfunction Round(x: Real): Integer \nfunction Abs(x: T): T\nfunction Sqr(x: T): T\nfunction Sin(x: Real): Real  \nfunction Cos(x: Real): Real  \nfunction Arctan(x: Real): Real  \nfunction Exp(x: Real): Real\nfunction Ln(x: Real): Real\nfunction SqRt(x: Real): Real\n```\n### Compiler \nThe compiler builds a DOS .com executable file according to the small\nmemory model. The program has the segments of code (pointed by CS), \ndata (pointed by DS) and stack (pointed by SS): \n\n![Memory map](memory.png)\n\nA program may have up to 64 Kb of code and up to 64 Kb of data.\nIt contains machine instructions with 16-bit and 32-bit operands and\ncan be run on a 80386+ machine in the real mode under DOS/NTVDM/DOSBox. \nBy default, the compiler does some code optimization by eliminating \nprocedures and functions which are never called. \nTo detect them, two compilation passes are performed instead of one\nand a call graph is built.\n\n### System library\nItems marked with * should not be used directly.\n\nConstants:\n```pascal\npi\nSEEKSTART * \nSEEKCUR * \nSEEKEND *\n```\nTypes:\n```pascal\nLongInt\nSingle\nPChar\nTStream *\nPStream * \nTRegisters \n```\nVariables:\n```pascal\nRandSeed: Integer\nIOError: Integer *\nLastReadChar: Char *\n```\nProcedures and functions:\n```pascal\nfunction Timer: Integer\nfunction KeyPressed: Boolean\nprocedure Randomize\nfunction Random: Real\nfunction Min(x, y: Real): Real\nfunction IMin(x, y: Integer): Integer\nfunction Max(x, y: Real): Real\nfunction IMax(x, y: Integer): Integer\nprocedure ReadConsole(var Ch: Char)\nprocedure WriteConsole(Ch: Char)\nprocedure Rewrite(var F: Text; const Name: string)\nprocedure Reset(var F: Text; const Name: string)\nprocedure Close(F: Text)\nprocedure BlockRead(F: Text; Buf: PChar; Len: SmallInt; var LenRead: SmallInt)\nprocedure BlockWrite(F: Text; Buf: PChar; Len: SmallInt)\nprocedure DeleteFile(const Name: string)\nfunction SeekFile(F: Text; Pos: Integer; Mode: ShortInt): Integer *\nprocedure Seek(F: Text; Pos: Integer)\nfunction FilePos(F: Text): Integer\nfunction EOF(F: Text): Boolean\nfunction IOResult: Integer\nprocedure WriteCh(F: Text; P: PStream; ch: Char) *\nprocedure WriteInt(F: Text; P: PStream; Number: Integer) *\nprocedure WriteHex(F: Text; P: PStream; Number: Integer; Digits: ShortInt); *\nprocedure WritePointer(F: Text; P: PStream; Number: Integer) *\nprocedure WriteReal(F: Text; P: PStream; Number: Real) *\nprocedure WriteString(F: Text; P: PStream; const s: string) *\nprocedure WriteBoolean(F: Text; P: PStream; Flag: Boolean) *\nprocedure WriteNewLine(F: Text; P: PStream) *\nprocedure ReadCh(F: Text; P: PStream; var ch: Char) *\nprocedure ReadInt(F: Text; P: PStream; var Number: Integer) *\nprocedure ReadReal(F: Text; P: PStream; var Number: Real) *\nprocedure ReadString(F: Text; P: PStream; const s: string) *\nprocedure ReadNewLine(F: Text; P: PStream) *\nfunction StrLen(const s: string): SmallInt\nprocedure StrCopy(var Dest: string; const Source: string)\nprocedure StrCat(var Dest: string; const Source: string)\nfunction StrComp(const s1, s2: string): Integer\nprocedure Val(const s: string; var Number: Real; var Code: Integer)\nprocedure Str(Number: Real; var s: string)\nprocedure IVal(const s: string; var Number: Integer; var Code: Integer)\nprocedure IStr(Number: Integer; var s: string)\nprocedure SetScreenMode(mode: Integer)\nprocedure PutPixel(x, y, clr: Integer)\nprocedure Line(x1, y1, x2, y2, clr: Integer)\nprocedure Circle(x, y, r, clr: Integer)\nprocedure OutCharXY(x, y, clr: Integer; ch: Char) *\nprocedure OutTextXY(x, y, clr: Integer; const s: string)\n```\n### Samples\n* `FACTOR.PAS`   - Integer factorization demo.\n* `LINEQ.PAS`    - Linear algebraic equation systems solver. Uses `GAUSS.PAS` unit. Requires `EQ.DAT`, `EQERR.DAT`, or similar data file.\n* `LIFE.PAS`     - The Game of life.\n* `CANNABIS.PAS` - Cannabola plot in polar coordinates.\n* `FRACTAL.PAS`  - Mandelbrot set fragment plot.\n* `SORT.PAS`     - Array sorting demo.\n* `FFT.PAS`      - Fast Fourier Transform.\n* `CLOCK.PAS`    - Clock demo.\n* `INSERR.PAS`   - Inertial navigation system error estimator. Uses `KALMAN.PAS` unit.\n* `PALETTE.PAS`  - Graphics palette usage demo.\n* `LIST.PAS`     - Linked list operations demo.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvtereshkov%2Fxdp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvtereshkov%2Fxdp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvtereshkov%2Fxdp/lists"}