#writing | enscriptions
Explore tagged Tumblr posts
divinehatred · 3 days ago
Text
LET ME IN.
a drabble of what happens at the end of chapter 3 in this au.
As the final dregs of your fear leak away from your mind, your body, your soul… you don’t understand why, but you still feel horrible. 
It’s been building, bit by bit, as you traveled through a labyrinth composed of your own emotions with the Builder himself as your sole companion. A festering, mangled feeling, like your heart is tearing itself into pieces and then tying those pieces into countless, impossibly tight knots. 
A hand presses to your chest, your face contorting in pain. Why? Why does it hurt so much? Are you having a heart attack? Are you dying?
A firm hand rests on your shoulder, startling you. “I’m proud of you, Hero. You did it.”
Right. It’s over.
Isn’t it?
Then why do you feel so..?
“You got rid of all of those little obstacles in our way.” 
Obstacles..? Emotions aren’t…
His grip on your shoulder turns into more of a vise, digging his nails into your flesh.
It hurts. “You got rid of everything keeping you from being perfect.” He emphasizes the final word in his statement in a tone of voice not unlike a snarl, endless malice dripping from it. 
A deep, horrible, burning sensation creeps out from where his fingers dig into your shoulder. You can’t move. You can’t stop shaking. You can’t breathe. You can’t. You.
“All that’s left to be done now… is to let me in.” 
Your mouth is dry. Your eyes won’t focus. 
He glances at your face, circling around to be in front of you without letting go.
“...you can at least do that, can’t you, Hero?” His tone is sickeningly sweet, a mockery of the helpful, kind man he had been pretending to be before. “Don’t tell me you’re still too weak even with those pesky emotions of yours out of the way. We can’t have that, now, can we?”
You shakily extend the fingers out of one of your hands, tuck in your thumb, close your fingers over it, and extend them again. The gesture catches his eye, making him laugh.
“Help? You want help?”
He leans in close, hissing in your ear.
“There’s nothing left to help you in here.” He pulls away, giving a condescending grin. “Just us. Just me.”
His hand leaves your shoulder. The pain remains. He moves to stand across from you, hands folded behind his back. 
“But I can see you’re not convinced yet. So let’s change that. Shall we?” His head tilts ever so slightly to the side. 
“In your current state… in order to wield the Ghostwalker… you’ve been made clean. Clear. Open.”
His smile widens. Were his eyes always so red?
“Weak.”
Each syllable feels like a nail being driven through your skull.
“Corruptible.”
His figure warps like a mirage. He’s larger than he was seconds ago. Looming.
“Defenseless.”
He’s more like a silhouette than a man. Pale, pulsating with pure hatred.
“Exposed.”
You can see his heart over his chest. It’s beating in sync with yours.
“Susceptible.”
It breaks in two. A wicked, devilish tail curls out from behind him.
“Vulnerable.”
You’re burning up. It hurts. It hurts. It hurts.
“You’re finally,” he laughs, “all,” he looks down on you, “MINE.”
The sheer weight of his hatred is nauseating. It feels like your eyes are being held open, like you’re being forced to see what your god has become. One has to wonder… is this your fault? Should you have ever gone on this journey?
Did he ever really need to be saved?
Was this a mistake?
let me in
Is the King okay? You saw him melt. Did you kill him?
Let me in
And… and Brad. Will he recover from that? Will he die?
Let Me in
Do they hate you?
Let Me In
Do you hate them?
LEt Me In
Do you hate yourself?
LET Me In
Do you hate?
LET ME In
Do you HATE?
LET ME IN
You can’t…
LET ME IN
You…
LET ME IN
It’s… it’s so… hard to…
LET ME IN
…think…
L E T  M E  I N
okay.
31 notes · View notes
convexicalcrow · 11 months ago
Text
Cairo, 1921
It's been a long season of exploration for Pix, leading expeditions into the oases west of Egypt in search of new discoveries. Much of what he'd found was rubble, or buried several feet under sand. But it had not all been for nothing! He was particularly interested in what some enscriptions call an invasion of the Sea Peoples towards the end of Dynastic Egypt which seems to have plunged the country into chaos. There's more records in Greek and Roman sources, but they're much more sedated in their descriptions, and mostly talk of Egypt falling into ruin. Concerning, but not that concerning for a civilisation that had lasted for thousands of years relatively unchanged.
The problem was, such an invasion was unlikely to leave much evidence behind, if some of the stories aare true about the scale of the slaughter. Which, of course, could have been for dramatic effect. To the victor goes the spoils. Certainly, in Bahariya Oasis, he'd uncovered some broken pots with various bits of papyrus in them, and evidence to suggest things had once burned. The temple that once stood there was barely standing anymore; it was just a few columns and stelae and statuary half-buried in the sand.
And now that the digging was over, he was now tasked with recording his finds and writing up a report for his benefactor, so he might continue exploring next season. Most of the papyri in the pots seemed to be letters to the dead, though there was no record of these sorts of papyri being buried in pots. Still, this could mean it was ground-breaking research and that was exciting! Well, as exciting as reading through such personal expressions of grief could be, Pix mused.
On their own, they were pretty standard. Children talking to their parents. Parents calling for their children. Others calling for other family members or friends, some who may or may not have been buried. They seemed to be the newest Egyptian artefacts found in terms of dates, as the hieratic they were written in was only from this late period around the time of this supposed invasion.
It was when Pix looked at them together that it kind of hit him how grief doesn't really change. These could have been written twenty years ago and no one would think them odd. And there were so many of them! Some were dated, some not, but he had uncovered over 115 of them in one necropolis, and another 97 more in a second necropolis further towards the outside of the main town in the oasis. That was a lot of grief, and might not have even been all of them. All of them written in the space of, perhaps, ten years or so, as if something calamatous did indeed befall the oasis. The letters are vague about what happened, but given the dates, Pix is sure it can only mean one thing. Some invading force reached this far-flung oasis and left a lot of people dead.
Pix finds himself returning to one letter in particular. It's written from a son to his father, with writing that's erratic and disjointed. Some of the ink has smudged, making parts of it unreadable. It's also remarkable that it contains no names. The son simply calls him, father, and himself, his beloved son. Which is rather unusual indeed. The remembrance of the name was considered vital to a good afterlife, so why would this letter remain so anonymous?
He picked it up to examine it. It was a small piece of papyrus, torn in places, and folded hastily and shoved into the pot, unlike the others that were rolled and tied with a piece of cloth. It suggested some reluctance, or haste, or perhaps he was disturbed in the process of writing to his father. Perhaps he'd never know. But some of the words just kept echoing around in his brain, as if somehow, these were people he once knew. Which seemed absurd of course! He was no ancient Egyptian! But something nagged at him. It was just-
"A letter from a son to his father. It begins, 'Praise to my father, who died for Ma'at, who rises with Ra into the sky from the belly of Nut! Praise to you, O Wesir, who gives life to the lifeless, shine on with my father, may he be justified! Please… keep him safe. I know not where you are. You would not recognise me today. My heart is. weary. How can I mourn when there is so much at stake? I have few friends in this world. Your beloved son misses you, and perhaps, one day, when my heart no longer rages, perhaps then I will find peace. Please just let me know you are okay. Let me know you made it to Wesir's court, that you are an akh in the skies, who lives forever. Every day I am met with uncertainty. I remember the last time I saw you. I remember the fear in your face. I think I knew then, that this would be the end. I was too young to understand, but somehow, I knew. I' and then it cuts off. I feel this son's sadness and confusion as if it is my own. But why though? Who are you? Who are you who haunts my dreams?" Pix said, staring at the papyrus as if it might give out more secrets.
He sat back in his chair, letting the papyrus sit on the desk. He could see- candles. A dark place with candles. Some kind of weird memorial. Nothing Egyptian, it looked nothing like that. And as soon as the image was in his head, it was gone. A fleeting imagining of something. Or a sign he was up too late again. It was, after all, after midnight, he confirned, checking his pocket watch. Perhaps sleep will cure him of his ills. Perhaps another expedition out to the oasis will yield more finds. Perhaps then he might be able to put these letters to rest, along with those who were being remembered.
13 notes · View notes
eligalilei · 1 year ago
Text
Second Chapter of My Rather Divergent 'Rendering' of the TTC
The beginning is intentionally playful, and I'll probably rework it, but I had a bit of fun writing it, and it captures a certain subset of readings of the text.
The more I work on this, the clearer it is that the text operates 'mathemematically', i.e., as a kind of equation (comprising mathemes), which is structurally precise in its underdeterminateness. This takes liberties to zero in on a meaning that I think is there, and shows sympathies with post-structuralism. I'll probably do a 'better' one that works more like a translation, but I also feel there are just so dreadfully many of those that one might as well buy the ticket and take the ride in terms of the text's demand that it be transformed if one isn't just going to leave it in Chinese or use an interlinear. If you're going to fail, might as well go all the way. I do swear it gets less liberal with further chapters.
2.
The Real types: Difference in the domain of the Symbolic is the fo(u)nt of generation, the world its text.
From zero to one, the penstroke of counterpolarity extends and divides the Imaginary domain of referent, splitting all things even beyond sight.
There: is, and there: is-no(ugh)t.
The poles are each, ex primordia, mutually pregnant, in eternatal enantiodromia.
Beings and their ideata form being. The fold of non-being sculpts from Being, ideas;
Every speaking subject knows what is indicated by ‘the good’
So, even unmarked, ‘the bad’ is coextensive.
There are many(,) but one form(s) of difference; they are united in differing, and bear all:
In time, sequences follow; in geometry, fractions compare; in values, desire pushes and pulls.
So it is that those with γνῶσις, having seen and unseen the source of the opposites,
And forged the Tripartite Stone on the anvil of forgetting and remembering,
Do act beyond particularity,
Practice with subtlety beyond words
In this is the origination of the myriad beyond enscription,
Produced with no claim,
Developed with no expectation,
The Work is accomplished, but there is no completion,
thus nothing in which to dwell
Insofar as there is no dwelling,
There need be no departure.
~~~~~~~~~~~~~~~~~~
The tripartite stone is the Philosopher's Stone, but in a Lacanian rendering, spelt as a relation between the three domains of phenomenation in Lacanian theory. The Work is, of course, the creation of the Philosopher's Stone. γνῶσις is the liberatory structure or task of insight: the Stone-as-knowledge, the Tao as philosophy which is not a philosophy and is unspeakable: empty, but inexhaustible.
0 notes
clarafordahwin · 8 months ago
Text
Okay, I dove way too deep into Gilman's politics, but I must have read some critique of her somewhere that summed this up, but I couldn't find it so instead I found her writings on the subject.
Basically she wanted a partial, temporary version of slavery. I know it went bad last time, she said, but this time it will totally benefit Black people. Each state should simply round up the underachievers and force them to work until they get the hang of it.
Tumblr media
She imagined the "enscripted" population being completely self-sufficient on food they grew. Those who weren't directly involved in growing the food would do basically every kind of labor possible, including widespread public work projects.
Tumblr media
The domestic labor section is brought up later, second-to-last paragraph, almost as an afterthought.
Tumblr media
I am now a little more understanding of the omission from the podcast. However, it's very clear that Gilman was racist and believed that Black people could not be trusted on their own. She recognizes slavery as wrong, but thinks everyone should have just figured it out by now (1908) and since they haven't they need to forced into labor for their own good.
She professes this as a temporary plan, and what I've seen of her other proposals for tackling gender inequality, she does have actual ideas of equity and shared work among men and women. BUT she is clearly okay with forcing Black women to be house servants for white women basically until they prove themselves, which is disgusting.
Podcaster mentioned Charlotte Perkins Gilman's critiques on housework without mentioning her solution was to reenslave Black people. Die.
9 notes · View notes
deathandrenegades · 5 years ago
Text
Masterlist
Updated 5.18.2020
1k writing challenge
Supernatural
Tumblr media
Sunk (one shot) - here
Dean Visits You at Work (Dean x Reader imagine) - here
Down for Whatever (Dean x Reader drabble) - here
Staged (Jensen x Reader drabble) - here
Enscripted (Dean x Reader series) - Part 1 Part 2 Part 3 Part 4 Part 5 Part 6 Part 7 Part 8
Royalty Burns (Dean x Reader series) *unfinished* - Part 1 Part 2 Part 3 Part 4 Part 5
Middle of the night (Dean x Reader Imagine NSFW) - here
The Backseat (Dean x Reader x Sam NSFW) - here
Tension (Dean x Reader series NSFW) - Part 1 Part 2
5 Years Later (Dean x Reader NSFW) - here
Marvel
Tumblr media
Awkward (one shot) - here
Unable to Sleep (Bucky x Reader Imagine) - here 
Middle of the night (Bucky x Reader Imagine) - here
Determined (Bucky x Reader drabble) - here
Bones (Reaper!Bucky x reader one shot) - here
Bloodshot (Bucky x Reader one shot) - here
Bruised (Bucky x Reader one shot) - here
Operation Foxtrot (Bucky x Reader series) - Part 1 Part 2 Part 3 Part 4 Part 5 Part 6 Part 7
Halloween Night (Drabble NSFW) - here
Just the Two of Us (Steve x Reader NSFW) - here
The L Word (Bucky x Reader series NSFW) - Part 1 Part 2 Part 3 Part 4 Part 5
Personal (Bucky x Reader NSFW) - here
Later (Bucky x Reader NSFW) - here
More than you Bargained For (Succubus!Bucky x Reader NSFW) - here
64 notes · View notes
peitalo · 4 years ago
Note
Can you tell us absolutely everything about Walcott?
YES !! ok i will try not to make this too long... his full name is walcott attenborough & he’s a wood elf wizard! 20 years ago he & his group of school friends became liches on accident while trying to perform a luck enchantment spell to help them pass their 1st level spell exams and in doing so lost all of their memories when the spell succeeded (here’s some pages depicting the event from his prop journal that i made:
Tumblr media Tumblr media
[page 1 transcript: “07/29. the exam is tomorrow, professor sawyer pushed it back a day. we rummaged through the deep parts of the library, and found a spell perfect for our situation! it will grant us wisdom and extensive power and knowledge, though only when one’s wearing the magic item you must enchant for good luck. if all goes well, we’ll all pass and enter actual magic training! the spell is a bit hard to read, and looks super old, so chances are professor sawyer won’t recognize it. it needs a full moon in order to work, and we have to adorn our items with enscriptions. i’m using the pocketwatch given to me by my parents, with our family name on it. i never knew them. i don’t think i ever will, either. we also have to cut our hands and make soup? Mitch called us the “soup squad.” we should get matching robes. i hope the soup tastes good, at least. i’d hate to risk this for just some foul broth. if it doesn’t work, assume we died.” / page 2 transcript: “it is raining. i do enjoy the rain. who am i? im cold. its cold. i dont know where i am. who i am. why i am. there are others. this (the journal) was in the bag she found me with. i think its mine. walcott. walcott. walcott. is that me? it must be. it has to be. i have to be. it’s still raining. i am outside. i enjoy the rain. the other writing in this book is prettier. is it mine? is this mine? im not breathing. she taught me how to breathe. i just forgot again. she’s not mad. she smiles”) he & the rest of the soup squad were taken in by a lich named sybia (the one he’s referring to as “she” in the second entry) who lived deep in the woods a town or so over from the school and she became like a mother to them, teaching them spells and helping them adjust. on one of her errand runs though she was caught by lich hunters and her physical form was destroyed, and walcott took on the quest of leaving and searching for the item her soul is bound to which is LONG lost bc shes OLD to make sure it’s in a safe place for her to reform. he didn’t know he was a lich until a session or two ago when he hit 0 hp and got knocked back onto his own grave and shot out of his body auduajficjwjfb but he got better! also he has a familiar named clive who’s a great horned owl she is very cool. his favorite soup is minestrone and he loves poetry and i love him very much
22 notes · View notes
ksmutty · 7 years ago
Text
They Called It Fate(Jae/Reader)
Tumblr media
Author: Admin Sunflower
Genre: Soulmate!au
Warnings: Stupid Humor
Word Count: 689
A/N: Honestly, what is this? I’m so sorry
Summary: Cliche soulmate!au where your soulmates first words your soulmate says to you are written on your wrist.
Your mother warned you that the eve of your 21st birthday you would find a small quote enscripted in your skin. She told you how they would be the first words your soulmate spoke to you.
Your father warned you not to show it to anyone because boys tend to think with the wrong head, and would try anything to swindle their way into such a pretty girls pants.
Your sister told you how wonderful it is hearing those words go from ink on your skin to the mouth of your soulmate. The way the fireworks erupt and you heart melts into the hands of your lover.
Your brain told you this all had to be a big fat fucking joke.
You tugged your sleeve down, covering your wrist and the words written across them. You took your father’s advice. The less people who knew about them the less chance of some loser spewing them just to get into your pants. Besides, the chances that anybody were actually going to speak the words on your wrist were highly unlikely.
You stepped out of the Science Department front doors and began your short walk back to the dorms. You were glad it was finally a warm day and decided to take a little shortcut, but the moment you stepped onto the crosswalk brakes squealed and a small beat up Honda Civic was just inches away from ending you. You screamed, smacked the hood of his car, and held up both middle fingers to him. All he did was smile apologetically and wave you across the road.
“What a douchebag” you thought to yourself. “Literally almost kills me and then he just smiles. What the fuck?”
You tossed your bag on the floor and face planted into your bed. The moment sleep threatened to rip you away from reality your roommate swung open the door and plopped down on your bed.
“Are you getting ready or what?”
“For what?” You groaned.
Raeh rolled her eyes, “that little mixer or whatever. The boys from Kappa Sig invited us over, remember?”
You let out a dramatic wail and pulled your pillow over your head. “No.” You mumbled.
“YES!” She ripped tour pillow away from your face an chucked it across the room. “Please! You know Wonpil will be there. You also know I have NO game so you have to wingman!!”
“Goddamn you, Raeh.”
“Atta girl!” She smirked. “Lets go!”
It wasn’t until you were in the Kappa Sigma house with a few mixed drinks in your system that you remembered the boy who had nearly hit you. Raeh had snuck off somewhere with Wonpil and left you making small talk with Dowoon when you spotted him.
“Ugh!” You scoffed. “What a prick! Do you know that guy?”
He laughed as you motioned towards him. “Jae? Everyone knows Jae.”
You rolled your eyes. “He’s an arrogant prick if you ask me.
You recalled the events of him nearly hitting you and Dowoon tried his best to assure you it was probably an accident, and Jae has a lot on his mind these days and meant no harm. His words did nothing to calm the fire fueling in the pit of your chest and finally you handed him your drink and shoved your way through people to approach Jae.
You didn’t even stop for a breath before waving a finger in his face and shouting. “YOU NEARLY KILLED ME, JACK ASS!”
Jae erupted into laughter and held his arm in the air. You tried to make out the writing across his wrist at an odd angle but the moment he spoke you knew exactly what was happening.
“Oh shit, waddup girl?!”
Your heart sunk to your chest in realization. You yanked your sleeve up your arm to reveal the words printed across your wrist in old fashioned comic sans. Oh Shit Waddup Girl. This was actually happening. You had finally put a voice to the words across your wrist. A frat boy. A memester. A complete idiot and a SHIT driver.
Park Jaehyung.
Mister “oh shit, waddup girl?”
Your soulmate.
195 notes · View notes
azteriot · 2 years ago
Text
I lived, bitc-
If you know why I’ve returned here, you know.
It’s been years and this blog has been catching dusty since forever as I don’t actively use or navigate through this website at all. Aside from initially just using it for contacting someone, I was thinking to turn this into some kind of archives.
......But again when I actually think through about it, this site is hardly suitable for what I have in my mind.
For example, to celebrate my return, I’d like to publish one of my OC fic right here BUT THE FUCKING TEXT AND FONT FORMATION IS SO LIMITED OTL I specifically need the “furigana”-like function to work, so if only I could resize text and space, I will be able to deliver the long-awaiting scenario that has been stuck in my mind for years into its closer glorious form, in words.
Speaking about my OCs, I have been trying to wrap my head around ungendered words and whatnot in English and Japanese to express their nature more accurately as they’re technically not a human, they just absorbed some of civilizations and twisted it into their own understanding of self.
For no one’s surprised, I obviously have the most difficulty with English. Especially when I want to apply some sort of “keigo” in Japanese into it.
Also for the banter between Kather and Denas, no, Kather didn’t and will never disrespect Denas’ definition of “being a man” and his masculinely splendor just because he thinks the other being’s way of expressing himself both inwardly and outwardly isn’t quite a cut for the majority of “manliness“ he has observed from many civilizations and stars, it’s just Kather’s little nitpicking of all of the residents of Afterworld are always constantly aware that they’re not truly human and doesn’t belong to such concept. in shortly, denas’ presence pissed him so he pissed back
I’m still considering and planning how to establish the whole Afterworld: Dasein Constella story in chronological order, I have always been dreaming about writing something in Light-novel or visual novel format all by myself with my own illustration, just adding bilingual version for double fun and trilingual dialogues (yes I’m still a noob who can’t write the scenery expression in Japanese, ダメだね) ...........or maybe even as in interactive environment in rpg game-like manner.
For now, it will be randomly in form of unconnected chapters of writing and standalone illustrations which I dubbed it as “disjointed enscripts”
1 note · View note
longleague · 2 years ago
Text
Phraseexpress not play nice with dragon naturally
Tumblr media
#Phraseexpress not play nice with dragon naturally how to#
#Phraseexpress not play nice with dragon naturally how to#
PHRASEEXPRESS AUTOTEXT NOT WORKING HOW TO Go to EvernoteĬopy the following script to Phrase contentĪssign a Hotkey, e.g. But Don’t use Autotext method in text editors, the text selected will be replaced as you type in the Autotext. PhraseExpress Macro for finding notes with Evernote CLI on Windows Demonstrationįor example, I am writing a Chinese article about PhD. I highlight the text in that I want to search, and then press the Hotkey for my script. Win + Shift + E) to call Evernote CLI for searching notes Search results on the Evernote Desktop app activated by the Evernote CLIĬontrol Evernote from the Windows command line - Evernote DevelopersĬommand line arguments in Evernote-ENScript - Windows Desktop Help - Evernote User Forumĭoes it help? I hope you can leave your comments below.PhraseExpress v10 Documentation Software installation Using PhraseExpress on USB flash drives First Steps with PhraseExpress The Evernote Desktop will launch in a second with the results of your search queue. Macro functions Overview How do I… …add time/date stamp to a phrase? …link a phrase with another phrase? …add manual text input to a phrase? …create an input form? …create a predefined email? How do I… …store a new phrase? …insert a phrase into a document? …edit a phrase? …find a certain phrase? …delete an unwanted phrase?Īdditional functions The phrase selection menu QuickSearch Floating desktop menus Hotkeys Autotext Restrict phrases to certain programs Restrict phrases to individual users Secure PhraseExpress against operating errors Text Prediction feature Clipboard Cache Last used phrases Spelling Correction Perform Calculations As-You-Type SmartSearch Using PhraseExpress in a Team PHRASEEXPRESS AUTOTEXT NOT WORKING SOFTWARE PHRASEEXPRESS AUTOTEXT NOT WORKING MANUAL PHRASEEXPRESS AUTOTEXT NOT WORKING LICENSE.PHRASEEXPRESS AUTOTEXT NOT WORKING SOFTWARE.PHRASEEXPRESS AUTOTEXT NOT WORKING MANUAL.PHRASEEXPRESS AUTOTEXT NOT WORKING INSTALL.PHRASEEXPRESS AUTOTEXT NOT WORKING HOW TO.
Tumblr media
0 notes
agent-thorn · 6 years ago
Text
Contracted Out
Carter swung his legs mindlessly as he sat perched on the ledge of brick wall. he supposed it was once a building, a gas station by the general cubism of it, but it has been long abandoned by society, and long inhabited by the wild. No matter the state of it, this was where his mission was starting so this is where he would wait *semi* patiently for his contact to arrive. The society had accepted a contract from an individual who had been recently exiled from the unseelie court: he was a paranoid fellow and didn’t trust anybody to not try and pick him off during his move. It was a simple escort mission, and as Parker still wasn’t signed off on fae work, it fell to Kieran. Who promptly said ‘fuck no’. And so it was that Carter received the mission. Kieran threw up a stink about that too, saying that Carter was too ‘irresponsibly green’ for his own mission, but when presented with the option to join him, declined and kept quiet. ‘No skin off my back,’ Carter pouted to himself as he recalled the way the senior agent gave him a half-hearted goodbye and sent him on his way. ‘It’s not like I wanted to get to know the only other fae I’ve encountered. Who’d want to talk to that dusty old grump who smells exactly like I think a father should anyways.’ He was pulled from his thoughts, which definitely wasn’t sulking, when some struggled clumsily through the bushes. “Hey!” He started brightly, determined to make this mission a good one, and the best way to do that was with a good first impression. “You’re the guy with the security contract right?” The small portly man, who was currently bent over and catching his breath, snapped his gaze up to Carter and gave him a scrutinizing look. “I beg your pardon, but you will address me as ‘Sir Theophilius’. If I had realized that Roanoke would’ve sent someone so curt, and make me hike out to this blasted location, I would’ve paid extra for better service!” The man looked like if the mole from the old ‘Thumbelina’ movie became a really fat human and decided to dress like a banker in 1901. So Carter decided that if he wasn’t going to make a new friend, he was going to have fun. “Oh Theo no, don’t be so down. See, when you hire Roanoke you hire the best.” He hopped effortlessly down from the wall and strode over to the man, tossing an arm around his shoulders. “Now if you’ll just step this way for a moment, and I will show you the true majesty of our capabilities.” He boasted, practically dragging the smaller man alongside him until he felt him go rigid and yelp with pain. “See? The reason we needed to meet here is that this is one of our resources; a rune circle that dispels any tracking device, spell, sigil, or connection that has been placed upon your person. Now don’t you worry Theo, now that we’ve taken care of your little problem that you weren’t even aware of, we can proceed with confidence to where you’ll be relocated.” He kept up the chatter for hours as they hiked, Showmanship and bravado gradually fading into his usual idle nonsense. Only stopping when he heard the tell-tale ‘click’ of a weapon in the distance. “Now Theo, I’m going to ask you to stand right here and-“ Carter pulled an egg from his pocket, the latest shielding spell from the ‘weapons development’ department, and cracked it over the other man’s head- freezing him in place instantly. “There we go, I’m going to take care of these friends you’ve seem to brought along, and then we’re going to have a talk.” He politely asked the surrounding environment and flora to hide his movements as best as they could, and snuck his way to where the noise came from. Sure enough, he crept up behind four masked individuals, all wielding glass weaponry enscripted with runes, and slowly creeping their way up to Theo, where he waited still and unmoving, a perfect target. A perfect distraction. “So I’m assuming y’all are here to answer my Craigslist add?” He started, getting their attention and throwing them off. “Well I did ask for four burly men to do unspeakable things to me, but y’all are a few days early.” “Speak villain,” one of them commanded, pointing his weapon at Carter but hesitating. “You sure? Usually people want me to stop speaking. Let’s change it up- why don’t you all tell me what the fuck you want.” The one who spoke, the smallest of the four, stood proudly and removed his mask. “We are the personal guard of the glorious Adwynnthe family, favored among the Unseelie court, and we are here to bring that sneaking creature to justice.” “So while that sounds super fun and hot and everything, I was under the assumption that he has already faced your courts and was exiled.” “That underhanded cur purloined the grand master’s emblem. Had the courts been privy to this information prior to final ruling, then surely his sentencing would have been exiling his miserable head from his body.” “Cool cool cool, right on. Only, and not to get into the details because I don’t really care, but I can’t let you do that.” Thorns, sharp and rigid, grew and pricked through his forearms and knuckles in preparation for a fight. They began to charge at him, only trip and get tangled in the roots and vines that had settled around their feet. One finally got free enough to try and crawl free, only to get kicked swiftly in the jaw. Carter reached into his pocket and threw a modified smoke bomb at the two coming toward him, releasing a cloud of powdered iron into the air, effectively blinding and choking everyone in the vicinity, him included.
Carter ignored the painful, acidic burn that numbed his hand and choked his airways, leaving him reeling and gasping for air as he stood in a defensive fighting stance that he could barely remember from training. Only no fight came, just some heavy thumping he couldn’t discern the location of.
“Y’ damn fool!” A familiar voice cut through the iron laden fog. Kieran strode towards him, holding a mask tightly over his face. “Didn’t even bring a fuckin’ gas mask. Your lucky I was around to take care of those goons and make sure you didn’t get yourself killed.”
“Aww Papa you do care.” Carter joked through his bowled over coughing fits. Looking over to where he threw the smoke bomb showed that Kieran had indeed took care of the ‘problem’. The four men who had been following them were now neatly restrained and unconscious. Maybe all that combat training was good for something.
“C’mon boy, we’ve still got work to do.” He clapped Carter on the shoulder and together they made their way over to where Theophilius waited, motionless and quiet. Carter rummaged through his pockets, and quickly discovered a heavy necklace, ornate and practically glowing with some sort of fae energy Carter wasn’t familiar with.
“Here you go boss man,” He chimed, tossing the pendant to Kieran, who snatched it out the air, and dispelled the enchantment keeping him in place.
“We’ll get this back to the rightful owner in a bit; I’ll take care of the guards, you get to clean up this mess. Have fun.” As Kieran sauntered away, Carter turned and smiled widely at the smaller man, slowly coming back to his surroundings.
“Theo,” He sang out. “You weren’t being honest with us.”
“Wh-what? I demand to know, where am I? What happened?”
“Relax Theo. You’re safe, but I am pissed. You put, in writing,” He pulled out a copy of the contract to waive in front in front the of man who was now starting to cower. “That we were to escort and protect, you, with ‘full and open intentions’, but I have just discovered that your real intentions were for us to escort and protect the ‘Adwynnthe family emblem’. So as far as I’m concerned, our contract is null and void. Now those gentlemen over there,” He pointed to the four guards. “Do not know as of yet, that we have returned the ‘Adwynnthe family emblem’, but don’t worry, I’ll leave a note. And since I’m so nice, I won’t wake them up right away either. Now, Sir Theophilius, if you wouldn’t mind being so kind as to getting the fuck out of my sight.”
Once the portly man scurried away, adequately frightened, Carter placed a crayon-written note in the pocket of one of the guards as Kieran released their bindings. It was about ten seconds before they fully woke up and were pointed in the right direction.
7 notes · View notes
kittykatanimelove23 · 7 years ago
Note
#94 sunset x shadow? :0
“We can’t go in there…”
Trigger Warning(s): Death Mention
Well this turned out a little angsty whoops
It was a quiet afternoon in the great castle of Equestria, which was pretty rare since a lot of people lived there. Rarity was at an auction sampling fashion with Fluttershy, Pinkie Pie was having a tea party with Amy, Cream, and Cheese, Twilight was having lunch with Silver, Rainbow was playing soccer with Sonic, Isis was hanging with Pacifica and Celestia was discussing kingdom matters with Sally. 
Yep, the castle was quiet.
Until the door to a hallway opened, revealing Sunset Shimmer, Rouge, and Shadow.
“And this is the main hallway, where it leads to all of the bedrooms.” Sunset had stated. Today she was giving her friends a tour of the castle since they would get lost in it every time they visited. “How can you tell which room is who’s?” Rouge asked, her voice dripping with boredom. “Simple.” She walked over to a bright purple door with intricate lines and had three diamonds in the middle “The doors are designed with our cutie marks! For example” She pointed at the door “This is Rarity’s room” Rouge hummed while Shadow nodded slowly at the small fact.
After showing off bedrooms, they reached the last destination, the relic room. After the guards let them in, while suspiciously eyeing Rouge, Sunset showed them the first artifact. It was a blade that had a golden handle with enscripted writing on it. “This is the blade my mother had received as a welcoming gift when she visited Saddle Arabia for the first time.” She explained while Shadow and Rouge were eyeing the old weapon with a mild interest. 
6 minutes looking at relics later..
“… and that’s how my aunt Luna used that axe to break apart a warship in two swings.” Sunset finished. “Remind me never to tick her off” The bat replied with a slight nervous tone. Sunset Shimmer and Rouge started walking towards the door “Well, that’s it for this room, where do you want me to show you next?” Before Rouge could answer, Shadow intervened “Wait, what about that door?” The two turned around to see Shadow standing in front of an old door that was slightly open from the far right corner in the room. Sunset’s face shifted to a very worried expression, she quickly walked over and shut it “We can’t go in there…” She had spoke, her voice clear with discomfort. Sunset speed-walked out of the room leaving Shadow and Rouge to look at each other with slight confusion and worry.
Rouge had left later that day for some “important business” leaving Shadow and Sunset Shimmer alone. They were both in the library looking at vast collections of books. Shadow glanced at Sunset, who was searching for a spell book, he hesitated a moment before speaking “So..” he began “What happened back in the relic room?” He heard Sunset stop moving, he was quick to apologize “ I’m sorry I shouldn’t have-” “That room contains his crown” Shadow’s eye’s widened a bit, Sunset then turned around to look at him with a small sad smile, “That room contains the king’s crown, barely anyone’s been there since….” She stopped for a brief second “..since we came here.” She stopped talking. Shadow didn’t need to hear anything else to know who that crown belonged to before the Equestrians came to Mobius. It was her father, Galactus Centauri, who sacrificed himself for her and Pinkie Pie. He knew how close she was to him and he knows that she’s still recovering from his death. He put his hand on her shoulder, “I shouldn’t have mentioned about that door earlier, I’m sorry.” “No.” Sunset raised her hand before he could say anything further “I shouldn’t have acted like that back there, you were just curious.” She smiled faintly and bent down to kiss his cheek. Before Shadow could say anything else…    
 “HEY SUNSET!!” Pinkie Pie shouted abruptly as she burst through the room.
Shadow inwardly cringed by the sudden loudness of her voice. “Rarity and Fluttershy came back with gifts from the auction! You should totally see what she has for you! She even has a gift for Shadow! Come on!” She giggled and skipped off. “Well” Sunset began “You want to go check out and see what kind of overglittery suit she bought you?” She asked him “Do I have much of a choice? Knowing Rarity she’ll probably never let me leave until I try it on.” He sighed and then took Sunset’s hand walking her out of the library.
5 notes · View notes
divinehatred · 6 days ago
Text
CASUAL ASK/RP BLOG FOR THE DIVINE HATRED AU OF BLOCK TALES
run by @rnainframe | main muse: "the builder"
character ref [placeholder - more polished art will come eventually]
while i am an adult, i would prefer for this blog to remain sfw.
magic anons are allowed!
while there's other characters in this au, builder is the main focus!
this blog is run by someone who is disabled, primarily chronically fatigued. if i don't answer or reply to you, it doesn't necessarily mean i reject what you have to say - it's probably because i don't have the energy.
this post also doubles as a place to store all the various tags this blog will use!
co-ran by @deathofamemer
15 notes · View notes
oldmacnewlife · 4 years ago
Text
Viewing CSV Files on the UNIX Command Line
In a previous post I covered basic UNIX command line printing from the Mac OS X Terminal app. I used typing and printting a letter as an example, so, in this post, we're going to work on building an address book that can also be accessed from the Terminal. Since it's an address book, we're going to want it to contain a listing of the names and addresses of the people we like to write to, displayed in a neat, columnar format. We COULD create a simple text file, with the columns manually created with the spacebar and tab keys, but that actually involves a fair amount of work getting everything lined up just so. There is another way.
CSV (Coma Separated Values) files are specially formatted text files for storing data. Originally developed to allow data sharing between different spreadsheet programs their format is dead simple: a text description of a data table with commas separating each column. Each line of text describes one row. The first row in a CSV file generally contains field or column names. 
Tumblr media
Here I’ve used the VIM text editor to create a simple address book. You can see the first line contains the column titles: Salutation, Name, Street, City and Zip. Each remaining line represents one row in the table, with each row containing one record or entry in the address book. If that sounds a bit like a spreadsheet or database to you, you’re not wrong. Both spreadsheet and database software can import CSV files.
Tumblr media
Using the UNIX command cat to display the contents of the file kind of works, except this CSV file contains more lines than the display can show, so the first few rows end up getting cut off. To fix this, we can use the pipe symbol to redirect the output to another UNIX command, less. So entering:
cat Fake_Address_Book.csv | less
Tumblr media
Output is displayed to the screen as before - except now it “pauses” when it reaches the limits of what the screen can show at one time. You can use the up and down arrow keys on the keyboard to scroll through the file contents.When you’re done viewing the file, press ‘q’ on your keyboard to quit.
This is a definite improvent, But the contents of our “table” are still are scrunched together. There has to be a way make it look more like a table. Well, of course there is.
The UNIX column command displays the contents of a specified file in, well, columns. So this time we’ll be redirecting the output of cat to the column and then the less commands to provide some formatting prior to display:
cat Fake_Address_Book.csv | column -t -s “,”  | less
There’s two options being set in column: “-t” and “-s”. “-t” instructs column to format the output as a table. “-s” tells column what character is being used to separate the columns in the table, in this case, a comma. The options are followed by the name of the file we want column to display. As before, the pipe symbol redirects the output to another program, less, to  “pause” the output to allow us to scroll through the contents of the file, since it still contains too many lines for the terminal to display at one time. This command results in...
Tumblr media
Nice! Just like before, you can use the up and down arrow keys to scroll through the file contents and press ‘q’ when you’re finished.
There seems to be a glitch with this in many Unixes, including Mac OS X, where if there is an empty column, the column to the right is shifted over to to the left to fill it. This is probably not the behavior you’re looking for.
Tumblr media
I’ve used VIM to empty fields on a couple of records.
Tumblr media
Running the commands again, we can see that in rows with empty fields, columns to the right of the empty fields were shifted one column to the left. To work around this, we’re going use the sed command to add some whitespace before each comma. A field containing space is technically not empty. We’ll be using the pipe command once again to redirect the output.  Here’s what the final commands look like:
cat Fake_Address_Book.csv | sed ‘s/,/ ,/g’ | column -t -s “,” | less
This gives the output:
Tumblr media
Thank you, sed! It’s worth noting that sed just modifies the output to the display, not the actual file itself. If you wanted to print out a hard copy of the file, you could use the pipe command to redirect to either lpr or enscript, depending on your preferences. I prefer enscript, so...
cat Fake_Address_Book.csv | sed ‘s/,/ ,/g’ | column -t -s “,” | enscript -r --no-header --margins=“36:36:36:36 --font=Courier11
which gave me...
Tumblr media
Also nice! And done. For now...
0 notes
davidhaltinner · 7 years ago
Text
Self compiling C compiler, written in C
// symboltable.h
#ifndef _SYMBOLTABLE_GUARD #define _SYMBOLTABLE_GUARD
using namespace std;
#include <string> #include "symbol.h" #include <list> #include <iostream>
// David Haltinner ******************************************************* // The SymbolTable class implements a symbol table, which is a set of // pointers to Symbols. // David Haltinner ******************************************************* // // public member functions // ======================= // // constructor/destructor // ====================== // not needed -- the defaults work fine // // mutators/modifiers // ================== // void Insert(SymbolPtr sym) -- add sym to the table (error if there is //                            -- already a symbol with the same name) // // other operations // ================ // SymbolPtr Lookup(string k)   -- if there is a symbol with the given name, //                              -- return a pointer to it; //                              -- otherwise, return NULL // Print(ostream & out) //     ��                        -- print the names of all the symbols, one //                              -- per line, to the given output stream
class SymbolTable {  public:    // mutator/modifier member functions
   void Insert(SymbolPtr sym);
   // other operations
   SymbolPtr Lookup(string k);    void Print(ostream &out);
 private:    static const int TABLESIZE = 17;    list<SymbolPtr> bucket[TABLESIZE];    int Hash(string & S); };
#endif # Makefile for p4
CC     = g++ CFLAGS = -Wall -g
LEX    = flex LEXLIB = -lfl YACC   = bison -yd
OBJ    = main.o message.o symbol.o symboltable.o symlist.o ast.o \         y.tab.o lex.yy.o  namecheck.o typecheck.o unparse.o int2str.o\ codegen.o emit.o
p5: $(OBJ) $(CC)  $(OBJ)  -o p5    $(LEXLIB) wosym: main.o message.o symbol.o symboltable.o symlist.obj ast.o y.tab.o lex.yy.o namecheck.o typecheck.o unparse.o int2str.o $(CC) main.o message.o symbol.o symboltable.o symlist.obj ast.o y.tab.o lex.yy.o namecheck.o typecheck.o unparse.o int2str.o -o p4 $(LEXLIB)
main.o: main.cc ast.h symbol.h scanner.h $(CC) -c $(CFLAGS)   main.cc message.o: message.cc message.h $(CC) -c $(CFLAGS)   message.cc symbol.o: symbol.cc symbol.h $(CC) -c $(CFLAGS)   symbol.cc symboltable.o: symboltable.cc symbol.h symboltable.h $(CC) -c $(CFLAGS)   symboltable.cc symlist.o: symlist.cc symlist.h $(CC) -c $(CFLAGS)   symlist.cc ast.o: ast.cc ast.h symbol.h $(CC) -c $(CFLAGS)   ast.cc unparse.o: unparse.cc ast.h symbol.h y.tab.h $(CC) -c $(CFLAGS)   unparse.cc
int2str.o: int2str.cc int2str.h $(CC) -c $(CFLAGS) int2str.cc
namecheck.o: namecheck.cc ast.h symbol.h symboltable.h message.h \             symlist.h $(CC) -c $(CFLAGS)   namecheck.cc typecheck.o: typecheck.cc ast.h symbol.h symboltable.h message.h \             symlist.h $(CC) -c $(CFLAGS)   typecheck.cc
codegen.o: codegen.cc ast.h emit.h scanner.h y.tab.h message.h symlist.h\   symboltable.h int2str.h $(CC) -c $(CFLAGS)   codegen.cc
emit.o: emit.cc emit.h ast.h message.h int2str.h $(CC) -c $(CFLAGS)   emit.cc
y.tab.o: y.tab.c $(CC) -c $(CFLAGS)   y.tab.c y.tab.h: y.tab.c touch             y.tab.h y.tab.c: grammar.yacc ast.h symbol.h scanner.h $(YACC)         grammar.yacc
lex.yy.o: lex.yy.c ast.h symbol.h scanner.h message.h int2str.h y.tab.h $(CC) -c $(CFLAGS)   lex.yy.c  -DYY_NO_UNPUT lex.yy.c: tokens.lex y.tab.h $(LEX)              tokens.lex
listings: enscript -2r -P halseyLinux \ main.cc Makefile codegen.cc
test: Go clean: /bin/rm -f *.o lex.yy.c y.tab.* erase: /bin/rm -f *.o *.s lex.yy.c y.tab.*  p5 preClean: /bin/rm -f *.s // symlist.h
#ifndef SYMLIST_H_ #define SYMLIST_H_
#include <list> #include <string>
#include "symboltable.h" using namespace std;
typedef SymbolTable *PSymbolTable;
class SymTableList {
public: SymTableList(); ~SymTableList();
void         push( PSymbolTable v );  // AddToFront PSymbolTable pop();                   // RemoveFromFront PSymbolTable top();                   // current scope
SymbolPtr    lookUp( string id );     // is id in any scope?
private: list<PSymbolTable> * symTableList;    // STL list };
#endif // message.cc
#include <iostream> #include <iomanip> #include "message.h"
// GLOBAL VARIABLE bool errorFlag = false;
// David Haltinner ******************************************************* // Error //    write the given error message, preceded by <line>:<col> to cerr //    also set the global errorFlag to true // David Haltinner ******************************************************* void Error(int line, int col, string msg) {  cerr << "ERROR line " << setw(2) << line       << " column " << setw(2) << col << ": " << msg << endl;  errorFlag = true; }
// David Haltinner ******************************************************* // Warn //    write the given warning message, preceded by <line>:<col> to cerr // David Haltinner ******************************************************* void Warn(int line, int col, string msg) {  cerr << "WARNING line " << setw(2) << line       << " column " << setw(2) << col << ": " << msg << endl; }
// David Haltinner ******************************************************* // InternalError //   write the given error message to cerr and quit // David Haltinner ******************************************************* void InternalError(string msg) {  cerr << endl << "INTERNAL COMPILER ERROR: " << msg << endl<<endl;  exit(1); } // this is just a test of string labels for print
int main(){ print("This is a test of the labeling"); print("\n"); print("This is a test of the labeling"); print("\n"); print("This is a test of the labeling"); print("\n"); print("This is a test of the labeling"); print("\n"); print("I hope this works"); print("\n"); print("This is a test of the labeling"); print("\n"); print("I hope this works"); print("\n"); print("This is a test of the labeling"); print("\n"); print("I hope this works"); print("\n"); print("This is a"); print("\n"); print("This is a test of the labeling"); print("\n"); } // test of various types of globals
int x; bool y; int w[2]; bool z[2];
int t(){ int x; bool z; z = true && y; // 1st true 2nd false x = 99; // 1st the then is executed // 2nd the else is executed if(z){ print("z is ", z, " x is ", x); print("\n"); x = 3; } else{ print("z failed", "\n"); x = 1; }
return x; }
int main(){ y = 3 == 3 && 4 < 5 && 7 != 9; // true x = 7; print("X before ", x, "\n"); w[0] = t(); print("X after ", x, "\n"); y = false; z[0] = false; z[1] = false; w[1] = t(); // this executes if(w[0] != w[1]){ print("Just as I thought", "\n"); print("W[0] is ", w[0], " and W[1] is ", w[1], "\n"); } return 1; } /* grammar.yacc */
%{ // stuff here is copied directly into y.tab.c above (outside of) yyparse()
#include "ast.h" #include "scanner.h"
// bison needs these two forward declarations (but yacc doesn't) extern int yylex(); int yyerror( char *msg);
// just need "one" null node // don't need to create a "new" null node every time we need one static NullNode * NULLnode = new NullNode();
%}
/*   define the data type of the value stack (YYSTYPE)   the "value" associated with some tokens  will be data type TokenType   the "value" associated with nonterminals will be data type ...Node * */
%union{ TokenType  t;
ProgramNode * Program ; GlobalListNode * GlobalList ; FunctionListNode * FunctionList ; FunctionDeclNode * FunctionDecl ; TypeNode * Type ; ParametersNode * Parameters ; ParamListNode * ParamList ; ParamNode * Param ; VarListNode * VarList ; DeclNode * Decl ; ArgListNode * ArgList ; StmtListNode * StmtList ; StmtNode * Stmt ; PrintListNode * PrintList ; PrintItemNode * PrintItem ; CoutListNode * CoutList      ; CoutItemNode * CoutItem      ; OrNode * Or ; AndNode * And ; RelOpNode * RelOp ; ArithOpNode * ArithOp ; ExpressionNode * Expression ; TargetNode * Target ; IdentifierNode * Identifier ; StringLiteralNode * StringLiteral ;      }
/*   since the value stack is a struct(union), it seems we need to use the   notation $2.t or $$.a;  the actual ugly notation is  $<t>2  or  $<a>$   the %type directive lets us use $2 or $$  because it tells yacc/bison   which member of the struct(union) should be referenced */
     /*** do not change these token and type specifications! ***/ /* David Haltinner ====================================================== */ %token     SEMICOLON RPAREN RBRACE RBRACKET %token <t> ID INTLITERAL STRINGLITERAL ASSIGN PRINT INT VOID TRUE FALSE %token <t> LPAREN LBRACE LBRACKET PLUS MINUS TIMES SLASH BOOL AND OR %token <t> IF ELSE WHILE RETURN LT GT LEQ GEQ EQ NEQ COMMA %token <t> COUT AARROW
%type <Program> program %type <GlobalList> globalList %type <FunctionList> functionList %type <FunctionDecl> functionDecl %type <Type> type %type <Decl> variableDecl %type <Parameters> parameters %type <ParamList> paramList %type <Param> param %type <VarList> varList %type <StmtList> stmtList %type <ArgList> argList %type <Stmt> stmt %type <PrintList> printList %type <PrintItem> printItem %type <CoutList> coutList %type <PrintItem>       coutItem
%type <Expression> expression %type <Expression> term %type <Expression> factor %type <Expression> primary %type <Expression> unit %type <Expression> nameVar %type <Expression> arrayVar %type <Expression> intLiteral
%type <Expression>      ORexpression %type <Expression>      ANDexpression %type <Expression>      ORlist %type <Expression>      ANDlist
%type <Target> target %type <Identifier> identifier %type <StringLiteral> stringLiteral /* David Haltinner ====================================================== */
%nonassoc THEN %nonassoc ELSE
%start program
%%
program : globalList  functionList      { astRoot = new ProgramNode($1,$2, $1->line,$1->column);      } ;
globalList : globalList  variableDecl { $$ = new GlobalListNode($1, $2, $1->line,$1->column ); }   | { $$ = (GlobalListNode *)NULLnode; }   ;
functionList : functionList functionDecl { $$ = new FunctionListNode($1, $2, $2->line, $2->column); }     | functionDecl {$$ = new FunctionListNode(      (FunctionListNode *)NULLnode, $1,$1->line,$1->column);}     ;
type : INT  {$$ = new TypeIntNode ( $1.line,$1.column ); }     | BOOL {$$ = new TypeBoolNode( $1.line, $1.column); }     ;
variableDecl : type identifier SEMICOLON {$$ = new VariableDeclNode( $1,$2, $2->line,$2->column );}     | type identifier LBRACKET intLiteral RBRACKET SEMICOLON {$$ = new ArrayDeclNode($1, $2, $4, $2->line, $2->column );}     ;
functionDecl : VOID identifier parameters LBRACE varList stmtList RBRACE       {$$ = new FunctionDeclNode(      (TypeNode *)NULLnode, $2,$3,$5,$6,$2->line,$2->column);}     | type identifier parameters LBRACE varList stmtList RBRACE       {$$ = new FunctionDeclNode($1, $2, $3, $5, $6, $2->line, $2->column);}     ;
parameters : LPAREN RPAREN { ParamListNode * n = (ParamListNode *)NULLnode;                  $$ = new ParametersNode(  n, $1.line,$1.column ); }   | LPAREN paramList RPAREN { $$ = new ParametersNode($2, $1.line, $1.column); }   ;
paramList : paramList COMMA param { $$ = new ParamListNode($1, $3, $2.line, $2.column); }  | param { $$ = new ParamListNode( (ParamListNode *)NULLnode, $1, $1->line, $1->column); }  ;
param : type identifier { $$ = new ParamValNode($1, $2, $1->line, $1->column); }      | type identifier LBRACKET RBRACKET { $$ = new ParamArrayNode($1, $2, $1->line, $1->column); }      ;
varList : { $$ = (VarListNode *)NULLnode; } | varList variableDecl { $$ = new VarListNode($1, $2, $1->line, $1->column); } ;
stmtList : stmtList stmt { $$ = new StmtListNode( $1, $2, $1->line,$1->column ); } | { $$ = (StmtListNode *)NULLnode; } ;
stmt : target ASSIGN expression SEMICOLON { $$ = new AssignNode( $1, $3, $2.line,$2.column ); } | PRINT LPAREN printList RPAREN SEMICOLON { $$ = new PrintNode( $3, $1.line,$1.column ); } | COUT AARROW coutList SEMICOLON { $$ = new CoutNode( $3, $1.line, $1.column ); } | IF LPAREN expression RPAREN stmt %prec THEN { $$ = new IfNode($3, $5, (StmtNode *)NULLnode, $2.line, $2.column); } | IF LPAREN expression RPAREN stmt ELSE stmt { $$ = new IfNode($3, $5, $7, $2.line, $2.column); } | WHILE LPAREN expression RPAREN stmt { $$ = new WhileNode($3, $5, $1.line, $1.column); } | LBRACE varList stmtList RBRACE { $$ = new BlockNode($2, $3, $1.line, $1.column); } | RETURN SEMICOLON { $$ = new ReturnNode((ExpressionNode *)NULLnode, $1.line, $1.column); } | RETURN expression SEMICOLON { $$ = new ReturnNode($2, $1.line, $1.column); } | identifier LPAREN RPAREN SEMICOLON { ArgListNode * n = (ArgListNode *)NULLnode;  $$ = new ProcCallNode($1, n, $2.line, $2.column); } | identifier LPAREN argList RPAREN SEMICOLON { $$ = new ProcCallNode($1, $3, $2.line, $2.column); }        ;
argList : argList COMMA expression { $$ = new ArgListNode($1, $3, $1->line, $1->column); } | expression { $$ = new ArgListNode((ArgListNode *)NULLnode, $1, $1->line, $1->column); } ;
printList : printList COMMA printItem { $$ = new PrintListNode($1, $3, $1->line, $1->column); }  | printItem { PrintListNode * n = (PrintListNode *)NULLnode;                  $$ = new PrintListNode(  n, $1, $1->line,$1->column); }  ;
printItem : stringLiteral { $$ = $1; }  | expression    { $$ = $1; }  ;
coutList : coutList AARROW coutItem { $$ = new CoutListNode($1, $3, $1->line, $1->column); } | coutItem { CoutListNode *n = (CoutListNode *)NULLnode;  $$ = new CoutListNode( n, $1, $1->line, $1->column); } ;
coutItem : stringLiteral {$$ = $1; } | expression    {$$ = $1; };
expression : ORexpression { $$ = $1; };
ORexpression: ORlist { $$ = $1; };
ORlist: ORlist OR ANDexpression { $$ = new OrNode($1, $3, $2.line, $2.column); }      | ANDexpression { $$ = $1; }      ;
ANDexpression: ANDlist { $$ = $1; };
ANDlist: ANDlist AND term { $$ = new AndNode($1, $3, $2.line, $2.column); }       | term { $$ = $1; };
term : factor LT  factor { $$ = new RelOpNode( LT, $1, $3, $2.line, $2.column); } | factor GT  factor { $$ = new RelOpNode( GT, $1, $3, $2.line, $2.column); } | factor LEQ factor { $$ = new RelOpNode( LEQ, $1, $3, $2.line, $2.column); } | factor GEQ factor { $$ = new RelOpNode( GEQ, $1, $3, $2.line, $2.column); } | factor EQ  factor { $$ = new RelOpNode( EQ, $1, $3, $2.line, $2.column); } | factor NEQ factor { $$ = new RelOpNode( NEQ, $1, $3, $2.line, $2.column); } | factor { $$ = $1; } ;
factor : factor PLUS  primary  { $$ = new ArithOpNode( PLUS , $1, $3, $2.line,$2.column ); } | factor MINUS primary  { $$ = new ArithOpNode( MINUS, $1, $3, $2.line,$2.column ); } | primary  { $$ = $1; } ;
primary : primary TIMES unit { $$ = new ArithOpNode( TIMES, $1, $3, $2.line, $2.column); } | primary SLASH unit { $$ = new ArithOpNode( SLASH, $1, $3, $2.line, $2.column); } | unit  { $$ = $1; } ;
unit : nameVar  { $$ = $1; }     | arrayVar { $$=$1;}     | intLiteral { $$=$1;}     | MINUS intLiteral { $$=$2; $$->myIntVal=-$2->myIntVal;}     | identifier LPAREN RPAREN { $$= new FnCallNode($1, (ArgListNode *)NULLnode,     $2.line, $2.column); }     | identifier LPAREN argList RPAREN { $$= new FnCallNode($1, $3, $2.line, $2.column); }     | TRUE     { $$ = new TrueNode($1.line, $1.column);}     | FALSE    { $$ = new FalseNode($1.line, $1.column);}     | LPAREN expression RPAREN { $$=$2; }     ;
nameVar : identifier { $$ = new NameVarNode( $1, $1->line,$1->column ); };
arrayVar: identifier LBRACKET expression RBRACKET { $$ = new ArrayVarNode( $1, $3, $1->line, $1->column); };
intLiteral : INTLITERAL             { $$ = new IntLiteralNode($1.intVal, $1.line,$1.column); };
stringLiteral : STRINGLITERAL     { $$ = new StringLiteralNode($1.stringVal, $1.line, $1.column);};
target : identifier            { ExpressionNode * n = (ExpressionNode *)NULLnode;                      $$ = new TargetNode( $1,  n, $1->line,$1->column ); } | identifier LBRACKET expression RBRACKET    { $$ = new TargetNode($1, $3, $1->line, $1->column ); } ;
identifier : ID { $$ = new IdentifierNode($1.stringVal, $1.line,$1.column); }           ;
%%
extern char *yytext; /* we must supply the yyerror function         */ /* bison demands int; yacc accepts int or void */ int yyerror( char *msg ) {  cerr << "\nbison: " << msg       << " line "    << yylval.t.line       << " column "  << yylval.t.column       << " (yytext=\""  << yytext << "\")\n\n";  exit(1); } // symbol.h
#ifndef SYMBOL_GUARD #define SYMBOL_GUARD
#include <string> using namespace std;
// ********************************************* // The Symbol class defines a symbol-table entry // ********************************************* // // Member functions // ================ // // constructor // =========== // Symbol(string S) -- constructor: creates a Symbol with the given name //
enum SymbolType {VoidType, IntType, BoolType, StringType, ErrorType}; enum SymbolKind {VarKind,ArrayKind, FnKind, ValParamKind,ArrayParamKind, ErrorKind}; enum SymbolAdr  {Global, Local};
class Symbol {  public:    Symbol(string S);   // constructor
   string symbolName;  // symbol name
   //set by the name checker
   SymbolType symbolType;    SymbolKind symbolKind;
   int arraySize;    int offset;    int parameterCount;  // only for functions    int localVarCount;   // only for functions    int frameSize;       // only for functions
   //set by the code generator
   SymbolAdr  adr;
   // class function (for debugging)    static string printSymbolType( SymbolType t ); };
typedef Symbol * SymbolPtr;
#endif // t1.z // A demonstration of bools and if // it also prints intLits and global ints, and string lits
int  x; int  y; bool b; bool t; bool f;
int main() {  x = 3; y = x; print( x, " ", y, " ", 5 ); print("\n");
 if (true ) print("true"); else print("false"); print("\n");  if (false) print("true"); else print("false"); print("\n");
 t = true; f = false;  b = true ; if (b) print("true"); else print("false"); print("\n");  b = false; if (b) print("true"); else print("false"); print("\n");  b = t    ; if (b) print("true");                      print("\n");  t = f    ; if (t) print("true"); else print("false"); print("\n");
 return 0; } // ast.h
#ifndef AST_H_ #define AST_H_
#include <iostream> #include <iomanip> #include "symbol.h"
// forward class  GlobalListNode ; class  FunctionListNode ; class  DeclNode ; class  FunctionDeclNode ; class  TypeNode ; class  ParametersNode ; class  ParamListNode ; class  ParamNode ; class  VarListNode ; class  StmtListNode ; class  StmtNode ; class  ArgListNode ; class  PrintListNode ; class  PrintItemNode ; class  ExpressionNode ; class  TargetNode ; class  IntLiteralNode ; class  CoutListNode ; class  CoutItemNode     ;
class ASTnode   // ABSTRACT BASE CLASS { public:
// every node will have a line number and a column number // so unparsing can produce a kind of pretty-printing const int line  ; const int column; void doLineNum() { cout << setw(6) << line << ": "; } int Reg; int lbl;
SymbolType nodeType;
ASTnode(int l, int c) : line(l), column(c) {};
virtual bool isNull ()  { return false; } virtual bool isBlock()  { return false; } virtual bool isName() { return false; } virtual bool isOr()     { return false; } virtual bool isAnd()    { return false; } virtual bool isRel()    { return false; } virtual bool isTrue()   { return false; } virtual bool isFalse()  { return false; } virtual void unparse(int indent=0) =0; virtual void checkNames() =0; virtual void checkTypes() =0; virtual void emitCode() =0; private:
// disable copy constructor and copy assignment operator ASTnode(const ASTnode & n); ASTnode & operator= (const ASTnode & n); };
class IdentifierNode : public ASTnode { private: string * myStringVal; Symbol * mySymbolTableEntry; public: IdentifierNode(string *, int, int); string getMyStringVal() { return * myStringVal; } void setMySymbolTableEntry(Symbol * s) { mySymbolTableEntry = s; } Symbol * getSymbol() { return mySymbolTableEntry; } virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode() {return;} };
class ProgramNode : public ASTnode { private: GlobalListNode   * myGlobalList; FunctionListNode * myFunctionList; public: ProgramNode(GlobalListNode*, FunctionListNode*, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class GlobalListNode : public ASTnode { private: GlobalListNode * myGlobalList; DeclNode       * myDecl; public: GlobalListNode(GlobalListNode*, DeclNode*, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class FunctionListNode : public ASTnode { private: FunctionListNode * myFunctionList; FunctionDeclNode * myFunctionDecl; public: FunctionListNode(FunctionListNode*, FunctionDeclNode*, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class FunctionDeclNode : public ASTnode { private: TypeNode       * myType; IdentifierNode * myIdentifier; ParametersNode * myParameters; VarListNode    * myVarList; StmtListNode   * myStmtList; Symbol * mySymbolTableEntry; public: FunctionDeclNode( TypeNode*, IdentifierNode*, ParametersNode*,                          VarListNode*, StmtListNode*, int, int); void setMySymbolTableEntry(Symbol * s) { mySymbolTableEntry = s; } virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class TypeNode : public ASTnode  // ABSTRACT BASE CLASS { public: TypeNode(int, int); virtual void unparse(int indent=0) =0; virtual void checkNames() = 0; virtual void checkTypes() = 0; }; // --------------- SUBCLASSES OF TypeNode --------------- class TypeIntNode : public TypeNode { public: TypeIntNode(int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class TypeBoolNode : public TypeNode { public: TypeBoolNode(int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); }; // --------------- SUBCLASSES OF TypeNode ---------------
class DeclNode : public ASTnode  // ABSTRACT BASE CLASS { public: DeclNode(int, int); virtual void unparse(int indent=0) =0; virtual void checkNames() = 0; virtual void checkTypes() = 0; virtual void emitCode()   = 0; }; // --------------- SUBCLASSES OF DeclNode ---------------
class VariableDeclNode : public DeclNode { private: TypeNode       * myType; IdentifierNode * myIdentifier; public: VariableDeclNode(TypeNode*, IdentifierNode*, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class ArrayDeclNode : public DeclNode { private: TypeNode       * myType; IdentifierNode * myIdentifier; ExpressionNode * myIntLit; public: ArrayDeclNode(TypeNode*, IdentifierNode*, ExpressionNode*, int,int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); }; // --------------- SUBCLASSES OF DeclNode ---------------
class ParametersNode : public ASTnode { private: ParamListNode * myParamList; public: ParametersNode :: ParametersNode(ParamListNode*, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class ParamListNode : public ASTnode { private: ParamListNode * myParamList; ParamNode     * myParam    ; public: ParamListNode :: ParamListNode(ParamListNode*, ParamNode*, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class ParamNode : public ASTnode   // ABSTRACT BASE CLASS { public: ParamNode :: ParamNode(int, int); virtual void unparse(int indent=0) =0; virtual void checkNames() =0; virtual void checkTypes() =0; virtual void emitCode()   =0; }; // --------------- SUBCLASSES OF ParamNode --------------- class ParamValNode : public ParamNode { private: TypeNode       * myType      ; IdentifierNode * myIdentifier; public: ParamValNode :: ParamValNode(TypeNode*, IdentifierNode*, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class ParamArrayNode : public ParamNode { private: TypeNode       * myType      ; IdentifierNode * myIdentifier; public: ParamArrayNode::ParamArrayNode(TypeNode*, IdentifierNode*, int,int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); }; // --------------- SUBCLASSES OF ParamNode ---------------
class VarListNode : public ASTnode { private: VarListNode * myVarList; DeclNode    * myDecl; public: VarListNode(VarListNode *, DeclNode *, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes();             virtual void emitCode(); };
class StmtListNode : public ASTnode { private: StmtListNode * myStmtList; StmtNode     * myStmt; public: StmtListNode(StmtListNode *, StmtNode *, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class StmtNode : public ASTnode   // ABSTRACT BASE CLASS { public: StmtNode(int, int); virtual void unparse(int indent=0) =0; virtual void checkNames() =0; virtual void checkTypes() =0; virtual void emitCode()   =0; }; // --------------- SUBCLASSES OF StmtNode --------------- class AssignNode : public StmtNode { private: TargetNode     * myTarget; ExpressionNode * myExpression; public: AssignNode(TargetNode *, ExpressionNode *, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class IfNode : public StmtNode { private: ExpressionNode * myExpression; StmtNode       * myThenStmt; StmtNode       * myElseStmt; public: IfNode(ExpressionNode *, StmtNode *, StmtNode *, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class WhileNode : public StmtNode { private: ExpressionNode * myExpression; StmtNode       * myStmt; public: WhileNode(ExpressionNode *, StmtNode *, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class BlockNode : public StmtNode { private:        VarListNode  * myVarList;        StmtListNode * myStmtList; public:        BlockNode( VarListNode*, StmtListNode*, int, int); virtual bool isBlock() { return true; }        virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class ReturnNode : public StmtNode { private: ExpressionNode * myReturnVal; public: ReturnNode(ExpressionNode*, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class ProcCallNode : public StmtNode { private: IdentifierNode * myIdentifier; ArgListNode    * myArgList   ; public: ProcCallNode(IdentifierNode*, ArgListNode*, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class PrintNode : public StmtNode { private: PrintListNode * myPrintList; public: PrintNode(PrintListNode *, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class CoutNode : public StmtNode { private: CoutListNode * myCoutList; public: CoutNode(CoutListNode *, int, int); virtual void unparse(int indent=0); virtual void checkNames() {return;} virtual void checkTypes() {return;} virtual void emitCode()   {return;} }; // --------------- SUBCLASSES OF StmtNode ---------------
class ArgListNode : public ASTnode { private: ArgListNode    * myArgList   ; ExpressionNode * myExpression;
public: ArgListNode(ArgListNode *, ExpressionNode *, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class PrintListNode : public ASTnode { private: PrintListNode * myPrintList; PrintItemNode * myPrintItem; public: PrintListNode(PrintListNode *, PrintItemNode *, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class CoutListNode : public ASTnode { private: CoutListNode * myCoutList; PrintItemNode * myCoutItem; public: CoutListNode(CoutListNode *, PrintItemNode *, int, int); virtual void unparse(int indent=0); virtual void checkNames() {return;} virtual void checkTypes() {return;} virtual void emitCode() {return;} };
class PrintItemNode : public ASTnode   // ABSTRACT BASE CLASS { public: SymbolType myType; Symbol * mySymbolTableEntry; void setMySymbolTableEntry(Symbol * s) { mySymbolTableEntry = s; } PrintItemNode(int,int); virtual void unparse(int indent=0) =0; virtual void checkNames() =0; virtual void checkTypes() =0; virtual void emitCode()   =0; };
class ExpressionNode : public PrintItemNode   // ABSTRACT BASE CLASS { public: int myIntVal;
ExpressionNode(int,int); virtual void unparse(int indent=0) =0; virtual void checkNames() =0; virtual void checkTypes() =0; virtual void emitCode()   =0; int emitRight() { return -1;} int emitLeft() {  return -1;} ExpressionNode * getL() {return NULL;} ExpressionNode * getR() {return NULL;} virtual IdentifierNode * getID() {return NULL;} virtual void doSethiUllmanLabeling() =0; virtual void doSethiUllmanCodeGen()  =0; int getOp() {return -1;} }; // --------------- SUBCLASSES OF ExpressionNode --------------- class OrNode : public ExpressionNode { private: ExpressionNode * myLeft  ; ExpressionNode * myRight ; public: OrNode(ExpressionNode *, ExpressionNode *, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); virtual void doSethiUllmanLabeling() { return; } virtual void doSethiUllmanCodeGen()  { return; } virtual bool isOr()     { return true; } ExpressionNode * getL() {return myLeft;} ExpressionNode * getR() {return myRight;} };
class AndNode : public ExpressionNode { private: ExpressionNode * myLeft  ; ExpressionNode * myRight ; public: AndNode(ExpressionNode *, ExpressionNode *, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); virtual void doSethiUllmanLabeling() { return; } virtual void doSethiUllmanCodeGen()  { return; } virtual bool isAnd()     { return true; } ExpressionNode * getL() {return myLeft;} ExpressionNode * getR() {return myRight;} };
class RelOpNode : public ExpressionNode { private: int              myRelOp; ExpressionNode * myLeft ; ExpressionNode * myRight; public: RelOpNode(int, ExpressionNode *, ExpressionNode *, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); virtual void doSethiUllmanLabeling() { return; } virtual void doSethiUllmanCodeGen()  { return; } int emitRight() { myRight->emitCode(); return myRight->Reg;} int emitLeft() { myLeft->emitCode(); return myLeft->Reg;} int getOp() { return myRelOp;} virtual bool isRel()     { return true; } };
class ArithOpNode : public ExpressionNode { private: int              myArithOp; ExpressionNode * myLeft ; ExpressionNode * myRight; public: ArithOpNode(int, ExpressionNode *, ExpressionNode *, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); virtual void doSethiUllmanLabeling(); virtual void doSethiUllmanCodeGen(); };
class FnCallNode : public ExpressionNode { private: IdentifierNode * myIdentifier; ArgListNode    * myArgList   ; public: FnCallNode(IdentifierNode *, ArgListNode *, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); virtual void doSethiUllmanLabeling(); virtual void doSethiUllmanCodeGen(); IdentifierNode * getID() { return myIdentifier; } };
class TrueNode : public ExpressionNode { public: TrueNode(int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); virtual void doSethiUllmanLabeling() { return; } virtual void doSethiUllmanCodeGen()  { return; } virtual bool isTrue()     { return true; } };
class FalseNode : public ExpressionNode { public: FalseNode(int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); virtual void doSethiUllmanLabeling() { return; } virtual void doSethiUllmanCodeGen()  { return; } virtual bool isFalse()     { return true; } };
class NameVarNode : public ExpressionNode { private: IdentifierNode * myIdentifier; public: NameVarNode( IdentifierNode *, int, int); virtual bool isName() { return true;} virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); virtual void doSethiUllmanLabeling(); virtual void doSethiUllmanCodeGen(); virtual IdentifierNode * getID() {return myIdentifier;} };
class ArrayVarNode : public ExpressionNode { private: IdentifierNode * myIdentifier; ExpressionNode * myExpression; public: ArrayVarNode( IdentifierNode *, ExpressionNode *, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); virtual void doSethiUllmanLabeling(); virtual void doSethiUllmanCodeGen(); };
class IntLiteralNode : public ExpressionNode { public: IntLiteralNode(int, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); virtual void doSethiUllmanLabeling(); virtual void doSethiUllmanCodeGen(); }; // --------------- SUBCLASSES OF ExpressionNode ---------------
class TargetNode : public ASTnode { private: IdentifierNode * myIdentifier; ExpressionNode * myExpression; public: TargetNode(IdentifierNode *, ExpressionNode *, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); IdentifierNode * getID() { return myIdentifier; } ExpressionNode * getExp() {return myExpression; } };
class StringLiteralNode : public PrintItemNode { private: string * myStringVal; public: StringLiteralNode(string *, int, int); virtual void unparse(int indent=0); virtual void checkNames(); virtual void checkTypes(); virtual void emitCode(); };
class NullNode : public ASTnode { public: NullNode() : ASTnode(0,0) {} virtual bool isNull() { return true; } virtual void unparse(int indentVal=0) { return; } virtual void checkNames() { return; }; virtual void checkTypes() { return; }; virtual void emitCode() {return;} };
extern ASTnode * astRoot;
#endif /* scanner.h */
#ifndef SCANNER_H_ #define SCANNER_H_
#include <stdio.h> #include <iostream> #include <string> using namespace std;
//input file pointer used by yylex();  defined in lex.yy.c extern FILE *yyin;
struct TokenType {  int    line;  int    column;  int    intVal;     // used by integer token  string *stringVal; // used by identifier and string tokens };
#endif // namecheck.cc
/* *  build symbol table and check for declaration/use errors: *      a) multiply declared identifiers *      b) undeclared identifiers *  find errors with the "main" function *  compute offsets and other information */ using namespace std; #include <string> #include "symbol.h" #include "symboltable.h" #include "symlist.h" #include "ast.h" #include "message.h"
#define DEBUG 0 #define BUG(d) if(d)cerr<<whoami()<<endl;cerr.flush();
static SymTableList  symList; static SymbolTable * ptrCurrentSymTab;
int declErrors        = 0; int currentOffset     = 0; int numParameters     = 0; int localVarCount     = 0; bool isGlobal         = true;
void ProgramNode :: checkNames() {  // Global Symbol Table  symList.push( new SymbolTable );  ptrCurrentSymTab = symList.top();  // ... your code goes here  myGlobalList->checkNames();  isGlobal = false;  myFunctionList->checkNames();  string str = "main";  if( symList.lookUp(str) == NULL || symList.lookUp(str)->symbolKind != FnKind){ string msg = "function main is missing"; Error(0,0,msg); declErrors++;  }  symList.pop(); }
void GlobalListNode :: checkNames() {  myGlobalList -> checkNames();  myDecl       -> checkNames(); }
void FunctionListNode :: checkNames() {  myFunctionList -> checkNames();  myFunctionDecl -> checkNames(); } // in file namecheck.cc, these are the only two nodes that // will record a data type in the member nodeType // this is done so that symbols entered in the symbol table // will have complete information // the next pass, implemented in file typecheck.cc, will // give other nodeType members data type information
void TypeIntNode  :: checkNames()  { nodeType =  IntType; } void TypeBoolNode :: checkNames()  { nodeType = BoolType; }
void VariableDeclNode :: checkNames()    // int x; {  myType -> checkNames();  // data type  localVarCount++;
 // name is being DECLARED  // check for multiply-declared variable name
 // strategy  // we cannot recurse to the identifier node because  //   identifier node assumes the USAGE of a name  // so, we must access identifier node information indirectly  //   by following the pointer to the identifier node
 string  varName = myIdentifier -> getMyStringVal();   // variable name  Symbol * symbol = ptrCurrentSymTab -> Lookup(varName);  // look it up
 if (symbol != NULL) { // name is already in the symbol table // ERROR : variable is MULTIPLY_DECLARED string msg =  varName + " is already declared"; Error(line,column,msg); declErrors++;  }  else{ // create symbol Symbol * s = new Symbol(varName); s->symbolType = myType->nodeType; s->symbolKind = VarKind; s->offset = currentOffset; if(isGlobal){ s->adr = Global; } else{ s->adr = Local; }
currentOffset += 4; s->arraySize = 0; ptrCurrentSymTab->Insert(s); myIdentifier->setMySymbolTableEntry(s);  } }
void ArrayDeclNode :: checkNames() {  myType -> checkNames();
 string varName =  myIdentifier -> getMyStringVal();  Symbol * symbol = ptrCurrentSymTab -> Lookup(varName);
 if (symbol != NULL) { // name is already in the symbol table // ERROR : variable is MULTIPLY_DECLARED string msg =  varName + " is already declared"; Error(line,column,msg); declErrors++;  }  else{ // create symbol Symbol * s = new Symbol(varName); s->symbolType = myType-> nodeType; s->symbolKind = ArrayKind; s->arraySize = myIntLit->myIntVal; if(isGlobal){ s->adr = Global; } else{ s->adr = Local; } localVarCount += s->arraySize; currentOffset += s->arraySize * 4; s->offset = currentOffset - 4; ptrCurrentSymTab->Insert(s); myIdentifier->setMySymbolTableEntry(s);  } }
void FunctionDeclNode :: checkNames() {  bool multipleDecl = false;  currentOffset  = 0;  numParameters  = 0;  localVarCount  = 0;
 myType -> checkNames();
 // your code goes here  string  varName = myIdentifier -> getMyStringVal();   // variable name  Symbol * symbol = ptrCurrentSymTab -> Lookup(varName);  // look it up
 if (varName == "main") { if(myType->isNull() || myType->nodeType == BoolType){ string msg = varName + " does not return int"; Error(line,column,msg); declErrors++; }  }
 if (symbol != NULL) { // name is already in the symbol table        // ERROR : function is MULTIPLY_DECLARED multipleDecl = true; string msg =  varName + " is already declared"; Error(line,column,msg); declErrors++;  }  // create symbol  mySymbolTableEntry = new Symbol(varName);
 if(!multipleDecl) ptrCurrentSymTab->Insert(mySymbolTableEntry);  // make new Symbol table and set it as the current one  symList.push(new SymbolTable);  ptrCurrentSymTab = symList.top();
 myParameters -> checkNames();  currentOffset += 8;
 if(numParameters != 0 && varName == "main"){ string msg = varName + " has a parameter"; Error(line, column, msg); declErrors++;  }  // in either case, keep going; name check body of function  myVarList  -> checkNames();  myStmtList -> checkNames();
 symList.pop();  ptrCurrentSymTab = symList.top();
 // if not multiply declared  // insert values into Symbol then put it into the symbolTable  if(! multipleDecl ){   if(!myType->isNull()){ mySymbolTableEntry->symbolType = myType->nodeType;   } else{ mySymbolTableEntry->symbolType = VoidType;   } mySymbolTableEntry->symbolKind = FnKind;   mySymbolTableEntry->parameterCount = numParameters; mySymbolTableEntry->frameSize      = (numParameters + localVarCount + 2) * 4;   mySymbolTableEntry->localVarCount  = localVarCount;   //ptrCurrentSymTab->Insert(mySymbolTableEntry);  } }
void ParametersNode :: checkNames() {  myParamList->checkNames(); }
void ParamListNode :: checkNames() {  myParamList->checkNames();  myParam    ->checkNames(); }
void ArgListNode :: checkNames() {  myArgList   ->checkNames();  myExpression->checkNames(); }
void ParamValNode :: checkNames() {  myType -> checkNames();  numParameters++;
 string  varName = myIdentifier -> getMyStringVal();   // variable name  Symbol * symbol = ptrCurrentSymTab -> Lookup(varName);  // look it up
 if (symbol != NULL) { // name is already in the symbol table // ERROR : variable is MULTIPLY_DECLARED string msg =  varName + " is already declared"; Error(line,column,msg); declErrors++;  }  else{ // create symbol Symbol * s = new Symbol(varName); s->symbolType = myType -> nodeType; s->symbolKind = ValParamKind; s->offset = currentOffset; currentOffset += 4; s->arraySize = 0; s->adr = Local; ptrCurrentSymTab->Insert(s); myIdentifier->setMySymbolTableEntry(s);  } }
void ParamArrayNode :: checkNames() {  myType -> checkNames();  numParameters++;
 string  varName = myIdentifier -> getMyStringVal();   // variable name  Symbol * symbol = ptrCurrentSymTab -> Lookup(varName);  // look it up
 if (symbol != NULL) { // name is already in the symbol table // ERROR : variable is MULTIPLY_DECLARED string msg =  varName + " is already declared"; Error(line,column,msg); declErrors++;  }  else{ // create symbol Symbol * s = new Symbol(varName); s->symbolType = myType -> nodeType; s->symbolKind = ArrayParamKind; s->offset = currentOffset; s->adr = Local; currentOffset += 4; ptrCurrentSymTab->Insert(s); myIdentifier->setMySymbolTableEntry(s);  } }
void VarListNode :: checkNames() {  myVarList->checkNames();  myDecl   ->checkNames(); }
void StmtListNode :: checkNames() {  myStmtList -> checkNames();  myStmt     -> checkNames(); }
void AssignNode :: checkNames() {  myTarget     -> checkNames();  myExpression -> checkNames(); }
void IfNode :: checkNames() {  myExpression-> checkNames();  myThenStmt  -> checkNames();  myElseStmt  -> checkNames(); }
void WhileNode :: checkNames() {  myExpression -> checkNames();  myStmt       -> checkNames(); }
void BlockNode :: checkNames() {  // make new Symbol table and set it as the current one  symList.push(new SymbolTable);  ptrCurrentSymTab = symList.top();
 // check the children's names  myVarList  -> checkNames();  myStmtList -> checkNames();
 // now that you're leaving take the symboltable off the stack  symList.pop();  ptrCurrentSymTab = symList.top(); }
void ReturnNode :: checkNames() {  myReturnVal->checkNames(); }
void ProcCallNode :: checkNames() {  myIdentifier -> checkNames();  myArgList    -> checkNames(); }
void PrintNode :: checkNames() {  myPrintList -> checkNames(); }
void PrintListNode :: checkNames() {  myPrintList-> checkNames();  myPrintItem-> checkNames(); }
void OrNode :: checkNames() {  myLeft  -> checkNames();  myRight -> checkNames(); }
void AndNode :: checkNames() {  myLeft  -> checkNames();  myRight -> checkNames(); }
void RelOpNode :: checkNames() {  myLeft  -> checkNames();  myRight -> checkNames(); }
void ArithOpNode :: checkNames() {  myLeft  -> checkNames();  myRight -> checkNames(); }
void TrueNode :: checkNames() {  return; }
void FalseNode :: checkNames() {  return; }
void NameVarNode :: checkNames() {  myIdentifier-> checkNames(); }
void ArrayVarNode :: checkNames() {  myIdentifier->checkNames();  myExpression->checkNames(); }
void FnCallNode :: checkNames() {  myIdentifier->checkNames();  myArgList   ->checkNames(); }
void IntLiteralNode :: checkNames() {  return; }
void TargetNode :: checkNames() {  myIdentifier->checkNames();  myExpression->checkNames(); }
void StringLiteralNode :: checkNames() {  return; }
void IdentifierNode :: checkNames()   // name USAGE {  // getting here recursively means that a  // name is being USED; check for undefined name  string varName = getMyStringVal();  Symbol * symbol = symList.lookUp(varName);
 if (symbol == NULL){ string msg = varName + " is undeclared"; Error(this->line, this->column, msg); declErrors ++; symbol = new Symbol(varName); symbol->symbolType = ErrorType;   ptrCurrentSymTab -> Insert(symbol);  }  setMySymbolTableEntry(symbol); } // codegen.cc             OO
using namespace std; #include "ast.h" #include "scanner.h" #include "y.tab.h" #include "message.h" #include "symlist.h" #include "symboltable.h" #include "int2str.h" #include "emit.h" #include <list> #include <map>
#define BUG(m)   // cerr<<m<<endl #define EMIT(m)  // emitComment(m)
#define NUMERIC false // Turn on numeric style coding / turn off control flow
void emitPrintString(); void emitPrintInt ( int reg ); void emitPrintBool( int reg );
void emitL ( string label, string opcode="",             string arg1="", string arg2="", string arg3="" ); void emitProgramHeader(); void emitProgramFooter(); void emitFunctionPrologue( string fn, int frameSize, int localVarCount ); void emitFunctionEpilogue( string fn, int parameterCount, int frameSize ); void declareGlobalVar  ( string name ); void declareGlobalArray( string name, int size ); void emitStringDefinition( string label, string String );
extern ofstream asmFile; extern bool   SethiUllmanFlag; static string    currentFunctionName(""); static SymbolPtr currentFunctionSym = NULL; map<string, string> l; //// static list<ExpressionNode *> * argumentList = NULL; // David Haltinner ===========================================================
string setRelOp( int kind ) {  string s;
 switch (kind) {     case LT : s = "slt"; break;     case LEQ: s = "sle"; break;     case GT : s = "sgt"; break;     case GEQ: s = "sge"; break;     case EQ : s = "seq"; break;     case NEQ: s = "sne"; break;     default : assert(0); break;  }  return s; }
string binaryOp( int kind ) {  string s;
 switch (kind) {    case PLUS : s = "add" ; break;    case MINUS: s = "sub" ; break;    case TIMES: s = "mulo"; break;    case SLASH: s = "div" ; break;    default   : assert(0) ; break;  }  return s; }
//*************storeIntoTarget is complete**************** void storeIntoTarget( ExpressionNode *astR, TargetNode *astL ) {   int     reg  = astR->Reg;   Symbol *ptrL = astL->getID()->getSymbol();
  if(ptrL->adr == Global && ptrL->symbolKind == VarKind){ emit( "sw",  "$t"+IntToStr(reg),  ptrL->symbolName+".v" );   }   else if( ptrL->adr == Global && ptrL->symbolKind == ArrayKind){ int regEx = astL->Reg; string regStr =  "0($t"+IntToStr(regEx)+")"; emit("sw", "$t"+IntToStr(reg), regStr); freeReg(regEx);   }   else if( ptrL->adr == Local &&  ( ptrL->symbolKind == VarKind || ptrL->symbolKind == ValParamKind )){ int o = ptrL->offset; string off = IntToStr(o); if(o > 0) off= "-"+off; emit("sw", "$t"+IntToStr(reg), off+"($fp)");   }   else if( ptrL->adr == Local && ptrL->symbolKind == ArrayKind){ int regEx = astL->Reg; int o = ptrL->offset; string off = IntToStr(o); if(o > 0) off= "-"+off; string regStr = off+"($t"+IntToStr(regEx)+")"; emit("sw", "$t"+IntToStr(reg), regStr); freeReg(regEx);   }   else if( ptrL->adr == Local && ptrL->symbolKind == ArrayParamKind){ int regEx = astL->Reg; string regStr = "0($t"+IntToStr(regEx)+")"; emit("sw", "$t"+IntToStr(reg), regStr); freeReg(regEx);   } }
void evaluateCondition( ExpressionNode *ast, string t, string f ) { if(ast->isAnd()) { string right(NextLabel()); evaluateCondition(((AndNode *)ast)->getL(), right, f); emitLabel(right); evaluateCondition(((AndNode *)ast)->getR(), t, f); } else if(ast->isOr()) { string next(NextLabel()); evaluateCondition(((OrNode *)ast)->getL(), t, next); emitLabel(next); evaluateCondition(((OrNode *)ast)->getR(), t, f); } else if(ast->isRel()){ string op; int kind = ((RelOpNode *)ast)->getOp(); int leftReg  = ((RelOpNode *)ast)->emitLeft(); int rightReg = ((RelOpNode *)ast)->emitRight(); string left = "$t" + IntToStr(leftReg); string right = "$t" + IntToStr(rightReg); switch (kind) {     case LT : op = "blt"; break;     case LEQ: op = "ble"; break;     case GT : op = "bgt"; break;     case GEQ: op = "bge"; break;     case EQ : op = "beq"; break;     case NEQ: op = "bne"; break;     default : assert(0); break; } emit(op, left, right, t); emit("j", f);
freeReg(leftReg); freeReg(rightReg); } else if(ast -> isTrue()){ emit("j", t); } else if(ast -> isFalse()){ emit("j", f); } else{ ast->emitCode();   emit( "beqz", ast->Reg, f ); emit( "j", t ); freeReg(ast->Reg); } } // David Haltinner ===========================================================
void ProgramNode :: emitCode() {  emitProgramHeader();  myGlobalList   -> emitCode();  myFunctionList -> emitCode();  emitProgramFooter(); }
void GlobalListNode :: emitCode() {  myGlobalList -> emitCode();  myDecl       -> emitCode(); }
void FunctionListNode :: emitCode() {  myFunctionList -> emitCode();  myFunctionDecl -> emitCode(); }
void ParametersNode :: emitCode() {  myParamList -> emitCode(); }
void ParamListNode :: emitCode() {  myParamList -> emitCode();  myParam     -> emitCode(); }
void VarListNode:: emitCode() {  myVarList -> emitCode();  myDecl    -> emitCode(); }
void StmtListNode :: emitCode() {  myStmtList -> emitCode();  myStmt     -> emitCode(); }
void PrintNode :: emitCode() {  myPrintList -> emitCode(); }
void TypeIntNode  :: emitCode() {return;} void TypeBoolNode :: emitCode() {return;}
void BlockNode :: emitCode() {  myVarList->emitCode();  myStmtList->emitCode(); }
void ParamValNode :: emitCode() { return; }
void ParamArrayNode :: emitCode() { return; }
void ArgListNode :: emitCode() { myArgList->emitCode(); myExpression->emitCode(); int reg = myExpression->Reg; emit("subu", "$sp", "$sp", IntToStr(4), "# argument"); emit("sw", "$t"+IntToStr(reg), "($sp)"); freeReg(reg); }
// David Haltinner ===========================================================
void VariableDeclNode :: emitCode()    // int x; {  //zinc always allocates 4 bytes for int and bool  //so, do not need to visit myType
  if(myIdentifier->getSymbol()->adr == Global){   declareGlobalVar( myIdentifier->getMyStringVal()+".v" );   } }
void ArrayDeclNode :: emitCode() {  Symbol * s = myIdentifier->getSymbol();
 if(s->adr == Global){ declareGlobalArray( s->symbolName+".v" , s->arraySize * 4 );  } }
void FunctionDeclNode :: emitCode() {  currentFunctionName =  myIdentifier -> getMyStringVal();  currentFunctionSym  = mySymbolTableEntry;  emitFunctionPrologue( currentFunctionName, currentFunctionSym->frameSize, currentFunctionSym->localVarCount);
 myParameters -> emitCode();  myVarList    -> emitCode();  myStmtList   -> emitCode();
 emitFunctionEpilogue     ( currentFunctionName,       currentFunctionSym->frameSize,       currentFunctionSym->parameterCount     );
 if (currentFunctionName!="main") emit( "jr", "$ra" );      // return  else{ emitEmptyLine(); emit( "li", "$v0", 10 );  // halt emit( "syscall", "\t\t# program exit" );  } }
// David Haltinner ===========================================================
void PrintListNode :: emitCode() {  myPrintList -> emitCode();  //emitComment( "print" );
 myPrintItem -> emitCode();   // string literal or expression
 switch( myPrintItem->nodeType ) {
    case StringType: emitPrintString(); break;     case IntType: emitPrintInt( myPrintItem->Reg ); freeReg(myPrintItem->Reg); break;     case BoolType: if(NUMERIC){ emitPrintBool( myPrintItem->Reg ); freeReg(myPrintItem->Reg); } else{ string endLabel = NextLabel();   emit( "la", "$a0", ".false" ); emit( "beqz", myPrintItem->Reg, endLabel);   emit( "la", "$a0", ".true" );   emitLabel(endLabel);   emitPrintString(); freeReg(myPrintItem->Reg); } break;     default: assert(0); break;  } }
void AssignNode :: emitCode() {  emitComment( "assignment" );
 myExpression -> emitCode();  // translate RHS (expression)  myTarget     -> emitCode();  // translate LHS (targetNode)
 storeIntoTarget( myExpression, myTarget );
 freeReg( myExpression->Reg );  freeReg( myTarget    ->Reg ); }
void IfNode :: emitCode() {  emitComment("if");  string trueLabel ( NextLabel() );  string falseLabel( NextLabel() );  string endifLabel( NextLabel() );
 if(NUMERIC){   myExpression -> emitCode();   emit( "beqz", myExpression->Reg, falseLabel );   freeReg(myExpression->Reg);  }  else{ evaluateCondition(myExpression, trueLabel, falseLabel);  }
 emitLabel(trueLabel);  emitComment("then");  myThenStmt -> emitCode();   // then clause  emit( "j", endifLabel );
 emitLabel(falseLabel);  emitComment("else");  myElseStmt -> emitCode();   // else clause
 emitLabel(endifLabel); }
void WhileNode :: emitCode() {  if(NUMERIC){   string compareLabel( NextLabel());   string trueLabel( NextLabel());
emitComment("while");   emit("j", compareLabel);   emitLabel(trueLabel);   myStmt -> emitCode();   emitLabel(compareLabel);   myExpression->emitCode();   emit("bnez", myExpression->Reg, trueLabel); freeReg(myExpression->Reg);  }  else{   string compareLabel( NextLabel());   string trueLabel( NextLabel()); string falseLabel( NextLabel() );
  emitComment("while"); emit("j", compareLabel); emitLabel(trueLabel); myStmt -> emitCode();   emitLabel(compareLabel); evaluateCondition(myExpression, trueLabel, falseLabel); emitLabel(falseLabel);  } }
void ProcCallNode :: emitCode() {   Symbol * s = myIdentifier->getSymbol();   emitComment("call");   saveRegs();   //throw args on stack   myArgList->emitCode();   emit("jal", s->symbolName+".f");   restoreRegs(); }
void ReturnNode :: emitCode() {  emitEmptyLine();  emitComment("return");
 if( !myReturnVal->isNull()) { myReturnVal -> emitCode(); emit( "move", "$v0", "$t"+IntToStr(myReturnVal->Reg) ); freeReg( myReturnVal->Reg );  }
 if(currentFunctionName=="main") emit( "j", currentFunctionName+".." );  else emit( "j", currentFunctionName+".f.." ); }
// David Haltinner ===========================================================
void OrNode :: emitCode() {   if(NUMERIC){ string falseLabel( NextLabel() ); string endLabel( NextLabel() );
myLeft->emitCode(); string regL = "$t"+IntToStr(myLeft->Reg); emit("beqz", regL, falseLabel ); emit("j", endLabel); emitLabel(falseLabel);
freeReg(myLeft->Reg); myRight->emitCode(); string regR = "$t"+IntToStr(myRight->Reg); emitLabel(endLabel); Reg = myRight->Reg;   }   else{ // THIS IS CONTROL FLOW CODE --------------------- string falseLabel = NextLabel(); string trueLabel = NextLabel(); string endLabel = NextLabel(); evaluateCondition(this, trueLabel, falseLabel); emitLabel(trueLabel); Reg = getReg();   emit( "li", Reg, 1 ); emit( "j", endLabel); emitLabel(falseLabel); emit( "li", Reg, 0 ); emitLabel(endLabel);   } }
void AndNode :: emitCode() {   if(NUMERIC){ string endLabel( NextLabel() ); myLeft->emitCode(); string regL = "$t"+IntToStr(myLeft->Reg); emit("beqz", regL, endLabel); freeReg(myLeft->Reg); myRight->emitCode(); Reg = myRight->Reg; emitLabel(endLabel);   }   else{ // THIS IS CONTROL FLOW CODE --------------------- string falseLabel = NextLabel(); string trueLabel = NextLabel(); string endLabel = NextLabel(); evaluateCondition(this, trueLabel, falseLabel); emitLabel(trueLabel); Reg = getReg();   emit( "li", Reg, 1 ); emit( "j", endLabel); emitLabel(falseLabel); emit( "li", Reg, 0 ); emitLabel(endLabel);   } }
void RelOpNode :: emitCode() {   if(NUMERIC){   // THIS IS NUMERIC CODE ----------- string op = setRelOp(myRelOp); int regL, regR; myLeft->emitCode(); myRight->emitCode(); regL = myLeft->  Reg; regR = myRight-> Reg; emit(op, "$t"+IntToStr(regL), "$t"+IntToStr(regL), "$t"+IntToStr(regR)); Reg = regL; freeReg(regR); // -------------------------------   }   else{ // THIS IS CONTROL FLOW CODE--------------------- string trueLabel = NextLabel(); string falseLabel = NextLabel(); string endLabel = NextLabel(); evaluateCondition(this, trueLabel, falseLabel); // Might need to load a 1 or a 0 into Reg for this to work emitLabel(trueLabel); Reg = getReg();   emit( "li", Reg, 1 ); emit( "j", endLabel); emitLabel(falseLabel); emit( "li", Reg, 0 ); emitLabel(endLabel);   } }
void ArithOpNode :: emitCode() { // ***************** ArithOpNode is finished ******************  if(SethiUllmanFlag){ doSethiUllmanLabeling(); doSethiUllmanCodeGen();  }  else{ string op = binaryOp(myArithOp); int regL, regR; myLeft->emitCode(); myRight->emitCode(); regL = myLeft->Reg; regR = myRight->Reg; emit(op, "$t"+IntToStr(regL), "$t"+IntToStr(regL), "$t"+IntToStr(regR)); Reg = regL; freeReg(regR);  } }
// David Haltinner ===========================================================
void FnCallNode :: emitCode() {   emitComment("call");   saveRegs();   //save args if any   myArgList->emitCode();   emit("jal", myIdentifier->getMyStringVal()+".f");   Reg=getReg();   emitComment("function value");   emit("move", Reg, "$v0"); }
void NameVarNode :: emitCode() {   Reg = getReg();   if(myIdentifier->getSymbol()->adr == Global &&      myIdentifier->getSymbol()->symbolKind == VarKind){   string name = myIdentifier->getMyStringVal();   emit( "lw", Reg, name+".v" );   // SUFFIX(variable)   }   else if(myIdentifier->getSymbol()->symbolKind == ArrayKind &&   myIdentifier->getSymbol()->adr == Global){   string name = myIdentifier->getMyStringVal(); emit("la", Reg, name+".v" );   }   else if(myIdentifier->getSymbol()->symbolKind == ArrayKind || myIdentifier->getSymbol()->symbolKind == ArrayParamKind ){ Symbol * s = myIdentifier->getSymbol(); int o = s->offset; string off = IntToStr(o); if(o > 0) off= "-"+off; emit( "addi", "$t"+IntToStr(Reg), "$fp", off);   }   else if(myIdentifier->getSymbol()->symbolKind == VarKind ||   myIdentifier->getSymbol()->symbolKind == ValParamKind){ Symbol * s = myIdentifier->getSymbol(); int o = s->offset; string off = IntToStr(o); if(o > 0) off= "-"+off; string regStr = off+ "($fp)"; emit( "lw", "$t"+IntToStr(Reg), regStr );   }   else{ assert(0);   } }
void ArrayVarNode :: emitCode() {   //need for all 3   myExpression->emitCode();   int RegFromExp=myExpression->Reg;   emit("sll", "$t"+IntToStr(RegFromExp), "$t"+IntToStr(RegFromExp), "2");
  //global only   if(myIdentifier->getSymbol()->adr == Global){ Reg=getReg(); string str(myIdentifier->getMyStringVal()); emit("la","$t"+IntToStr(Reg), str+".v"); emit("add","$t"+IntToStr(RegFromExp), "$t"+IntToStr(RegFromExp)  , "$t"+IntToStr(Reg)); emit("lw", "$t"+IntToStr(RegFromExp), "($t"+IntToStr(RegFromExp)+")"); freeReg(Reg); //am i really done with it? Reg = RegFromExp;   }   else if(myIdentifier->getSymbol()->adr == Local        && myIdentifier->getSymbol()->symbolKind == ArrayKind){   //local Symbol * s = myIdentifier->getSymbol(); emit("add", "$t"+IntToStr(RegFromExp), "$fp", "$t"+IntToStr(RegFromExp)); int o = s->offset; string off = IntToStr(o); if(o > 0) off= "-"+off; emit("lw", "$t"+IntToStr(RegFromExp), off+"($t"+IntToStr(RegFromExp)+")"); //freeReg(Reg); Reg = RegFromExp;   }   else{   //Param Reg=getReg(); Symbol * s = myIdentifier->getSymbol(); int o = s->offset; string off = IntToStr(o); if(o > 0) off= "-"+off; string regStr = off+ "($fp)"; emit("lw", "$t"+IntToStr(Reg), regStr); emit("add", "$t"+IntToStr(RegFromExp), "$t"+IntToStr(Reg),  "$t"+IntToStr(RegFromExp)); emit("lw", "$t"+IntToStr(RegFromExp), "0($t"+IntToStr(RegFromExp)+")"); freeReg(Reg); //ami really done with it though? Reg = RegFromExp;   } }
void IntLiteralNode :: emitCode() {  Reg = getReg();  emit( "li", Reg, myIntVal ); }
void TrueNode :: emitCode() {  Reg = getReg();  emit( "li", Reg, 1 ); }
void FalseNode :: emitCode() {  Reg = getReg();  emit( "li", Reg, 0 ); }
// David Haltinner ===========================================================
void TargetNode :: emitCode() {   // Explicitly tell the target it is the fp   // since all local vars are offset from fp   // and globals don't use registers   Reg = 30;   Symbol *ptrL = getID()->getSymbol();
  if(ptrL->adr == Global && ptrL->symbolKind == VarKind){ return;   }   else if( ptrL->adr == Global && ptrL->symbolKind == ArrayKind){ getExp()->emitCode(); int regEx = getExp()->Reg; int global = getReg(); string regStr = "$t"+IntToStr(regEx); emit("sll", regStr, regStr, IntToStr(2)); emit("la", "$t"+IntToStr(global), ptrL->symbolName+".v"); emit("add", regStr, regStr, "$t"+IntToStr(global)); freeReg(global); Reg = regEx;   }   else if( ptrL->adr == Local &&  ( ptrL->symbolKind == VarKind || ptrL->symbolKind == ValParamKind )){ return;   }   else if( ptrL->adr == Local && ptrL->symbolKind == ArrayKind){ getExp()->emitCode(); int regEx = getExp()->Reg; string regStr = "$t"+IntToStr(regEx); emit("sll", regStr, regStr, IntToStr(2)); emit("add", regStr, "$fp", regStr); Reg = regEx;   }   else if( ptrL->adr == Local && ptrL->symbolKind == ArrayParamKind){ getExp()->emitCode(); int reg = getReg(); int regEx = getExp()->Reg; int o = ptrL->offset; string regS = "$t"+IntToStr(reg); string regStr = "$t"+IntToStr(regEx); string off = IntToStr(o)+"($fp)"; if(o != 0) off = "-" + off; emit("sll", regStr, regStr, IntToStr(2)); emit("lw", regS, off); emit("add", regStr, regS, regStr); Reg = regEx; freeReg(reg);   } }
void StringLiteralNode :: emitCode() {  string label;
 if ( *myStringVal == "\"\\n\"" ) label = ".nl";  else{ if(l.find((*myStringVal)) == l.end()){ label = NextLabel(); emitStringDefinition( label, *myStringVal ); l[(*myStringVal)] = label; } else{ label = l[*myStringVal]; }  }
 // load into $a0 so it can be printed; can do it here  // because a string literal is only used in print statements  emit( "la", "$a0", label ); }
// David Haltinner =========================================================== // //          H I G H E R - L E V E L     E M I T     R O U T I N E S // // David Haltinner ===========================================================
void emitPrintString() {  emit( "li", "$v0", 4 );  emit( "syscall", "\t\t# print_string" ); }
void emitPrintInt( int reg ) {  emit( "move", "$a0", "$t"+IntToStr(reg) );  emit( "li"  , "$v0", 1 );  emit( "syscall", "\t\t# print_int" ); }
void emitPrintBool( int reg ) {  string falseLabel = NextLabel();  string endLabel = NextLabel();  emit( "beqz", "$t"+IntToStr(reg), falseLabel);  emit( "la", "$a0", ".true" );  emit( "j", endLabel);  emitLabel(falseLabel);  emit( "la", "$a0", ".false" );  emitLabel(endLabel);  emit( "li", "$v0", 4);  emit( "syscall", "\t\t# print_bool" ); }
// David Haltinner ===========================================================
void emitL (string label, string opcode,string arg1,string arg2,string arg3) {  asmFile << label << ":\t" ;  if ( opcode=="" ) {asmFile<<endl; return;} else asmFile << opcode;  if ( arg1  =="" ) {asmFile<<endl; return;} else asmFile << arg1;  if ( arg2  =="" ) {asmFile<<endl; return;} else asmFile << arg2;  if ( arg3  =="" ) {asmFile<<endl; return;} else asmFile << arg3;  asmFile<<endl;  asmFile.flush(); }
// David Haltinner ===========================================================
void emitProgramHeader() {  emit ( ".data" );  emitL( ".true" , ".asciiz\t", "\"true\""  );  emitL( ".false", ".asciiz\t", "\"false\"" );  emitL( ".nl"   , ".asciiz\t", "\"\\n\"" );  emit ( ".text" );  emit ( ".globl  main" );  emitEmptyLine(); }
void emitProgramFooter() {  asmFile.close(); }
// David Haltinner ===========================================================
void emitFunctionPrologue( string fn, int frameSize, int localVarCount ) {  emitEmptyLine();  if(fn!="main") emitLabel( fn+".f" ); else emitLabel( fn );  emitBlockComment( "PROLOGUE" );
 string space( IntToStr(localVarCount*4+8) );  if (localVarCount == 0)       emit( "subu", "$sp", "$sp", "8"  , "# registers ra & fp" );  else       emit( "subu", "$sp", "$sp", space, "# ra, fp & locals"   );  emit( "sw"  , "$ra", IntToStr(localVarCount*4+4)+"($sp)" );  emit( "sw"  , "$fp", IntToStr(localVarCount*4  )+"($sp)" );
 emit( "addu", "$fp", "$sp", IntToStr(frameSize-4), "# set new fp" ); }
void emitFunctionEpilogue( string fn, int frameSize, int parameterCount ) {  emitEmptyLine();  if(fn!="main") emitLabel( fn+".f.." ); else emitLabel( fn+".." );  emitBlockComment( "EPILOGUE" );
 emitOffset( "lw"  , "$ra", parameterCount*4,   "$fp", "# restore ra" );  emitOffset( "lw"  , "$fp", parameterCount*4+4, "$fp", "# restore fp" );
 emit( "addu", "$sp", "$sp", IntToStr(frameSize), "# Pop" ); }
// David Haltinner ===========================================================
void declareGlobalVar( string name ) {  emit ( ".data" );  emit ( ".align 2" );  emitL( name, ".space 4" );  //always 4 for simplicity  emit ( ".text" );  emitEmptyLine(); }
void declareGlobalArray( string name, int size ) {  emit ( ".data" );  emit ( ".align 2" );  emitL( name, ".space "+IntToStr(size) );  emit ( ".text" );  emitEmptyLine(); }
void emitStringDefinition( string label, string String ) {  emitEmptyLine();  emit ( ".data" );  emitL( label, ".asciiz\t ", String );  emit ( ".text" );  emitEmptyLine(); }
// David Haltinner =========================================================== // //                      S E T H I  -  U L L M A N // // David Haltinner ===========================================================
void ArithOpNode    :: doSethiUllmanLabeling() {  myLeft->doSethiUllmanLabeling();  myRight->doSethiUllmanLabeling();  if(myLeft->lbl == myRight->lbl){  lbl = myLeft->lbl+1;  }  else if(myLeft->lbl > myRight->lbl){ lbl = myLeft->lbl;  }  else{ lbl = myRight->lbl;  } }
void IntLiteralNode :: doSethiUllmanLabeling() {  lbl = 1; } void NameVarNode    :: doSethiUllmanLabeling() {  lbl = 1; } void ArrayVarNode   :: doSethiUllmanLabeling() {  lbl = 1; } void FnCallNode     :: doSethiUllmanLabeling() {  lbl = 1; }
void ArithOpNode    :: doSethiUllmanCodeGen()  { string op = binaryOp(myArithOp); int regL, regR;
if(myLeft->lbl > myRight->lbl){ myLeft->doSethiUllmanCodeGen(); myRight->doSethiUllmanCodeGen(); } if(myRight->lbl >= myLeft->lbl){ myRight->doSethiUllmanCodeGen(); myLeft->doSethiUllmanCodeGen(); }
regL = myLeft->Reg; regR = myRight->Reg; emit(op, "$t"+IntToStr(regL), "$t"+IntToStr(regL), "$t"+IntToStr(regR)); Reg = regL; freeReg(regR); }
void IntLiteralNode :: doSethiUllmanCodeGen()  { emitCode(); } void NameVarNode    :: doSethiUllmanCodeGen()  { emitCode(); } void ArrayVarNode   :: doSethiUllmanCodeGen()  { emitCode(); } void FnCallNode     :: doSethiUllmanCodeGen()  { emitCode(); } int j(int x, int y){ //tests function call, arithmatic operations, as well as print statements it should return 7 as the answer int z; z = 3; z = x + y + z; print(z);print("\n"); return z; } int main(){ //tests the main function, calls a function, and prints. Should print 7. int y; int x; x = 2; y = j(2, x); print(y);print("\n"); return 1; } int main(){ //tests printing and arithmatic operations plus, multiply, and divide. Should print "x is 28" followed by a new line int x; x = 2 + 3 * 5 / 4 * 8 + 2; print("x is ", x, "\n"); return x; } /* tokens.lex */
/* *  char *yytext  contains the lexeme of each token *  int   yyleng  is the length of the lexeme */
/* *  section 1:  names for regular expressions */
delimiter [ \t] newline [\n] whitespace {delimiter}+ digit [0-9] letter [a-zA-Z] integer {digit}+ other . identifier ({letter}|_)({letter}|{digit}|_)* comment1 "//"[^\n]*[\n] comment2 "//"[^\n]* mgcStrLt \"([^\"\n]|\\[^\n])*\" strLt \"([^\"\000-\037\177\n\\]|\\[^\000-\037\177\n])*\" rnAwyStrLt \"([^\"\000-\037\177\n]|\\[^\000-\037\177\n])*
%{ /* *  stuff here is copied directly into lex.yy.c *  as info outside of (above) yylex() */ using namespace std; #include "ast.h" #include "message.h" #include "scanner.h" #include "y.tab.h"    // token definitions created by bison #include "int2str.h"
#define  MAXINT  2147483647
static int line   = 1;  /* current line   number */ static int column = 1;  /* current column number */
/* forward */ void setPosition(); void doIntConvert(); int  idScreener(string *lexeme);
%}
%%
%{ /* * section 2: rules for regular expressions */ %}
{whitespace} { column += yyleng; } {newline} { line++; column=1; }
"="             { setPosition(); return ASSIGN;    } "," { setPosition(); return COMMA;   } ";" { setPosition(); return SEMICOLON;  } "("             { setPosition(); return LPAREN;    } ")" { setPosition(); return RPAREN;    } "{"             { setPosition(); return LBRACE;    } "}" { setPosition(); return RBRACE;   } "["             { setPosition(); return LBRACKET;  } "]" { setPosition(); return RBRACKET;  } "+" { setPosition(); return PLUS;   } "-" { setPosition(); return MINUS;   } "*" { setPosition(); return TIMES;   } "/" { setPosition(); return SLASH;   } ">" { setPosition(); return GT;   } "<" { setPosition(); return LT;   } "==" { setPosition(); return EQ;   } "!="        { setPosition(); return NEQ;   } ">=" { setPosition(); return GEQ;   } "<=" { setPosition(); return LEQ;   } "&&" { setPosition(); return AND;   } "||" { setPosition(); return OR;   } "<<" { setPosition(); return AARROW;    }
{integer} {  doIntConvert();  setPosition();  return INTLITERAL; }
{identifier} {  setPosition();  string *lexeme = new string(yytext);  yylval.t.stringVal = lexeme;  return idScreener(lexeme); }
{strLt} {  setPosition();  yylval.t.stringVal = new string(yytext);  return STRINGLITERAL;   }
{rnAwyStrLt} {  string c(yytext);  string msg = "unterminated string ";  msg = msg  + c;  Warn(line,column, msg);  column += yyleng; }
{mgcStrLt} {  string c(yytext);  string msg = "magic string ";  msg = msg + c;  Warn(line,column, msg);  column += yyleng; }
{comment1} { line++; column = 1; } {comment2} { line++; column = 1; }
{other} {  int bad = yytext[0];  string c(IntToStr(bad));  string msg = "yylex(): ignoring illegal character ";  msg = msg + " (ascii code " + c + ")";  Warn(line,column, msg);  column += yyleng; }
%%
/* *  section 3: functions used in section 2 */
void setPosition() {  yylval.t.line   = line  ;  yylval.t.column = column;  column += yyleng; }
int idScreener(string *lexeme) {  if      ( *lexeme == "print"  ) return PRINT;  if      ( *lexeme == "cout"   ) return COUT;  else if ( *lexeme == "int"    ) return INT;  else if ( *lexeme == "void"   ) return VOID;  else if ( *lexeme == "if" ) return IF;  else if ( *lexeme == "else"   ) return ELSE;  else if ( *lexeme == "while"  ) return WHILE;  else if ( *lexeme == "bool"   ) return BOOL;  else if ( *lexeme == "true"   ) return TRUE;  else if ( *lexeme == "false"  ) return FALSE;  else if ( *lexeme == "return" ) return RETURN;  else                            return ID; }
void doIntConvert() { if(atof(yytext) > MAXINT){ yylval.t.intVal = MAXINT; string msg = "int literal exceeds MAXINT;\n\tsubstituting MAXINT"; Warn(line, column, msg); } else{ yylval.t.intVal = atoi(yytext); } } // unparse.cc
#include <assert.h> #include <iomanip> #include <typeinfo> #include  "ast.h" #include  "scanner.h" #include  "y.tab.h"
void indent(int indentVal=0) {  for (int i=1; i<=indentVal; i++) cout << "   ";  // 3 spaces }
//============================================================
void ProgramNode :: unparse( int indentVal ) {  indent(indentVal+1);  cout<<"functionName<parameters:locals:frameSize>;"<<endl;  indent(indentVal+1);  cout<<"variableName<offset>\n";  myGlobalList   -> unparse();  myFunctionList -> unparse(); }
void GlobalListNode :: unparse( int indentVal ) {  myGlobalList -> unparse();  myDecl       -> unparse(); }
void TypeIntNode :: unparse( int indentVal ) {  cout << "int  "; }
void TypeBoolNode :: unparse( int indentVal ) {  cout << "bool "; }
void VariableDeclNode :: unparse( int indentVal ) {  doLineNum();  indent(indentVal);  myType       -> unparse(indentVal);  myIdentifier -> unparse(indentVal);  if(myIdentifier->getSymbol()->adr == Local){  cout<<" <" << myIdentifier->getSymbol()->offset << "> ";  }  cout << ";" << endl; }
void FunctionDeclNode :: unparse( int indentVal ) {    doLineNum();  myType -> unparse(indentVal);  if(myType->isNull())  {    indent(indentVal);    cout<<"void ";  }  myIdentifier -> unparse(indentVal);  cout<<" <"<<mySymbolTableEntry->parameterCount<<":"      <<mySymbolTableEntry->localVarCount<<":"<<mySymbolTableEntry->frameSize      <<"> (";  myParameters -> unparse(indentVal);  cout << ")" << endl;
 doLineNum();  cout << "{" << endl;  myVarList->unparse(indentVal+1);  myStmtList -> unparse(indentVal+1);  doLineNum();  cout << "}" << endl; }
void ParametersNode:: unparse(int indentVal){  myParamList -> unparse(indentVal); }
void ParamListNode:: unparse(int indentVal){  if(!myParamList->isNull()){    myParamList->unparse(indentVal);    cout<< ", ";  }  cout<<endl;  doLineNum();  indent(indentVal+2);  myParam->unparse(indentVal); }
void ParamValNode::unparse(int indentVal){  myType->unparse(indentVal);  myIdentifier->unparse(indentVal);  cout << " <" << myIdentifier->getSymbol()->offset << "> "; }
void ParamArrayNode::unparse(int indentVal){  myType->unparse(indentVal);  myIdentifier->unparse(indentVal);  cout<< " <" << myIdentifier->getSymbol()->offset << "> " << "[]"; }
void ArgListNode :: unparse(int indentVal){  if (!myArgList->isNull()) {    myArgList->unparse(indentVal);    cout<<", ";  }  myExpression->unparse(indentVal); }
void OrNode :: unparse(int indentVal){  if(!myLeft->isNull()){    cout << "(";    myLeft->unparse(indentVal);    cout <<" || ";    myRight->unparse(indentVal);    cout << ")";    return;  }  myRight->unparse(indentVal); }
void StringLiteralNode::unparse(int indentVal){   cout<< *myStringVal; }
void FnCallNode::unparse(int indentVal){  myIdentifier->unparse(indentVal);  cout<<"(";  myArgList->unparse(indentVal);  cout<<")"; }
void TrueNode::unparse(int indentVal){  cout<<"true"; }
void FalseNode::unparse(int indentVal){  cout<<"false"; }
void ArrayVarNode::unparse(int indentVal){  myIdentifier->unparse(indentVal);  cout<<"[";  myExpression->unparse(indentVal);  cout<<"]"; }
void AndNode::unparse(int indentVal){  if(!myLeft->isNull()){    cout << "(";    myLeft->unparse(indentVal);    cout << " && ";    myRight->unparse(indentVal);    cout << ")";    return;  }  myRight->unparse(indentVal); }
void ReturnNode::unparse(int indentVal){  doLineNum();  indent(indentVal);  cout<<"return";  if(!myReturnVal->isNull()){ cout << " ";   myReturnVal -> unparse(indentVal);  }  cout << ";" << endl; }
void IfNode::unparse(int indentVal){  doLineNum();  indent(indentVal);  cout<<"if (";  myExpression->unparse(indentVal);  cout<<")"<<endl;  if(!myThenStmt->isBlock()){    indentVal++;  }  myThenStmt->unparse(indentVal);  if(!myElseStmt->isNull()){    doLineNum();    if(!myThenStmt->isBlock()){      indentVal = indentVal - 1;    }    indent(indentVal);    cout<<"else"<<endl;    if(!myElseStmt->isBlock()){      indentVal = indentVal + 1;    }    myElseStmt->unparse(indentVal);  } }
void BlockNode::unparse(int indentVal){  doLineNum();  indent(indentVal);  cout<<"{"<<endl;  if(!myVarList->isNull()){ myVarList->unparse(indentVal+1);  }  myStmtList->unparse(indentVal+1);  doLineNum();  indent(indentVal);  cout<<"}"<<endl; }
void WhileNode::unparse(int indentVal){  doLineNum();  indent(indentVal);  cout<<"while (";  myExpression->unparse(indentVal);  cout<<")"<<endl;  if(!myStmt->isBlock()){    indentVal = indentVal + 1;  }  myStmt->unparse(indentVal); }
void VarListNode::unparse(int indentVal){  if(!myVarList->isNull()){    myVarList->unparse(indentVal);  }  myDecl->unparse(indentVal); }
void ProcCallNode::unparse(int indentVal){  doLineNum();  indent(indentVal);  myIdentifier->unparse(indentVal);  cout<<"(";  myArgList->unparse(indentVal);  cout<<");"<<endl; }
void ArrayDeclNode :: unparse( int indentVal ) {  doLineNum();  indent(indentVal);  myType -> unparse(indentVal);  myIdentifier -> unparse(indentVal);  cout << " <" <<myIdentifier->getSymbol()->offset<< "> ";  cout << "[";  myIntLit -> unparse(indentVal);  cout << "];"<< endl; }
void FunctionListNode :: unparse( int indentVal ){  myFunctionList -> unparse(indentVal);  myFunctionDecl -> unparse(indentVal); }
void StmtListNode :: unparse( int indentVal ){  myStmtList -> unparse(indentVal);  myStmt     -> unparse(indentVal); }
void AssignNode :: unparse( int indentVal ){  doLineNum();  indent(indentVal);  myTarget -> unparse( indentVal );  cout << " = ";  myExpression -> unparse( indentVal );  cout << ";" << endl; }
void PrintNode :: unparse( int indentVal ){  doLineNum();  indent(indentVal);  cout<<"print(";  myPrintList->unparse( indentVal );  cout<<");"<<endl; }
void PrintListNode :: unparse( int indentVal ){  if(!myPrintList->isNull()){    myPrintList->unparse( indentVal );    cout << ",";  }  myPrintItem->unparse( indentVal );  if (myPrintItem->nodeType==IntType) cout<<" <IntType>";  else if (myPrintItem->nodeType==BoolType) cout<<" <BoolType>";  else if (myPrintItem->nodeType==StringType) cout<<" <StringType>"; }
void CoutNode :: unparse( int indentVal ){  doLineNum();  indent(indentVal);  cout<<"cout";  myCoutList->unparse( indentVal );  cout<<";"<<endl; }
void CoutListNode :: unparse( int indentVal ){  myCoutList->unparse( indentVal );  cout << "<<";  myCoutItem->unparse( indentVal ); }
void ArithOpNode :: unparse( int indentVal ) {  cout << "(";  myLeft -> unparse(indentVal);  switch (myArithOp) { case PLUS  :  cout << " + ";  break; case MINUS :  cout << " - ";  break; case TIMES :  cout << " * ";  break; case SLASH :  cout << " / ";  break; default    :  assert(0);  }  myRight -> unparse(indentVal);  cout << ")"; }
void RelOpNode :: unparse(int indentVal ){  cout << "(";  myLeft -> unparse(indentVal);  switch (myRelOp) { case LT  :  cout << " < ";  break; case GT  :  cout << " > ";  break; case EQ  :  cout << " == "; break; case NEQ :  cout << " != "; break; case LEQ :  cout << " <= "; break; case GEQ :  cout << " >= "; break; default  : assert(0);  }  myRight -> unparse(indentVal);  cout << ")"; }
void NameVarNode :: unparse( int indentVal ){  myIdentifier -> unparse(indentVal); }
void IdentifierNode :: unparse( int indentVal ){  cout << myStringVal->c_str(); }
void TargetNode :: unparse(int indentVal ){  myIdentifier -> unparse(indentVal);  if(!myExpression->isNull()){    cout <<"[";    myExpression -> unparse(indentVal);    cout <<"]";  } }
void IntLiteralNode :: unparse( int indentVal ){  cout << myIntVal; }
// symbol.cc
#include "symbol.h" #include <string>
// implementation of Symbol class
// David Haltinner ******************************************************* // Symbol constructor: initialize Symbol to have given name // David Haltinner ******************************************************* Symbol::Symbol(string S)       : symbolName(S), symbolType(ErrorType), symbolKind(ErrorKind) {} // main.cc
/* * Description: * This is a compiler for the language zinc * * Usage: * $ p5 <source_file> * $ p5 -u <source_file> * $ p5 -R <source_file> * S p5 -u -R <source_file> * $ p5 -R -u <source_file> * * Input: * p5 takes between 1 and 3 arguments the last argument * must always be the source file to be compiled, which must end * in .z.  the flags -u and -R are optional. -u == unparse (or pretty * print info about the source file) and -R == Sethi Ullman Register * Allocation is to be used in code generation. * * Written by: * Shawn Gens and David Haltinner */
using namespace std; #include <iostream> #include <fstream>
#include "ast.h" #include "scanner.h"   // yyin is here
ASTnode * astRoot;     // root of AST
extern int  declErrors; extern int  typeErrors; bool SethiUllmanFlag; extern ofstream asmFile;
int main( int argc, char **argv ) {  // Check for correct usage (arguments)  if ( argc==1                                                         ||       argc==3 && (strcmp(argv[1],"-u")!=0&&strcmp(argv[1],"-R")!=0)   ||       argc==4 && ((strcmp(argv[1], "-u")!=0&&strcmp(argv[2], "-R")!=0)&&                  (strcmp(argv[1], "-R")!=0&&strcmp(argv[2], "-u")!=0))||       argc>4 ) {    cerr << "\nusage: " << argv[0] << " <source_file>"    <<endl;    cerr <<   "       " << argv[0] << " -u <source_file>" <<endl;    cerr <<   "       " << argv[0] << " -R <source_file>" <<endl;    cerr <<   "       " << argv[0] << " -u -R <source_file>" <<endl;    cerr <<   "       " << argv[0] << " -R -u <source_file>" <<endl;    cerr <<   "       options: -u==unparse, -R==SethiAllman register allocation"         <<endl<<endl;    return 1;  }
 bool unparse       = false;  SethiUllmanFlag    = false;  int  fileName      = 1;
 // Which flags (if any) are set?  if ( (argc==3||argc==4) && strcmp(argv[1],"-u")==0 ) {    unparse  = true;    fileName = 2;  }  if( (argc==3||argc==4) && strcmp(argv[1], "-R")==0 ) {    SethiUllmanFlag = true;    fileName        = 2;  }  if( argc==4 && strcmp(argv[2], "-R")==0 ) {    SethiUllmanFlag = true;    fileName        = 3;  }  if( argc==4 && strcmp(argv[2], "-u")==0 ) {    unparse  = true;    fileName = 3;  }
 // Now look at the source file  string file_name = argv[fileName];  string asmfile = file_name;  string ex = "s";  if (file_name.size() <= 2)  {        cerr << endl << argv[0] << ": " << argv[1]             << " does not have a \".z\" extension"             << endl << endl;        return 1;  }  if (file_name.substr(file_name.size()-2, 2) != ".z")  {        cerr << endl << argv[0] << ": " << argv[1]             << " does not have a \".z\" extension"             << endl << endl;        return 1;  }
 if ( (yyin = fopen(argv[fileName],"r")) == NULL ) {    cerr<<endl<<argv[0] << ": could not open " << argv[fileName] <<endl<<endl;    return 1;  }
 asmfile[asmfile.length()-1] = ex[0];  char afile[asmfile.length()];  for(unsigned int i=0; i<=asmfile.length(); i++){ afile[i] = asmfile[i];  }
 asmFile.open(afile);  if(asmFile.fail()){ cerr << endl << argv[0] << ": could not open " << asmfile <<endl<<endl; return 1;  }
 // Start compilation  extern int yyparse();  cout << "source file: " << argv[fileName] << endl;  cout << "...parse" << endl;
 if ( yyparse() == 0 ) {
   cout << "...name check" << endl;    astRoot->checkNames();    if (declErrors>0) {        string msg = "error";        if (declErrors>1) msg = msg + "s";        cerr << declErrors << " declaration/use " << msg << " found" << endl;        cerr << "Compilation aborted." << endl;        return 1;    }
   cout << "...type check" << endl;    astRoot->checkTypes();    if (typeErrors>0) {        string msg = "error";        if (typeErrors>1) msg = msg + "s";        cerr << typeErrors << " type " << msg << " found" << endl;        cerr << "Compilation aborted." << endl;        return 1;    }
   // The file made it to code generation    cout << "...emit code";    if( SethiUllmanFlag ) { // Sethi Ullman Flag has been set...tell the user cout << " using Sethi Ullman register allocation";    }    cout << endl;    astRoot->emitCode();
   if ( unparse ) { // The unparse flag is set...tell the user cout << "...unparse" << endl; astRoot->unparse();    }  }
 fclose(yyin);  return 0; } // test of some complex expressions using &&
int x(bool q, int z[], bool y[], int w){ y[w] = q;  //y[1] = true z[2] = 2;   // this is true if(q && 3 > 2 && true && true && (q || true) && (true && true)){ print("HERE", "\n"); // prints z[2] = z[2] + 4 - 1 - 3 + w / w; // z[2] = 3 print("z[2] is: ", z[2], "\n"); } return (3 + 8 + z[2]); }
int main(){ bool y[6]; int v[2]; bool q; int hi; v[2] = 0; q = 4 < 1; y[1] = true && true || false || true && q; //y[1] = true v[1] = x(true, v, y, 1); // v[1] = 14 print("v[1] ", v[1], " v[2] ", v[2], " y[1] ", y[1], "\n"); return 0; } .data .true: .asciiz "true" .false: .asciiz "false" .nl: .asciiz "\n" .text .globl  main
j.f: ##### ####### PROLOGUE ####### ##### subu $sp, $sp, 12 # ra, fp & locals sw $ra, 8($sp) sw $fp, 4($sp) addu $fp, $sp, 16 # set new fp #assignment li $t0, 3 sw $t0, -16($fp) #assignment lw $t0, 0($fp) lw $t1, -4($fp) add $t0, $t0, $t1 lw $t1, -16($fp) add $t0, $t0, $t1 sw $t0, -16($fp)
#return lw $t0, -16($fp) move $v0, $t0 j j.f..
j.f..: ##### ####### EPILOGUE ####### ##### lw $ra, -8($fp) # restore ra lw $fp, -12($fp) # restore fp addu $sp, $sp, 20 # Pop jr $ra
t.f: ##### ####### PROLOGUE ####### ##### subu $sp, $sp, 8 # registers ra & fp sw $ra, 4($sp) sw $fp, 0($sp) addu $fp, $sp, 16 # set new fp
t.f..: ##### ####### EPILOGUE ####### ##### lw $ra, -12($fp) # restore ra lw $fp, -16($fp) # restore fp addu $sp, $sp, 20 # Pop jr $ra
main: ##### ####### PROLOGUE ####### ##### subu $sp, $sp, 28 # ra, fp & locals sw $ra, 24($sp) sw $fp, 20($sp) addu $fp, $sp, 24 # set new fp #assignment lw $t0, -24($fp) li $t1, 3 li $t2, 3 mulo $t1, $t1, $t2 add $t0, $t0, $t1 sw $t0, -24($fp)
#return li $t0, 1 move $v0, $t0 j main..
main..: ##### ####### EPILOGUE ####### ##### lw $ra, 0($fp) # restore ra lw $fp, -4($fp) # restore fp addu $sp, $sp, 28 # Pop
li $v0, 10 syscall # program exit source file: OO/test.z ...parse ...name check ...type check ...code generation ...unparse   functionName<parameters:locals:frameSize>;   variableName<offset>     1: int  j <2:1:20> (     1:       int  x <0> ,     1:       int  y <4> )     1: {     2:    int  z <16> ;     3:    z = 3;     4:    z = ((x + y) + z);     5:    return z;     1: }     8: void t <3:0:20> (     8:       int  z <0> ,     8:       int  q <4> [],     8:       bool e <8> )     8: {     8: }    10: int  main <0:5:28> ()    10: {    11:    int  y <20> [4];    12:    int  x <24> ;    14:    y[1] = (((x + 3) + x) - (y[3] * 2));    17:    return 1;    10: }
******** p5/OO/typecheck.obj: Not a text file ********
source file: test.z ...parse ...name check ...type check ...unparse   functionName<parameters:locals:frameSize>;   variableName<offset>     1: int  j <2:1:20> (     1:       int  x <0> ,     1:       int  y <4> )     1: {     2:    int  z <16> ;     3:    z = 3;     4:    z = ((x + y) + z);     5:    return z;     1: }     8: void t <3:0:20> (     8:       int  z <0> ,     8:       int  q <4> [],     8:       bool e <8> )     8: {     8: }    10: int  main <0:5:28> ()    10: {    11:    int  y <20> [4];    12:    int  x <24> ;    14:    y[1] = (((x + 3) + x) - (y[3] * 2));    17:    return 1;    10: } ...emit code int j(int x, int y){ int z; z = 3; z = x + y + z; return z; }
void t(int z, int q[], bool e){}
int main(){ int y[4]; int x; //x = 2; x = x + 3 * 3; //y[3] = j(2, x); //t(x, y, true); return 1; }
******** p5/OO/namecheck.obj: Not a text file ********
.data .true: .asciiz "true" .false: .asciiz "false" .nl: .asciiz "\n" .text .globl  main
j.f: ##### ####### PROLOGUE ####### ##### subu $sp, $sp, 12 # ra, fp & locals sw $ra, 8($sp) sw $fp, 4($sp) addu $fp, $sp, 16 # set new fp #assignment li $t0, 3 sw $t0, -16($fp) #assignment lw $t0, -4($fp) lw $t1, 0($fp) add $t1, $t1, $t0 lw $t0, -16($fp) add $t1, $t1, $t0 sw $t1, -16($fp)
#return lw $t0, -16($fp) move $v0, $t0 j j.f..
j.f..: ##### ####### EPILOGUE ####### ##### lw $ra, -8($fp) # restore ra lw $fp, -12($fp) # restore fp addu $sp, $sp, 20 # Pop jr $ra
t.f: ##### ####### PROLOGUE ####### ##### subu $sp, $sp, 8 # registers ra & fp sw $ra, 4($sp) sw $fp, 0($sp) addu $fp, $sp, 16 # set new fp
t.f..: ##### ####### EPILOGUE ####### ##### lw $ra, -12($fp) # restore ra lw $fp, -16($fp) # restore fp addu $sp, $sp, 20 # Pop jr $ra
main: ##### ####### PROLOGUE ####### ##### subu $sp, $sp, 28 # ra, fp & locals sw $ra, 24($sp) sw $fp, 20($sp) addu $fp, $sp, 24 # set new fp #assignment li $t0, 3 li $t1, 3 mulo $t1, $t1, $t0 lw $t0, -24($fp) add $t0, $t0, $t1 sw $t0, -24($fp)
#return li $t0, 1 move $v0, $t0 j main..
main..: ##### ####### EPILOGUE ####### ##### lw $ra, 0($fp) # restore ra lw $fp, -4($fp) # restore fp addu $sp, $sp, 28 # Pop
li $v0, 10 syscall # program exit
******** p5/OO/z5: Not a text file ********
// message.h
#ifndef MESSAGE_GUARD #define MESSAGE_GUARD
#include <string> using namespace std;
void Error(int line, int col, string msg); void Warn (int line, int col, string msg); void InternalError(string msg);
// GLOBAL VARIABLE extern bool errorFlag;
#endif #! /bin/csh
# usage # zoc test
echo "p5" $1.z
./p5    $1.z if ( $status != 0 ) exit -1
echo "...peephole optimization" /home/perrie/spim/bin/copt  peephole.rules  <$1.s  >$1.S
echo "...assemble and execute" echo "/home/perrie/spim/bin/spim  -file  " $1".S"
/home/perrie/spim/bin/spim  -file  $1.S
echo "" echo "" echo "differences between" $1".s and" $1".S:" diff  $1.s  $1.S echo "" int x; //test global variables bool y; int w[2]; bool q[2];
int z(int i, bool b, int v[], bool n[]){ //tests functin calls int t; int h[2]; bool p[2]; bool m; h[1] = i; //local arrays h[0] = h[1] + 3 + v[0] / x; //mathematic operations with local arrays t = 1 + (x - i) / v[0] * v[1] - w[0] + w[1]; m = b && i != 6 || b && t <= 4; //boolean math with local variables p[1] = true; p[0] = p[1] && b && y && q[0] && q[1]; print(1,2,3, true, false,  "\n"); //a bunch of prints print("t is local and it is...", t, "\n"); print("m is local and it is ...", m, "\n"); print("p[1] is local and it is ...", p[1], "\n"); print("h[0] is local and it is ...", h[0], "\n"); print("i is a param and it is ...", i, "\n"); print("v[1] is a param and it is ...", v[1], "\n"); print("n[0] is a param and it is ...", n[0], "\n"); print("b is a param and it is ...", b, "\n"); print("x is global and it is ...", x, "\n"); print("y is global and it is ...", y, "\n"); print("w[0] is global and it is ...", w[0], "\n"); print("q[1] is global and it is ...", q[1], "\n"); return h[1]; }
int main(){ //math with global and local arrays and variabales, as well as a funtion call int try; int tArray[2]; tArray[0] = 1; tArray[1] = 9; x = 1 + 3 + 2; y = false; w[0] = x * x; w[1] = x / 5; q[0] = true; q[1] = false; try = z(w[1], y, w, q); try = z(tArray[1], y, tArray, q); return w[1]; } // int2str.cc
#include "int2str.h" #include <assert.h>
//David Haltinner ******************************************************* // IntToStr //   convert the given (non-negative) int to a String // David Haltinner ******************************************************* string IntToStr(int k) { int digit;  string tmp = "";
 assert(k >= 0);  if (k == 0) return("0");  while (k>0) {    digit = k % 10;    k = k / 10;    switch (digit) {    case 0:      tmp = "0" + tmp;      break;    case 1:      tmp = "1" + tmp;      break;    case 2:      tmp = "2" + tmp;      break;    case 3:      tmp = "3" + tmp;      break;    case 4:      tmp = "4" + tmp;      break;    case 5:      tmp = "5" + tmp;      break;    case 6:      tmp = "6" + tmp;      break;    case 7:      tmp = "7" + tmp;      break;    case 8:      tmp = "8" + tmp;      break;    case 9:      tmp = "9" + tmp;      break;    }  }  return(tmp); }
// symboltable.cc
#include <cassert> #include <list> #include <string> #include <iostream> #include <iomanip> #include "symbol.h" #include "symboltable.h"
// implementation of the SymbolTable class using a hash table
/* Assignment #1: * a) Do not modify functions Hash or Print * b) Implement functions Insert and Lookup */
// David Haltinner ====================================================== // Insert // David Haltinner ====================================================== // add the given symbol to the table // error if there is already a symbol with the same name
void SymbolTable::Insert(SymbolPtr sym) {  //error if Lookup(sym->symbolName)!=NULL  assert(Lookup(sym->symbolName) == NULL);
 // at this point, Lookup(sym->symbolName) == NULL  // i.e.  we have a guarantee that sym is not already in the symbol table  // software needs to call Lookup before calling Insert  // i.e.  duplicate names will never be in the symbol table
 // now, add sym to the symbol table // Hash the item int hashVal = Hash((sym->symbolName));
// Put it in the back of the bucket bucket[hashVal].push_back(sym); }
// David Haltinner ====================================================== // Lookup // David Haltinner ====================================================== // if there is a symbol with the given name in the table, return a //    pointer to that symbol; // otherwise, return NULL
SymbolPtr SymbolTable::Lookup(string name) { int hashVal = Hash(name); // Which list to look in list<SymbolPtr> L; // Pointer to the list list<SymbolPtr>::iterator i; // Iterator for the list SymbolPtr sym; // Pointer for examining items in list bool found = false; // Tells if item is found or not L = bucket[hashVal]; i = L.begin();
while( i != L.end()){ sym = *i; if(sym->symbolName == name){ found = true; // The item is found return sym; // Now stop looking } i++; }
return NULL; }
// David Haltinner ====================================================== // Hash // David Haltinner ====================================================== // hash function
int SymbolTable::Hash(string & S) {  int val = 0;  for (int j=0; j<int(S.length()); j++) val = (val << 3) + S[j];  if (val < 0) val = -val;  return(val % TABLESIZE); }
// David Haltinner ====================================================== // Print // David Haltinner ====================================================== // print the names of all the symbols, one per line
void SymbolTable::Print(ostream & out) {  SymbolPtr       sym;  list<SymbolPtr> L;  list<SymbolPtr>::iterator i;
 for (int k=0; k<TABLESIZE; k++) {    L = bucket[k];    i = L.begin();    while ( i != L.end() ) {      sym = *i;      out << sym->symbolName.c_str() << endl;      i++;    }  } } // int2str.h
#ifndef _INT2STR_H #define _INT2STR_H
using namespace std; #include <string>
string IntToStr( int k );
#endif #! /bin/csh
# usage # zcc test
echo "" echo "p5" $1.z
./p5 $1.z if ( $status != 0 ) exit -1
echo "...assemble and execute" echo "spim  -file  " $1".s"
/home/perrie/spim/bin/spim   -file   $1.s echo "" // emit.cc
using namespace std; #include "ast.h" #include "emit.h" #include "int2str.h" #include "message.h"
#include <iostream> #include <iomanip> #include <fstream> #include <string> #include <assert.h>
ofstream asmFile;
//David Haltinner ============================================================ // //                             Reg Routines // //David Haltinner ============================================================
// oops. should have 10 $t registers static int regInUse[8] = { 0,0,0,0,0,0,0,0 }; // 0 == free; 1 == in use static int nRegInUse = 0;
static int argRegInUse[4] = { 0,0,0,0 };      // 0 == free; 1 == in use static int nArgRegInUse = 0;
int getReg() {  int i;
 for (i=0; i<8 && regInUse[i]==1; i++) {};  if ( i==8 ) InternalError("emit: out of registers in getReg");
 regInUse[i] = 1;  nRegInUse++;  return i; }
void freeReg( int r ) {  if (r==30) {  return; }  assert( r>=0 && r<=7 );  regInUse[r] = 0;  nRegInUse--; }
static void emitOffsetSP    ( string opcode, int rD, int offset ) {  asmFile << "\t" << opcode << "\t" ;  asmFile << "$t"+IntToStr(rD) << ", " << IntToStr(offset) << "($sp)" <<endl;  asmFile.flush(); }
void saveRegs() {   if(nRegInUse>0) emit( "subu",  "$sp, $sp", IntToStr(nRegInUse*4) );   for (int i=0; i<8; i++) if(regInUse[i]==1) emitOffsetSP("sw", i, i*4 ); }
void restoreRegs() {   for (int i=0; i<8; i++) if(regInUse[i]==1) emitOffsetSP("lw", i, i*4 );   if(nRegInUse>0) emit( "addu",  "$sp, $sp", IntToStr(nRegInUse*4) ); }
int getArgReg() {  int i;
 for (i=0; i<4 && argRegInUse[i]==1; i++) {};  if ( i==4 ) InternalError("emit: out of registers in getArgReg");
 argRegInUse[i] = 1;  nArgRegInUse++;  return i; }
void freeArgReg( int r ) {  assert( r>=0 && r<=3 );  argRegInUse[r] = 0;  nArgRegInUse--; }
// David Haltinner =========================================================== // //                             Emit Routines // // David Haltinner ===========================================================
void emit( string opcode,           string arg1, string arg2, string arg3,           string comment ) {  asmFile << "\t" << opcode;
 if ( arg1 != "" ) { asmFile << "\t" << arg1; if ( arg2 != "" ) { asmFile << ", " << arg2; if ( arg3 != "" ) { asmFile << ", " << arg3; if ( comment != "" ) asmFile << "\t" << comment; } }  }
 asmFile<<endl;  asmFile.flush(); }
// David Haltinner ===========================================================
void emit( string opcode, int rD, string arg ) {  asmFile << "\t" << opcode << "\t";
 asmFile << "$t" << IntToStr(rD) << ", " << arg << endl;  asmFile.flush(); }
void emit( string opcode, string rD, int arg ) {  asmFile << "\t" << opcode << "\t";
 asmFile << rD << ", " << arg << endl;  asmFile.flush(); }
void emit( string opcode, int rD, int arg ) {  asmFile << "\t" << opcode << "\t";
 asmFile << "$t" << IntToStr(rD) << ", " << arg << endl;  asmFile.flush(); }
// David Haltinner ===========================================================
void emitOffset    ( string opcode, string arg1, int offset, string arg2, string comment ) {  asmFile << "\t" << opcode << "\t" ;
 string stringOffset = (offset==0) ? IntToStr(offset) : "-"+IntToStr(offset);  asmFile << arg1 << ", " << stringOffset << "(" << arg2 << ")";
 if (comment!="") asmFile << "\t" << comment;
 asmFile<<endl;  asmFile.flush(); }
void emitOffset    ( string opcode, int rD, int offset, string arg2, string comment ) {  asmFile << "\t" << opcode << "\t" ;
 string stringOffset = (offset==0) ? IntToStr(offset) : "-"+IntToStr(offset);  asmFile << "$t"+IntToStr(rD) << ", " << stringOffset << "(" << arg2 << ")";
 if (comment!="") asmFile << "\t" << comment;
 asmFile<<endl;  asmFile.flush(); }
// David Haltinner ===========================================================
void emitComment( string comment ) {  asmFile << "#" << comment << endl;  asmFile.flush(); }
void emitBlockComment( string comment ) {  asmFile << "\t#####"    << endl;  asmFile << "\t####### " << comment << " #######" << endl;  asmFile << "\t#####"    << endl;  asmFile.flush(); }
void emitEmptyLine() {  asmFile << endl;  asmFile.flush(); }
// David Haltinner ===========================================================
void emitLabel( string label ) {  asmFile << label << ":" << endl; }
// =================================== // Return a different label each time: //        .L0, .L1, .L2,    etc. // =================================== string NextLabel() {  static int currLabel = 0;
 string tmp = ".L" + IntToStr(currLabel++);  return(tmp); } // typecheck.cc #include "ast.h" #include "message.h" #include "symbol.h" #include "symboltable.h" #include "symlist.h" #include "scanner.h" #include "y.tab.h"
/* *  do type checking, i.e. find type errors * */
int typeErrors = 0;
void ProgramNode :: checkTypes() {  myFunctionList -> checkTypes(); }
void GlobalListNode :: checkTypes() {  return; }
void FunctionListNode :: checkTypes() {  myFunctionList -> checkTypes();  myFunctionDecl -> checkTypes(); }
void FunctionDeclNode :: checkTypes() {  myStmtList -> checkTypes(); }
void VariableDeclNode :: checkTypes() {  return; }
void ArrayDeclNode :: checkTypes() {  return; }
void TypeIntNode :: checkTypes() {  return; }
void TypeBoolNode :: checkTypes() {  return; }
void ParametersNode :: checkTypes() {   return; }
void ParamListNode :: checkTypes() {   return; }
void ArgListNode :: checkTypes() {   myArgList -> checkTypes();   myExpression -> checkTypes(); }
void ParamValNode :: checkTypes() {  return; }
void ParamArrayNode :: checkTypes() {  return; }
void VarListNode :: checkTypes() {  myVarList -> checkTypes();  myDecl -> checkTypes(); }
void StmtListNode :: checkTypes() {  myStmtList -> checkTypes();  myStmt -> checkTypes(); }
void AssignNode :: checkTypes() {  bool errors = false;  myTarget -> checkTypes();  myExpression -> checkTypes();  Symbol * s = myTarget->getID()->getSymbol();  if((s->symbolKind == ArrayKind || s->symbolKind == ArrayParamKind) && myTarget->getExp()->isNull()){ typeErrors++; string msg = "assignment: LHS name is an array name"; Error(line, column, msg); errors = true;  }  if(s->symbolKind == FnKind){ typeErrors++; string msg = "assignment: LHS name is a function name"; Error(line, column, msg); errors = true;  }  if(myExpression->isName()){ s = myExpression->getID()->getSymbol();   if(s->symbolKind == FnKind){ typeErrors++; string msg = "assignment: RHS name is a function name"; Error(line, column, msg); errors = true;   }   else if(s->symbolKind == ArrayKind || s->symbolKind == ArrayParamKind){ typeErrors++; string msg = "assignment: RHS name is an array name"; Error(line, column, msg); errors = true;   }  }  if(myExpression-> nodeType != myTarget->nodeType && !errors){ typeErrors++; string msg = "assignment: LHS type != RHS type"; Error(line, column, msg);  } }
void IfNode :: checkTypes() {  myExpression -> checkTypes();  myThenStmt -> checkTypes();  myElseStmt -> checkTypes(); }
void WhileNode :: checkTypes() {  myExpression -> checkTypes();  myStmt -> checkTypes(); }
void BlockNode :: checkTypes() {  myStmtList -> checkTypes();  return; }
void ReturnNode :: checkTypes() {  myReturnVal -> checkTypes();  nodeType = myReturnVal -> nodeType; }
void ProcCallNode :: checkTypes() {  myArgList->checkTypes(); }
void PrintNode :: checkTypes() {  myPrintList -> checkTypes(); }
void PrintListNode :: checkTypes() {  myPrintList -> checkTypes();  myPrintItem -> checkTypes();  if(myPrintItem->nodeType == VoidType){ typeErrors++; myPrintItem->nodeType = ErrorType; string msg = "print expression is void type"; Error(line, column, msg);  } }
void OrNode :: checkTypes() {  myLeft->checkTypes();  myRight->checkTypes();  nodeType = myRight -> nodeType;  if(!myLeft->isNull() && !myRight->isNull()){ if(myLeft->nodeType != BoolType){ typeErrors++; string msg = "left  operand of || is not bool"; Error(line, column, msg);   } if(myRight->nodeType != BoolType){ typeErrors++; string msg = "right operand of || is not bool"; Error(line, column, msg);   } nodeType = BoolType;  } }
void AndNode :: checkTypes() {  myLeft->checkTypes();  myRight->checkTypes();  nodeType = myRight->nodeType;  if(!myLeft->isNull()&&!myRight->isNull()){ if(myLeft->nodeType != BoolType){ typeErrors++; string msg = "left  operand of && is not bool"; Error(line, column, msg);   }
if(myRight->nodeType != BoolType){ typeErrors++; string msg = "right operand of && is not bool"; Error(line, column, msg);   } nodeType = BoolType;  } }
void RelOpNode :: checkTypes() {  myLeft->checkTypes();  myRight->checkTypes();  nodeType = myRight->nodeType;  if(!myLeft->isNull()&&!myRight->isNull()){ if(myLeft->nodeType != IntType){ typeErrors++; string msg = "left  operand of"; switch(myRelOp){ case LT: msg = msg + "  < "; break; case GT: msg = msg + "  > "; break; case LEQ: msg = msg + " <= "; break; case GEQ: msg = msg + " >= "; break; case EQ: msg = msg + " == "; break; case NEQ: msg = msg + " != "; break; } msg = msg + "is not int"; Error(line, column, msg);   } if(myRight->nodeType != IntType){ typeErrors++; string msg = "right operand of"; switch(myRelOp){ case LT: msg = msg + "  < "; break; case GT: msg = msg + "  > "; break; case LEQ: msg = msg + " <= "; break; case GEQ: msg = msg + " >= "; break; case EQ: msg = msg + " == "; break; case NEQ: msg = msg + " != "; break; } msg = msg + "is not int"; Error(line, column, msg); } nodeType = BoolType;  } }
void ArithOpNode :: checkTypes() {  myLeft->checkTypes();  myRight->checkTypes();  nodeType = myRight->nodeType;  if(!myLeft->isNull()&&!myRight->isNull()){   if(myLeft->nodeType != IntType){ typeErrors++; string msg = "left  operand of "; switch(myArithOp){ case PLUS: msg = msg + " + "; break; case MINUS: msg = msg + " - "; break; case TIMES: msg = msg + " * "; break; case SLASH: msg = msg + " / "; break; } msg = msg + "is not int"; Error(line, column, msg);   }   if(myRight->nodeType != IntType){ typeErrors++; string msg = "right operand of "; switch(myArithOp){ case PLUS: msg = msg + " + "; break; case MINUS: msg = msg + " - "; break; case TIMES: msg = msg + " * "; break; case SLASH: msg = msg + " / "; break; } msg = msg + "is not int"; Error(line, column, msg);   } nodeType = IntType;  } }
void NameVarNode :: checkTypes() {  myIdentifier -> checkTypes();  nodeType = myIdentifier->nodeType; }
void ArrayVarNode :: checkTypes() {  myIdentifier -> checkTypes();  nodeType = myIdentifier->nodeType;
 myExpression -> checkTypes(); }
void FnCallNode :: checkTypes() {  myIdentifier->checkTypes();  nodeType = (myIdentifier->getSymbol())->symbolType;  myArgList->checkTypes(); }
void TrueNode :: checkTypes() { nodeType = BoolType; } void FalseNode :: checkTypes() { nodeType = BoolType; } void IntLiteralNode :: checkTypes() { nodeType = IntType; } void TargetNode :: checkTypes() {  Symbol * s = myIdentifier->getSymbol();  nodeType = s->symbolType; } void IdentifierNode :: checkTypes() { nodeType = mySymbolTableEntry->symbolType; } void StringLiteralNode :: checkTypes() { nodeType = StringType; } // more tests of booleans
bool y;
int main(){ bool x; x = false; //x = true; y = (x && true) || (false && x); // y = false print("X is ", x, "\n"); // false print("Y is ", y, "\n"); // false
// fails if(false || y && true || x){ print("Its true", "\n"); } else{ int i; i = 0; while(i < 3 || x){ print("Its false", "\n"); i = i + 1; } } } // emit.h
#ifndef EMIT_H_ #define EMIT_H_
#include <iostream> #include <iomanip> #include <fstream> #include <string> using namespace std;
int   getReg(); void freeReg( int r ); int   getArgReg(); void freeArgReg( int r );
void saveRegs(); void restoreRegs();
// David Haltinner ============================================================
void emit( string opcode,           string arg1="", string arg2="", string arg3="", string comment="" );
void emit( string opcode, int    rD, string arg ); void emit( string opcode, string rD, int    arg ); void emit( string opcode, int    rD, int    arg );
// David Haltinner ============================================================
void emitOffset    ( string opcode, string arg1, int offset, string arg2, string comment="" ); void emitOffset    ( string opcode, int rD, int offset, string arg2, string comment="" );
// David Haltinner ============================================================
void emitLabel( string label ); void emitComment     ( string comment ); void emitBlockComment( string comment ); void emitEmptyLine ();
// David Haltinner ============================================================
string NextLabel();
#endif // test of assignment of functions and while
bool t(bool y){ bool z; // z is true // y is true z = y || y && false; print(z, "\n", y, "\n"); return true; }
int main(){ int x; x = 3; while(x > 0){ bool z; print("Test: ", x, "\n"); z = t(true); // z is true print("t returns: ", z, "\n"); x = x - 1; } return 1; } // ast.cc
#include "symbol.h" #include "ast.h"
ProgramNode :: ProgramNode(GlobalListNode*g, FunctionListNode*f, int l, int c)            :  ASTnode(l,c),  myGlobalList(g), myFunctionList(f)            {}
GlobalListNode :: GlobalListNode(GlobalListNode*g, DeclNode*v, int l, int c)               :  ASTnode(l,c),  myGlobalList(g), myDecl(v)               {}
FunctionListNode       :: FunctionListNode(FunctionListNode*f, FunctionDeclNode*d, int l, int c)       :  ASTnode(l,c),  myFunctionList(f), myFunctionDecl(d)       {}
FunctionDeclNode        :: FunctionDeclNode(TypeNode*t, IdentifierNode*i, ParametersNode*p,                            VarListNode*v, StmtListNode*s, int l, int c)        :  ASTnode(l,c), myType(t), myIdentifier(i), myParameters(p),                         myVarList(v), myStmtList(s)        {}
TypeNode :: TypeNode(int l, int c) : ASTnode(l,c) {}
TypeIntNode  :: TypeIntNode (int l, int c) : TypeNode(l,c) {} TypeBoolNode :: TypeBoolNode(int l, int c) : TypeNode(l,c) {}
DeclNode :: DeclNode(int l, int c) : ASTnode(l,c) {}
VariableDeclNode :: VariableDeclNode(TypeNode *t, IdentifierNode *i, int l, int c)                 :  DeclNode(l,c), myType(t), myIdentifier(i)                 {}
ArrayDeclNode     :: ArrayDeclNode(TypeNode*t, IdentifierNode*i, ExpressionNode*n, int l,int c)     :  DeclNode(l,c), myType(t), myIdentifier(i), myIntLit(n)     {}
ParametersNode :: ParametersNode(ParamListNode* p, int l, int c)               :  ASTnode(l,c), myParamList(p)               {}
ParamListNode :: ParamListNode(ParamListNode* p, ParamNode* n, int l, int c)              :  ASTnode(l,c), myParamList(p), myParam(n)              {}
ArgListNode :: ArgListNode(ArgListNode *a, ExpressionNode *e, int l, int c)            :  ASTnode(l,c),  myArgList(a),   myExpression(e)            {}
ParamNode :: ParamNode(int l, int c) :  ASTnode(l,c) {}
ParamValNode :: ParamValNode(TypeNode* t, IdentifierNode* i, int l, int c)             :  ParamNode(l,c), myType(t),   myIdentifier(i)             {}
ParamArrayNode :: ParamArrayNode(TypeNode* t, IdentifierNode* i, int l,int c)               :  ParamNode(l,c),   myType(t),   myIdentifier(i)               {}
VarListNode :: VarListNode(VarListNode *v, DeclNode *d, int l, int c)            :  ASTnode(l,c),  myVarList(v),   myDecl(d)            {}
StmtListNode :: StmtListNode(StmtListNode *s, StmtNode *n, int l, int c)             :  ASTnode(l,c),   myStmtList(s),   myStmt(n)             {}
StmtNode :: StmtNode(int l, int c) : ASTnode(l,c) {}
AssignNode :: AssignNode(TargetNode  *t, ExpressionNode *e, int l, int c)           :  StmtNode(l,c), myTarget(t),   myExpression(e)           {}
IfNode :: IfNode(ExpressionNode *ex, StmtNode *t, StmtNode *e, int l, int c)       :  StmtNode(l,c), myExpression(ex), myThenStmt(t), myElseStmt(e)       {}
WhileNode :: WhileNode(ExpressionNode *e, StmtNode *s, int l, int c)          :  StmtNode(l,c), myExpression(e), myStmt(s)          {}
BlockNode :: BlockNode( VarListNode  *v, StmtListNode *s, int l, int c)          :  StmtNode(l,c), myVarList(v),   myStmtList(s)          {}
ReturnNode :: ReturnNode(ExpressionNode *e, int l,int c)           :  StmtNode(l,c), myReturnVal(e)           {}
ProcCallNode :: ProcCallNode(IdentifierNode*i, ArgListNode*a, int l, int c)             :  StmtNode(l,c), myIdentifier(i),  myArgList(a)             {}
PrintNode :: PrintNode(PrintListNode *p, int l, int c)          :  StmtNode(l,c), myPrintList(p)          {}
CoutNode :: CoutNode(CoutListNode *p, int l, int c) :  StmtNode(l,c), myCoutList(p) {}
PrintListNode :: PrintListNode(PrintListNode *p, PrintItemNode *i, int l, int c)              :  ASTnode(l,c), myPrintList(p), myPrintItem(i)              {}
CoutListNode :: CoutListNode(CoutListNode *p, PrintItemNode *i, int l, int c)     :  ASTnode(l,c), myCoutList(p), myCoutItem(i)     {}
PrintItemNode :: PrintItemNode(int l, int c) : ASTnode(l,c) {}
ExpressionNode :: ExpressionNode(int l, int c) : PrintItemNode(l,c) {}
OrNode :: OrNode(ExpressionNode *e1, ExpressionNode *e2, int l,int c)           :  ExpressionNode(l,c), myLeft(e1), myRight(e2)           {}
AndNode :: AndNode(ExpressionNode *e1, ExpressionNode *e2, int l,int c)           :  ExpressionNode(l,c), myLeft(e1), myRight(e2)           {}
RelOpNode :: RelOpNode(int o, ExpressionNode *e1, ExpressionNode *e2, int l,int c)          :  ExpressionNode(l,c), myRelOp(o), myLeft(e1), myRight(e2)          {}
ArithOpNode :: ArithOpNode                    (int o,ExpressionNode *e1,ExpressionNode *e2, int l,int c)            :  ExpressionNode(l,c), myArithOp(o), myLeft(e1), myRight(e2)            {}
TrueNode  :: TrueNode (int l, int c) : ExpressionNode(l,c) {} FalseNode :: FalseNode(int l, int c) : ExpressionNode(l,c) {}
NameVarNode :: NameVarNode( IdentifierNode *n, int l, int c)            :  ExpressionNode(l,c),  myIdentifier(n)            {}
ArrayVarNode :: ArrayVarNode( IdentifierNode *n, ExpressionNode *e, int l, int c)             :  ExpressionNode(l,c),  myIdentifier(n), myExpression(e)             {}
FnCallNode :: FnCallNode(IdentifierNode *i, ArgListNode *a, int l, int c)           :  ExpressionNode(l,c),  myIdentifier(i), myArgList(a)           {}
IntLiteralNode :: IntLiteralNode(int n, int l, int c)               :  ExpressionNode(l,c)               { myIntVal=n; }
TargetNode :: TargetNode(IdentifierNode *i, ExpressionNode *e, int l, int c)           :  ASTnode(l,c), myIdentifier(i), myExpression(e)           {}
IdentifierNode :: IdentifierNode(string *s, int l, int c)               :  ASTnode(l,c),  myStringVal(s)               {}
StringLiteralNode :: StringLiteralNode(string *s, int l, int c)                  :  PrintItemNode(l,c),  myStringVal(s)                  {} // test of global arrays and while loops
int x[3]; bool y[3];
void fill(){ int j[3]; bool k[3]; int i; i = 0; while(i < 3){ j[i] = i; x[i] = j[i]; // 0, 1 y[i] = true; k[i] = y[i]; // true print("k[", i, "] is ", k[i], "\n"); print("j[", i, "] is ", j[i], "\n"); i = i + 1; } }
void printItems(){ int i; i = 0; while(i < 3){ print("y[", i, "] is ", y[i], "\n"); print("x[", i, "] is ", x[i], "\n"); i = i + 1; } }
int main(){ fill(); printItems(); return 1; } #!/bin/sh
for i in 1 2 3 4 5 6 7 do echo "****************" zcc "t$i" echo "****************" done for i in 1 2 3 do echo "****************" zcc "test$i" echo "****************" done echo "Printing Big and Bad" echo "" echo "*************" echo "Big" zcc eBig echo "*************" echo "Bad" zcc eBad echo "*************"
******** p5/z5: Not a text file ********
// This is a test to use all 8 registers
int main(){ int x; int y; int z; x = 1; y = 2; z = 3;
// Lets use all of the registers x = x + x * (3 + 4 * (z + 3 * (4 * 1))); // Print the value 64 print("X is ", x, " and it uses a lot of registers"); print("\n"); } // This is a test to run out of registers
int main(){ int x; int y; int z; x = 1; z = 3; // Now lets break the compiler x = x - x / (3 - 4 / (z - 3 / (4 - 4 / 1))); } // symlist.cc
#include "message.h" #include "symlist.h"
SymTableList::SymTableList() {  symTableList = new list<PSymbolTable>(); }
SymTableList::~SymTableList() {  delete symTableList; }
void SymTableList::push(PSymbolTable v) {  symTableList->push_front(v); } PSymbolTable SymTableList::pop() {  PSymbolTable p=symTableList->front();  symTableList->pop_front();  return p; } PSymbolTable SymTableList::top() {  return symTableList->front(); } SymbolPtr SymTableList::lookUp(string id) {  list<PSymbolTable>::iterator i;  for (i=symTableList->begin(); i != symTableList->end(); i++) {    SymbolPtr p=(*i)->Lookup(id);    if (p!=NULL) return p;  }  return NULL; }
1 note · View note
rainbowmod · 6 years ago
Link
Bloom: Finally.... Maid, I need you to arrange a room for a baby. I have a child coming. Other Maid go out and buy the supplies. You Enscripter I need you to write two letters for me. One to my father and One to Queen Charlotte. Guard I want my generals to meet with me within the hour. We have business to discuss. Does everyone understand me?
Hope: I-I don't know I... I'm sorry.
Chariot: Easy fix. All I need is a blindfold and headphones. I'll be back. *She leaves you and Hope alone. She goes to Pip* Sweetheart do you have a minute?
76K notes · View notes
deathandrenegades · 8 years ago
Text
Masterlist
updated 5.8.2020
SPN
Tumblr media
Sunk (one shot) - here
Enscripted (Dean x Reader series) - Part 1 Part 2 Part 3 Part 4 Part 5 Part 6 Part 7 Part 8
Royalty Burns (Dean x Reader series) - Part 1 Part 2 Part 3 Part 4 Part 5
Middle of the night (Dean x Reader Imagine NSFW) - here
Staged (Jensen x Reader drabble) - here
Tension (Dean x Reader series NSFW) - Part 1 Part 2
Dean Visits You at Work (Dean x Reader imagine) - here
Down for Whatever (Dean x Reader drabble) - here
The Backseat (Dean x Reader x Sam NSFW) - here
5 Years Later (Dean x Reader NSFW) - here
JOKER
Tumblr media
Split at the Seams (drabble Series) - Part 1 Part 2 Part 3 Part 4 Part 5 Part 6 Part 7 Part 8 Part 9 Part 10
MARVEL
Tumblr media
Awkward (one shot) - here
Determined (Bucky x Reader drabble) - here
Unable to Sleep (Bucky x Reader Imagine) - here
Middle of the night (Bucky x Reader Imagine) - here
Operation Foxtrot (Bucky x Reader series) - Part 1 Part 2 Part 3 Part 4 Part 5 Part 6 Part 7 
The L Word (Bucky x Reader series NSFW) - Part 1 Part 2 Part 3 Part 4 Part 5 
Bones (Reaper!Bucky x reader one shot) - here
Halloween Night (Drabble NSFW) - here
Personal (Bucky x Reader NSFW) - here
Just the Two of Us (Steve x Reader NSFW) - here
Bloodshot (Bucky x Reader one shot) - here
Later (Bucky x Reader NSFW) - here
Bruised (Bucky x Reader one shot) - here
1k writing challenge
569 notes · View notes