We define here a programming language called C-Minus (or Cā. for short), which is a suitable language for a compiler project, which is more complex than the TINY language in that it includes functions and arrays. It is essentially a subset of C, but is missing some important pieces, hence its name. This appendix consists of five sections. In the first we list the lexical conventions of the language. Including a description of the tokens of the language. In the second, we give a BNF description of each language construct, together with an English description of the associated semantics.
In the third section, we give two sample programs in Cā. In the fourth, we describe a Tiny Machine runtme environment for Cā. The last section describes a number of programming projects using C – and TM, suitable for a compiler course.
A.1 LEXICAL CONVENTIONS OF Cā
I . The ke voiāIs (I (he lanuige ā¢ire I he fol h w i ng:
else if mt return void while
All Leywoids are iesered. tiid must he written in lowercase.
2. .Speeial symh 1s are the following:
+ ā * / < < i… = ; ( ) [ ] ( ) /* */ 3. Oilier tokens are ID and NUM. dcliiied by the Ćolk)wing regular expressions: ID – letter letter* NVM digit djgjt* l.tteraI..Iz[AI..IZ digit = OI..19 Lower- arid uppercase letters are distinct. -1. White %JCC consists of blanks. newlƬnes. and labs. White space is ignored except that it must separate IDs. Nt4s. and keywords. 5. Comments are surrounded by the usual C notations / *⢠* . * /⢠Comments caii he placed anyhcre white space can appear (that is, comments cannot he placed within likens) and may include more than one line. Comments may hot he nested. Ai SYNTAX AND SEMANTICS OF Cā A KNF grammar for C ā is as follows: I. Ā”)roƧāranl leckiruth;n-lixt 2. deCIcii(ltiĆ ;,z-list ā (kelā¬lrU1i)fl Ii.t Āæk(āl(IIĆItĆOfl kLĆilrUIU1l 3. declaration ā ar-declaiaiioi Jun1ācIarci(iwi . 4. āur-ae.ācIara (loll ā iVJ)CāpCCtJkār LV ; i iĆÆNā-Ćāiie LL. L LVULāi J 5. Ā”ype-cpecijƬer mt P void 6. fien _declaration 1vpeās)eciƬer ID ( Ā”mrwns ) Co,flj)OU,ldāVlāflI 7. params ā. partan-lis! void 8. Ā”iiĆÆiiƬtāiIst āā parain-!ivi , parain partan 9. paraiti ā tvpe-cpecifier ID f vĆ;e-speācitƬer ID [ ] 10. (Ulll,)Illitt-SIfllt āā ( lv ti1deā. lariiioiis .IaUāiHeiIt- lis f ) IL. loca!-rleclaraiions ā Iocc:lāIeclaratio,zs var-declaruiiiā,z I c,nplv 12. stuiementālisi ā viate,nentālist v(awinenf empty 13. statement epressit)n-%1mnt I cuntpoundāstnit sekācrum-sinif I iferaiüāii-s(mni m-etnrnā.st,nt 14. ĀæixfWSSù,fl_ NiDal ā expression ; ; 15. seleciion-sant ā* if ( evprcVsiāl ) slateflIelit if ( ei.precsu?n ) staienieni el se sicltcincm 16. ileralmon-sunI ā. while ( expre.csion ) xta(eāmnenl 17. return-stint ā+ return ; return ev,iressĆÆoii ; 1. e.pres.ciomi āā c,r e,tprev clon imnple-e.ĆÆ;re v 19. ar ā. ID ID [ āx,iressI.nr ] 20. .c,inpie-e.vpression czddiuāe -e.Vf)riāsVlon reloj) (u/dull e -e.precxion I tultliiftc . (āXflrLSSU)fl 21. relopāā < P < I = I == ! 22. (ulduneā(vpressu)Il ā tI(l(hIii(ā-CA/;ressu)il uddop term term 23. addopā. +1ā ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦ā¦. couldnt write the whole requirements. the assignment is complete anyway


