From 089ed0f0b4c2e08c7c5b7071153bff94547a47d3 Mon Sep 17 00:00:00 2001 From: Raphael Pour Date: Wed, 2 Feb 2022 11:58:56 +0100 Subject: [PATCH] Readme: fix highlighting --- README.MD => README.md | 126 ++++++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 63 deletions(-) rename README.MD => README.md (83%) diff --git a/README.MD b/README.md similarity index 83% rename from README.MD rename to README.md index 52b1ab1..0379a62 100644 --- a/README.MD +++ b/README.md @@ -1,4 +1,4 @@ -#PL/0 Compiler +# PL/0 Compiler This Python-based Compiler converts PL/0 source code into CL/0 virtual machine code. Both are educational languages with the aim to get faster to the real handwork of compiler-construction. @@ -33,26 +33,26 @@ Additional Features ## Examples ### Hello World -~~~~ +```basic ! "Hello World!". -~~~~ +``` ### Arithmetic expressions -~~~~ +```basic !- 3+ (-4). -~~~~ +``` ### I/O -~~~~ +```basic VAR input; BEGIN ?input; !input END. -~~~~ +``` ### If -~~~~ +```basic VAR a,b; BEGIN ?a; @@ -68,12 +68,12 @@ BEGIN IF ODD a THEN !7 END. -~~~~ +``` ### If-Else If-Else Odd-Number tester -~~~~ +```basic VAR input; PROCEDURE main; BEGIN @@ -90,10 +90,10 @@ BEGIN END END; CALL main. -~~~~ +``` Extended If-Else with a third case using Else-If. -~~~~ +```basic CONST pHNeutral=7; VAR input; PROCEDURE main; @@ -105,10 +105,10 @@ BEGIN ELSE !"Acid" END; CALL main. -~~~~ +``` ### While-Loop -~~~~ +```basic VAR a, fak; BEGIN ?a; @@ -121,10 +121,10 @@ BEGIN ! fak END END . -~~~~ +``` ### Define Procedures/ Constants/ Variables -~~~~ +```basic CONST a=5; VAR b; PROCEDURE main; @@ -134,17 +134,17 @@ PROCEDURE main; !b END; CALL main. -~~~~ +``` ### Procedures with parameters -~~~~ +```basic PROCEDURE f(x); !x; CALL f(7331). -~~~~ +``` Exponentiation programm using a self implemented pow function -~~~~ +```basic VAR result,i,a,b; PROCEDURE pow(base,power); BEGIN @@ -161,10 +161,10 @@ BEGIN ?b; CALL pow(a,b) END. -~~~~ +``` ### For-Loop -~~~~ +```basic CONST k=5; VAR i,j; PROCEDURE main; @@ -175,10 +175,10 @@ BEGIN END END; CALL main. -~~~~ +``` ### Arrays -~~~~ +```basic VAR x[4],i; BEGIN FOR(i:=0; i < 4; i:=i+1) @@ -187,10 +187,10 @@ BEGIN !x[i] END END. -~~~~ +``` Sorting numbers -~~~~ +```basic VAR x[5],i,j,tmp; BEGIN /* Initialize "random" int vector*/ @@ -214,10 +214,10 @@ BEGIN FOR(i:=0; i < 5; i:=i+1) !x[i] END. -~~~~ +``` ### Recursion -~~~~ +```basic CONST a=5; VAR b; PROCEDURE sub; @@ -232,20 +232,20 @@ PROCEDURE main; CALL sub END; CALL main. -~~~~ +``` ### Logical Expressions -~~~ +```basic BEGIN IF { ODD 1 AND NOT ODD 1} OR NOT ODD 1 THEN !1 ELSE !2 END. -~~~ +``` ### Number guessing game -~~~~ +```basic /* * Number-Guessing Game * @@ -307,22 +307,22 @@ BEGIN END END; CALL main. -~~~~ +``` ## Language specification -~~~ +```ebnf ::= '.'. ::= [ ] [ ] - { } . - ::= 'CONST' {',' } ';'. - ::= ident '=' number. - ::= 'VAR' {',' } ';'. - ::= ident [ '[' number ']' ]. - ::= 'PROCEDURE' ident ['(' [ ] ')' ] ';' ';'. - ::= 'CALL' ident ['(' [ ] ')' ] - ::= ident {',' ident } - ::= {',' } + { } . + ::= 'CONST' { ',' } ';' . + ::= ident '=' number . + ::= 'VAR' { ',' } ';' . + ::= ident [ '[' number ']' ] . + ::= 'PROCEDURE' ident [ '(' [ ] ')' ] ';' ';' . + ::= 'CALL' ident [ '(' [ ] ')' ] + ::= ident { ',' ident } + ::= { ',' } ::= | | @@ -331,27 +331,27 @@ CALL main. | | | - | 'RETURN'. - ::= 'BEGIN' { ';' STATEMENT } 'END'. - ::= '?' ident. - ::= '!' (string | ). - ::= ident ':=' . - ::= '[' ']'. - ::= 'IF' 'THEN' ['ELSE' ]. + | 'RETURN' . + ::= 'BEGIN' { ';' STATEMENT } 'END' . + ::= '?' ident . + ::= '!' ( string | ) . + ::= ident ':=' . + ::= '[' ']' . + ::= 'IF' 'THEN' [ 'ELSE' ] . ::= 'ODD' - | ('=' | '#' | '<' | '<=' | '>' | '>=') . - ::= 'WHILE' 'DO' . - ::= 'FOR' '(' ';' '; ')' . - ::= ['+' | '-'] term { ('+' | '-') }. - ::= { ( '*' | '/' ) }. + | ( '=' | '#' | '<' | '<=' | '>' | '>=' ) . + ::= 'WHILE' 'DO' . + ::= 'FOR' '(' ';' ';' ')' . + ::= [ '+' | '-' ] term { ( '+' | '-' ) } . + ::= { ( '*' | '/' ) } . ::= ident [ ] | number - | '(' ')'. - ::= LOGICAL_TERM {'OR' LOGICAL_TERM}. - ::= ['NOT'] LOGICAL_FACTOR {'AND' ['NOT'] LOGICAL_FACTOR}. + | '(' ')' . + ::= LOGICAL_TERM { 'OR' LOGICAL_TERM } . + ::= [ 'NOT' ] LOGICAL_FACTOR { 'AND' [ 'NOT' ] LOGICAL_FACTOR } . ::= CONDITION - | ( '{' LOGICAL_EXPRESSION '}'). -~~~ + | ( '{' LOGICAL_EXPRESSION '}' ) . +``` ## Architecture @@ -369,9 +369,9 @@ The lexical analyzer (short: lexer) transforms source code into tokens and provi It does this transformation on-demand, when the parser asks for the next token. One token can be a symbol, number, or a whole variable identifier. Let's take the Hello-World programm as an example: -~~~~ +```basic !"Hello World". -~~~~ +``` The lexer would identify and transform this program into the following three tokens: - SYMBOL (!) @@ -426,4 +426,4 @@ EDIT: The crossed out features managed itself to get to the actual feature list. ## License -(C) 2019 [Raphael Pour](https://raphaelpour.de), licensed under [GPL v3](http://www.gnu.de/documents/gpl-3.0.de.html) \ No newline at end of file +(C) 2019 [Raphael Pour](https://raphaelpour.de), licensed under [GPL v3](http://www.gnu.de/documents/gpl-3.0.de.html)