Created
May 9, 2022 02:34
-
-
Save hakxcore/6ea1307e49555ea516481e17e58ff65c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## input.txt | |
| #define PI 3.14 | |
| #define p(y) y+y | |
| void main(){ | |
| int a ; | |
| int PI ; | |
| a= PI ; | |
| int b; | |
| b= p(y) ; | |
| } | |
| ## Macro_prac.java | |
| import java.io.*; | |
| public class Macro_prac { | |
| String cur; | |
| String[][] macro_arr; | |
| int arrindex=0,strpt=0; | |
| boolean ind; | |
| String sep(){ | |
| String temp=""; | |
| int i=strpt; | |
| while((i<cur.length()) && (cur.charAt(i) != ' ')){ | |
| temp=temp+cur.charAt(i); | |
| i++; | |
| } | |
| strpt=++i; | |
| return temp; | |
| } | |
| void arr_setter(String var,String val){ | |
| macro_arr[arrindex][0]=var; | |
| macro_arr[arrindex][1]=val; | |
| } | |
| public static void main(String[] args) { | |
| FileReader in; | |
| FileWriter out; | |
| String var,val; | |
| String temp=""; | |
| try { | |
| in = new FileReader("input.txt"); | |
| BufferedReader br=new BufferedReader(in); | |
| out = new FileWriter("ouput.txt"); | |
| BufferedWriter bw=new BufferedWriter(out); | |
| Macro_prac ob=new Macro_prac(); | |
| ob.macro_arr=new String[10][2]; | |
| ob.cur=br.readLine(); | |
| while(ob.cur != null){ | |
| while(ob.strpt <= ob.cur.length()){ | |
| ob.ind=true; | |
| temp=ob.sep(); | |
| if(temp.equals("#define")){ | |
| var=ob.sep(); | |
| val=ob.sep(); | |
| ob.arr_setter(var, val); | |
| ob.arrindex++; | |
| } | |
| else{ | |
| for(int i=0;i<=ob.arrindex;i++){ | |
| if(temp.equals(ob.macro_arr[i][0])){ | |
| out.write(ob.macro_arr[i][1]); | |
| if(ob.strpt<ob.cur.length()){ | |
| out.write(" "); | |
| } | |
| else{ | |
| out.write("\n"); | |
| } | |
| ob.ind=false; | |
| } | |
| } | |
| if(ob.ind){ | |
| out.write(temp); | |
| if(ob.strpt<ob.cur.length()){ | |
| out.write(" "); | |
| } | |
| else{ | |
| out.write("\n"); | |
| } | |
| } | |
| } | |
| } | |
| ob.strpt=0; | |
| ob.cur=br.readLine(); | |
| } | |
| br.close(); | |
| bw.close(); | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| } | |
| ## Output.txt | |
| void main(){ | |
| int a ; | |
| int 3.14 ; | |
| a= 3.14 ; | |
| int b; | |
| b= y+y ; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment