NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

struct node {
int data;
char first[10];
char second[10];
struct node *next;
};
struct stack {
int pop;
struct stack *next;
};
struct stack *new; // global tanımlı bir stack dügümü global olma sebebi recursive fonksiyon dolasıyla her noktadan degistirebilmek.

void printStack(struct stack*); //Stack yaziyor.
void insertList(struct node**); //File'dan okuma yapıp dügüm olusturuyor. (struct node)
int ff(struct node*); //Begin Main'in yerini return ediyor. (Mesela 8. satırı return ediyor) bu sayede baslangıc noktası bulunuyor.
int trans(struct node*, int); //ff fonksiyonu return ettikten sonra gönderilen degerin bir sonraki dügümünü bulup o degerler üstünde recursive olarak islemler yapıyor.ff gibi deger döndürüp kendini tekrar calıstırıyor.
int Push(struct stack**, struct node*, char[], int); //eger call görülürse push yapıyor ve o degeri kaydediyor. ve o call fonksiyonunun ilk baslama noktası bulunup (BEGİN func1) gibi return ediliyor. tekrar trans fonksiyonu calısıyor.
int Pop(struct stack**); //eger end görülürse pop yapıp en son degeri siliyor ve o degeri return ediyor.tekrar trans fonksiyonu calısıyor

int main() {
int temp;
struct node *list = NULL;
insertList(&list);

temp = trans(list, ff(list));
while (temp != 0) {
temp = trans(list, temp);
}


printf("n---END---n");
system("PAUSE");
return 0;
}

void printStack(struct stack *start) { // Sadece stack yazıyor.

printf("Stack = ");
while(start!=NULL){
printf("%d ", start->pop);
start = start->next;
}
printf("n");

}
//islemler burda baslıyor.
int trans(struct node *start, int sort) {
struct stack *new_stack = NULL;
struct node *new_node = start;
int temp;
while (new_node->next->data != sort) {
new_node = new_node->next;
}

if (strcmp(new_node->first, "CALL") == 0) {
printf("%dt", new_node->data); // call icin print
return Push(&new, start, new_node->second, new_node->data);
}
else if (strcmp(new_node->first, "EXECUTE") == 0) {
printf("%dn", new_node->data); //execute icin print
return new_node->data;
}
else if (strcmp(new_node->first, "END") == 0) {
printf("%dt", new_node->data); // End görürse o satırı print ediyor
temp = Pop(&new);
if (temp != -1)
return temp;

else
return 0;
}
}


int Push(struct stack **new_stack, struct node *new_node, char second[], int x) {
int temp;
struct stack *newp;
newp = (struct stack *) malloc(sizeof(struct stack));
while (new_node != NULL) {

if (strcmp(new_node->second, second) == 0 && strcmp(new_node->first, "BEGIN") == 0) {
temp = new_node->data;

}
new_node = new_node->next;
}
if (newp == NULL)
printf("Cannot allocate memory!n");
else {
newp->pop = x;
newp->next = *new_stack;
*new_stack = newp;
}


printStack(*new_stack);
printf("%dn", temp); // begin noktasını print ediyor.
return temp;
}

int Pop(struct stack **start) {
int value;
struct stack * temp = NULL;
if (*start == NULL)
return -1;
temp = (*start)->next;
value = (*start)->pop;
free(*start);
*start = temp;
printStack(new);
return value;

}



// okuma fonksiyonu

void insertList(struct node **start) {
FILE *ptr;
ptr = fopen("code.prg", "r");
if (ptr == NULL) {
printf("File does not opened !!");
}
while (!feof(ptr)) {

struct node *new_node = (struct node *) malloc(sizeof(struct node));
fscanf(ptr, "%d %s", &new_node->data, new_node->first);
if (strcmp(new_node->first, "BEGIN") == 0 || strcmp(new_node->first, "CALL") == 0) {
fscanf(ptr, "%s", new_node->second);
}
new_node->next = (*start);
(*start) = new_node;
//printList(new_node);
}
fclose(ptr);
}
// ilk begin ve main in yerini bulan fonksiyon sadece bir defa calısıyor.
int ff(struct node *start) {
while (start != NULL) {
if (strcmp(start->first, "BEGIN") == 0 && strcmp(start->second, "Main") == 0) {
printf("%dn", start->data); // İlk basladıgı yeri yazan printf
return start->data;
}
start = start->next;
}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.