******** A Very Simple COMPILER MANUAL ******** ******** by Louis Guzik April 29, 1995 ******** ******** Call if you have any questions ******** 341-2606 Max Chars per Line is 40 chars. MY STATIC MEMORY ---------------------------- | 0 - 9 : 10 CONSTANTS | |--------------------------| | 10 - 35 : 26 VARS | |--------------------------| | 36 : START of CODE | |--------------------------| | MEM_END : END of MEM | ---------------------------- Machine Code OpCode Operand Comment ---------------------------------------------------------------------------- 1 Load Var | Const ; Load Accumulator with address 2 Store Var ; Store from Accum. to Address 3 Read --- ; Read from Keyboard to Accum 4 Write --- ; Write Addr in Accum to CRT Screen 5 Print Str ; Print Addr of Str in Accum to CRT Screen 6 Cmp Var ; Compare Var to Accum, if Accum == Var do stmt. 7 Not Var ; Compare Var to Accum, if Accum != Var do stmt. 8 Add Var ; Add; Accum = Accum + Var 9 Sub Var ; Subtract; Accum = Accum - Var 10 Mul Var : Multiply; Accum = Accum * VAr 11 Div Var ; Divide; Accum = Accum / Var 12 Jmp Label ; Jump to a label 13 Halt --- ; End of program LANG. RULES 1 S --> ASSIGN id = A; 2 S --> COMPUTE id = A oper A; 3 S --> WRITE id | string; 4 S --> READ id; 5 S --> S* 6 S --> IF A = A S_Special; 7 A --> id | constant; 8 S_Special --> ASSIGN id = A; | WRITE id | string; | READ id; id: a single alpha character, A to Z. string: " any string of chars " or "\n". constant: intergers values between 0 and 9. operators: + add, - subtract, * multiply, / divide, = equal, ! not equal. EXAMPLE PROGRAM write "Enter x ==>"; read x; write "x = "; write x; write "\n"; if x = 0 write "Enter New x =>"; if x = 0 read x; if x ! 0 assign b = x; write "x = "; write x; write "\n"; write "b=x c=9 d=c/b d="; assign c = 9; compute d = c / b; write d; - To start the compiler, run the program "COMPILER". - DeBug mode shows in table form, what the compiler is doing. - Default source input file name is SOURCE.VSL, you may enter a new name. - The program has five (5) parts: MAIN, LEX, PARSER, GEN_CODE and EXECUTE. - MAIN is very small and calls the other parts. - LEX; works as a State Machine. Based on in class diagram from teacher. - RECURSIVE DESCENT PARSER; Based on Compiler Design textbook Ch. 4 page 102. - GEN_CODE; based on handout from teacher, generates machine code. - EXECUTE; my own design, executes machine code ******* END OF MANUAL.