Post Reply 
monic part 5: writing C programs on the calculator
02-17-2021, 09:14 AM (This post was last modified: 02-17-2021 09:15 AM by F-73P.)
Post: #15
RE: monic part 5: writing C programs on the calculator
Thanks Jonathan for your helpful advice, always appreciated.

I removed "int" from the type_specifier grammar production and replaced it with "apq" (arbitrary precision rational), "apf" (arbitrary precision float - not supported on the calculator yet) and "int32_t" (maybe?).

I also added "read" and "write" from the TINY programming language, and post increment and decrement operators (just to increment/decrement variables for now, not used in assignments).

There were a few aspects of the original BNF grammar I found confusing:

1) expression_stmt -> expression ; | ;

I couldn't figure out what the ; on its own is for, so I changed the production to

expression_stmt -> expression ;

2) expression -> var = expression | simple expression

At first I thought this was a typo as I couldn't see how you can have e.g.

expression -> var = expression
Replace non-terminal expression with var = expression to obtain:
expression -> var = var = expression

e.g. a=b=100

and so I changed the production to

expression -> var = simple expression | simple expression

But then I saw your comment explaining that = is right-associative and that a=b=100 is indeed legal. So I'll go back and fix that Smile

I added some code generation instructions to the parser and now simple C programs like the factorial program below can be executed:

[Image: 50951738358_9280a3f65a.jpg]

The C language combines all the power of assembly language with all the ease-of-use of assembly language
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: monic part 5: writing C programs on the calculator - F-73P - 02-17-2021 09:14 AM



User(s) browsing this thread: 1 Guest(s)