-
Notifications
You must be signed in to change notification settings - Fork 0
Simple Compiler
Deitel's simple compiler compiles simple language programs directly to simpletron instructions. The simple language is a subset of the basic language.Up wiki heirarchy; Across to computer.
Official specification pdf. Enliterate specification. Aspects: Compiler, Postfixer, Stack, disassembler. Test facilities, example programs. (Alternative implementations: intermediate assembler, interpreter)
SIMPLE COMPILER GRAMMER:
- <A>: <D> <X> | <D> <C> <E> | <D> <F> <E> <G> <D>
- <C>: rem | input | let | print
- <D>: { 0-9 } | <D><D>
- <E>: <L> | <D> | <L> <O> <D> | <L> <O> <E>
- <G>: goto
- <F>: if
- <L>: { a-z } | <L><L>
- <O>: + | - | * | / | % | = | > | < | ==
- <X>: end
//--fix to valid html--// SIMPLE COMPILER GRAMMER (in Wirth's EBNF):
program = { statement }; statement = line number , space , command expression; line number = number; number = digit, { digit }; digit = "0" | "1" | "2" ; (et cetera on integers) space = ? white space ?; command expression = unary expression | math expression | conditional expression; unary expression = ( unary command, ( identifier | number ) ) | ( "rem" , string ) ; unary command = "input" | "print" | "goto" ; . (actually goto can't jump to identifier value, yet) math expression = "let", identifier , "=", ( identifier | number | equation ); equation = ( parenthized equation | number | identifier ), { operator, equation } ; parenthized equation = "(", equation, ")" ; operator = "/" | "*" | "+" | "-" | "%" ; identifier = alphabetic character { alphabetic character } ; . (depends on how python interprets str.isdigit() else treated as id) alphabetic character = "a" | "A" | "b" | "B" | "c" ; (et cetera for english chars) conditional expression = "if", identifier, relation, ( identifier | number ), . . . "goto" , line number ; relation = ">" | "<" | "==" | ">=" | "<=" ; (should add != or depreciated <>)
SIMPLE COMMANDS
- rem "" - commented string
- input x - value from terminal
- let x = ( 5 + 3 ) / 2 - assign via x = expression
- print 5 - print to terminal
- goto 6 - unconditional jump
- if 5 >= n goto 3 - conditional jump, form of if [ expression ] goto [ line number ]
- end - stop execution