Skip to main content

Posts

Showing posts with the label SPCC

Lex - YACC

Try your hands on Lex Tools using C. Store the following code with desired filename having extension .l (dot L) Use Ubuntu operating system for running the code at ease. Code to check whether given number is Positive or Negative . %{ int p=0, n=0,pf=0,nf=0; %} %% [0-9]+ {p++;} -[0-9]+ {n++;} [0-9]*.[0-9]+ {pf++;} -[0-9]*.[0-9]+ {nf++;} %% main() { printf("Enter the data\t"); yylex(); printf("The positive Number %d \n",p); printf("The Positive Float %d \n",pf); printf("The Negative Number %d \n",n); printf("The Negative Float %d \n",nf); } Commands in terminal- lex filename .l gcc lex.yy.c -ll ./a.out

Macro Pass 1 and Pass 2

Hello, I presumed that you are aware of various databases needed for the Pass 1 &2. Please provide a following with the input file macroinput.txt I request you to post the screenshot of the output. import java.util.*; import java.io.*; class MntTuple { String name; int index; MntTuple(String s, int i) { name = s; index = i; } public String toString() { return("[" + name + ", " + index + "]"); } } class MacroProcessor { static List<MntTuple> mnt; static List<String> mdt; static int mntc; static int mdtc; static int mdtp; static BufferedReader input; static List<List <String>> ala; static Map<String, Integer> ala_macro_binding; public static void main(String args[]) throws Exception { initializeTables(); System.out.println("===== PASS 1 =====\n"); pass1(); System.out.println("\n===== PASS 2 =====\n"); pass2(); } static void pas...

Absolute Loader

Hello, We will now code for absolute loader scheme. For that, you have to give input code which is stored in SAMPLE_TEC.TXT When asked for Object File Name, please give the name stored in file SAMPLE_TEC.TXT. (i.e. TECPGM) You are encouraged to post the screenshot of the output of the program in comment section. import java.io.*; import java.io.RandomAccessFile.*; import java.lang.*; class absolute { String s,prog_name,obj_name,staddr; long d=0; int i,j,staddr1; //char[] staddr=new char[30]; void display() { try { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("\nEnter the program name : "); prog_name=br.readLine(); File f=new File("E:/sample_tec.txt"); RandomAccessFile fr=new RandomAccessFile(f,"r"); long size=fr.length(); if(d<size) { s=fr.readLine(); if(s.charAt(0)=='H') { obj_name=s.substring(2,8); System.out.println("Object Program Name From File : "+obj...

MACRO DATABASE

Great to know that you are curious about the databases used in the MACRO Pass1 and Pass2. Here we Go.!!!!! Pass 1: Databases Source Program Output of Source Program to be fed to Pass 2 Macro Definition Table (MDT)- Stores Macro Definitions Macro Name Table(MNT) - Stores the Macro Name that are defined in the Program Macro Definition Table Counter (MDTC) - Indicates next available entry in MDT Macro Name Table Counter (MNTC) - Indicates next available entry in MNT Argument List Array (ALA)-  Stores the index markers for dummy arguments Pass 2: Databases Input Source Program Expanded Source Code i.e  Output for Assembler  Macro Definition Table (MDT)- Created and Maintained by Pass 1 Macro Name Table(MNT) -  Created and Maintained by Pass 1  Macro Definition Table Pointer (MDTP) - Indicate next line used in Expansion. Arguments List Arrays (ALA)- Substitutes arguments for index markers. Example       ...

First and Follow

You are encouraged to post screenshots of output in comment section. #include<stdio.h> #include<ctype.h> char a[8][8]; struct firTab {     int n;     char firT[5]; }; struct folTab {     int n;     char folT[5]; }; struct folTab follow[5]; struct firTab first[5]; int col; void findFirst(char,char); void findFollow(char,char); void folTabOperation(char,char); void firTabOperation(char,char); void main() {     int i,j,c=0,cnt=0,n;     char ip;     char b[8];     printf("\nFIRST AND FOLLOW SET \n\nenter number of productions (in format A->B+T)\n");     scanf("%d",&n);     printf("enter the productions \n");     for(i=0;i<n;i++)     {     scanf("%s",&a[i]);      }     fo...

First Pass of an Assembler

Here is the code for First Pass of an Assembler. You are encouraged to post the screenshot of the output in comment section. #include<stdio.h> #include<string.h> int main (void) { char name[8][8],value[8][4]; inti,j,l,len,k=0,val=-4,m=0; char l1[8][6],l4[8][6]; int l2[8],l3[8]; char c1[8][6]={{"ABCD"},{"NULL"},{"NULL"},{"NULL"},{"NULL"},{"FOUR"},{"TEMP"},{"NULL"}}; char c2[8][6]={{"START"},{"USING"},{"L"},{"A"},{"ST"},{"DC"},{"DC"},{"END"}}; char c3[8][6]={{"0"},{"*"},{"1"},{"1"},{"1"},{"F4"},{"1F"},{"NULL"}}; char c4[8][6]={{"NULL"},{"15"},{"FOUR"},{"=F5"},{"TEMP"},{"NULL"},{"NULL"},{"NULL"}}; char mot[8][8]={"L",...