// additional functionality of power right associative
grammar Exp;
options{
k=2;
}
/* This will be the entry point of our parser. */
eval returns [double value]
: additionExp{$value=$additionExp.value; System.out.println($value);}
;
/* Addition and subtraction have the lowest precedence. */
additionExp returns [double value]
: m1=multiplyExp {$value=$m1.value;}
( '+' m2=multiplyExp {$value+=$m2.value;}
| '-' m2=multiplyExp {$value-=$m2.value;}
)*
;
/* Multiplication and division have a higher precedence. */
multiplyExp returns [double value]
: a1=restExp {$value=$a1.value;}
( '*' a2=restExp {$value*=$a2.value;}
| '/' a2=restExp {$value/=$a2.value;}
| '%' a2=restExp {$value=$value\%$a2.value;}
)*
;
/* Power have a higher precedence. */
restExp returns [double value]
: a1=incdecExp {$value=$a1.value;}
(
'^' a2=restExp {$value=Math.pow($value,$a2.value);}
)*
;
/* Power have a higher precedence. */
incdecExp returns [double value]
: a1=atomExp {$value=$a1.value;}
('++' {$value+=1;} )*
;
/* An expression atom is the smallest part of an expression: a number. Or
when we encounter parenthesis, we're making a recursive call back to the
rule 'additionExp'. As you can see, an 'atomExp' has the highest precedence. */
atomExp returns [double value]
: Number {$value=Double.parseDouble($Number.text);}
| '(' additionExp ')' {$value=$additionExp.value;}
;
/* A number: can be an integer value, or a decimal value */
Number
: ('0'..'9')+ ('.' ('0'..'9')+)?
;
/* We're going to ignore all white space characters */
WS
: (' ' | '\t' | '\r'| '\n') {$channel=HIDDEN;}
;
Sunday, September 2, 2012
[ANTLR]Simple Expression evalution using ANTLR
[lex-yacc] Simple Expression evalution using lex & yacc
CAL1.l---------------------------------------------------------------------- %{ #include <stdlib.h> #include <stdio.h> #include "y.tab.h" void yyerror(char*); %} %% [ \t]+ ; [0-9]+\.[0-9]+ {yylval.fval=atof(yytext);return FLOAT;} [0-9]+ {yylval.ival=atoi(yytext);return INTEGER;} [-+*/] {return *yytext;} "(" {return *yytext;} ")" {return *yytext;} \n {return *yytext;} . {printf("invalid character: %c",*yytext);} CAL1.Y-------------------------------------------------------------------------------------------------- %{ #include <stdlib.h> #include <stdio.h> int yylex(void); %} %union {int ival; float fval;} %token <ival> INTEGER %token <fval> FLOAT %type <fval> expr %type <fval> mulex %type <fval> term %% program: line program | line line: expr '\n' { printf("%f\n",$1); } | '\n' expr: expr '+' mulex { $$ = $1 + $3; } | expr '-' mulex { $$ = $1 - $3; } | mulex { $$ = $1; } mulex: mulex '*' term { $$ = $1 * $3; } | mulex '/' term { $$ = $1 / $3; } | term { $$ = $1; } term: '(' expr ')' { $$ = $2; } | INTEGER { $$ = $1; } | FLOAT {$$ = $1;} %% void yyerror(char *s) { fprintf(stderr,"%s\n",s); return; } int main(void) { yyparse(); return 0; }
How to run it?
$lex cal.l
$yacc -d cal.y
$gcc -o cal lex.yy.c y.tab.c -ll
$./cal
Reverse Enginnering
Reverse
Enginnering
The term reverse engineering as applied to
software means different things to different people."Reverse engineering
is the process of analyzing a subject system to create representations of the
system at a higher level of abstraction." It can also be seen as
"going backwards through the development cycle". In this model, the
output of the implementation phase (in source code form) is reverse-engineered
back to the analysis phase, in an inversion of the traditional waterfall model.
Reverse engineering is a process of examination only: the software system under
consideration is not modified (which would make it re-engineering). In
practice, two main types of reverse engineering emerge. In the first case,
source code is already available for the software, but higher-level aspects of
the program, perhaps poorly documented or documented but no longer valid, are
discovered. In the second case, there is no source code available for the
software, and any efforts towards discovering one possible source code for the software
are regarded as reverse engineering. This second usage of the term is the one
most people are familiar with.
Reverse engineering of software can be
accomplished by various methods. The three main groups of software reverse
engineering are:
·
Analysis
through observation of information exchange, most prevalent in protocol reverse
engineering, which involves using bus analyzers and packet sniffers, for
example, for accessing a computer bus or computer network connection and
revealing the traffic data thereon. Bus or network behavior can then be
analyzed to produce a stand-alone implementation that mimics that behavior.
This is especially useful for reverse engineering device drivers. Sometimes,
reverse engineering on embedded systems is greatly assisted by tools
deliberately introduced by the manufacturer, such as JTAG ports or other
debugging means. In Microsoft Windows, low-level debuggers such as SoftICE are
popular.
·
Disassembly
using a disassembler, meaning the raw machine language of the program is read
and understood in its own terms, only with the aid of machine-language
mnemonics. This works on any computer program but can take quite some time,
especially for someone not used to machine code. The Interactive Disassembler
is a particularly popular tool.
·
Decompilation
using a decompiler, a process that tries, with varying results, to recreate the
source code in some high-level language for a program only available in machine
code or bytecode.
Using
process re-engineering technique for Database Manager, our system will help
small enterprises to efficiently manage their accounts and stocks. According to
their need, customers can also design their own databases. Thus, it will lead
them to more flexible system and will improve their functionality.
The objective of the Tranformation
Team is to re-engineer the way in which small enterprises handle their data and
stocks. It will enable them to have a great harmony in business and to
progress.
This is accomplished
through:
·
Operational
Discovery Audits - At the beginning of all strategic engagements Operational
Discovery Audits are conducted by a team of enterprise vice presidents,
executive advisors, and transformation engineers. During this 2-day, onsite
visit we interview every level of the organization including front line staff,
managers, and executives to get a better understanding of how the enterprise
operates.
·
Current/Future
State Analysis - During phase one of implementation, members of the team will
work with organisation's team members to document in detail current enterprise
operations. Once there is an understanding of how the organization presently
works and its current management system, the Transformation team will work to
create swim lane diagrams outlining the optimal future state processes.
·
On
Path Progress Reports - Our transformation engineering team helps you make a
smooth transition from your current management system to go-live with your new
system to successful on-going performance via our reporting process. Included in
the maintenance of your customer management system are on six month check-ups
after each module go-live. This analysis provides you feedback on your progress
towards achieving optimal sustained performance.
Wifi technology
WiFi enabled devices are connected wirelessly and can connect to the Internet via a wireless access point.WiFi can function in geographical location and can be used where wiring and cable connection is not feasible.
In this experiment we will learn the different standards and the simulation of WiFi network. It also explains the concept of hidden node and exposed node problem and solve these issues.
The following hardware devices are required for connecting the Wi Fi Network.
Access Point
Access Point acts as a bridge between the wireless devices and wired network. It allows multiple devices to connect through it for accessing the network. An AP can also act as a router by which the data transmission can be possible from one access point to another.
Wireless Network Card
A wireless network card is required on each device on a wireless network. A laptop usually has an expansion slot which the network card would fit in to. A desktop computer would need an internal card, which will usually have a small antenna or an external antenna on it. These antennas are optional on most equipment and they help to increase the signal on the card.
Transmitter
A transmitter is basically used for emitting the wireless signals and it also receive the connection requests where a wireless client will send the requests and receives the replies from the transmitter. Here the transmitter is the wireless router.
How to connect Wi-Fi Network?
Wi-Fi Network is very easy to connect. If you will think about your laptop with any operating systems, then you can easily connect to a Wi-Fi network for accessing or you can share different files on a network.
Once you have acquired the necessary wireless networking hardware then the next step is to connect it all together to form a network and allow each device to communicate. The instructions below will act as basic guidelines of what needs to be done.
* The distance between each computer should be below 100 meters
* Each computer should be on the same floor
* Plug the access point into the power outlet and existing Ethernet jack on the network
* Configure the access point (usually via a web browser)
* Configure the client computers with the appropriate network settings required to be able to communicate with the access point.
Benefits of Wi Fi
Following are the different benifits of Wi Fi Networks
* In wireless ad-hoc network mode, devices like consumer electronics and gaming applications can directly connect and exchange data with each other.
* Digital images can be transferred wirelessly from cameras and other devices.
* All connected devices within the range have access to internet and inter-networking.
* Wi-Fi enables wireless voice-applications (Vo WLAN or WVOIP).
* Wi Fi provides a secure computer networking gateway, firewall, DHCP server and an intrusion detection system among many other features.
* Cost of cabling and network deployment of Local Area Networks is significantly reduced.
* Can be used at placed where wiring and cable lay-out is not feasible
* Due to its cost effective nature, it can be used widely in corporate set-ups and different educational campuses.
* A standard Wi Fi device can function in any geographical location.
Limitations
Like any other types of technology, Wi Fi has its set of drawbacks that are listed as follows:
* Global inconsistency of spectrum assignments and operational limitations.
* Overlapping of channels
* Limited range of equivalent isotropically radiated power in some areas.
* Greater power consumption compared to lower bandwidth standards.
* Limited battery life due to range and reach requirements.
* Wi Fi network range is also limited.
[C-CODE] Reverse file content using lseek function
#include<protos.h> #include<io.h> void main() { clrscr(); int fd=open("C:\\text.txt",O_RDONLY); if(fd==-1) { printf("FIle does not exists...."); return ; } char c; int i=0; lseek(fd,-1L-i,SEEK_END); do { read(fd,&c,1); printf("%c",c); i++; } while( lseek(fd,-1L-(i),SEEK_END)!=0); read(fd,&c,1); printf("%c",c); getch(); }
How to run it?
$gcc file.c \
$./a.out
[C-CODE] Copy file contents using system calls
/*Code open-sourced by http://codejar-lab.in
This is only for study purpose only and if you found any error use own logic to correct it so dont comment error.
*/
#include <syscall.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/uio.h>
#include <sys/stat.h>
#include <stdio.h>
int main(int argc,char * argv[])
{
int fd;
fd=open(argv[1],O_CREAT | O_RDONLY);
if(fd==-1)
{
printf("error opening the file");
}
void *buf = (char*) malloc(120);
int count=read(fd,buf,120);
printf("count : %d",count);
printf("%s",buf);
close(fd);
int f1;
f1=open(argv[2],O_CREAT | O_WRONLY);
if(f1==-1)
{
printf("error opening the file");
}
int c;
while(count=read(fd,buf,120)>0)
{
c=write(f1,buf,120);
}
if(c==-1)
{
printf("error writing to the file");
}
close(f1);
}
How to run it?
$gcc file.c
$./a.out
[C-CODE]Program to sum numbers using parallel processing
/*Code open-sourced by http://codejar-lab.in This is only for study purpose only and if you found any error use own logic to correct it so dont comment error. */ #include<stdio.h> #include<sys/ipc.h> #include<sys/wait.h> #include<sys/shm.h> int FFork(int iProcess) { int iCount; int PId; for (iCount=1; iCount<iProcess; iCount++) { PId = fork(); if (PId == 0) return(iCount); } return(0); } void FJoin(int nProc,int PId) { int iCount; if (PId == 0) for (iCount=1; iCount<nProc; iCount++) wait(0); else exit(0); } void *sshared (int size, int *shmid) { *shmid=shmget ( IPC_PRIVATE, size,0666 | IPC_CREAT); if (*shmid < 0) { printf("Error, cannot share memory"); exit(0); } return shmat(*shmid,0,0); } void cleanup_memory(int *shmid) { struct shmid_ds *buf; if (shmctl(*shmid,IPC_RMID,buf) !=0) { printf("Error, cannot free memory"); exit(0); } } int main() { int a[10]={1,2, 3,4, 5,6, 7,8, 9,10}; int pid,j; int *sum,shmid; sum=(int *)sshared(sizeof(int)*5,&shmid); pid=FFork(5); printf("Current process : %d" ,pid); for(j=pid;j<pid+2;j++) { sum[pid] = sum[pid] + a[j] ; } FJoin(5,pid); printf("[1] = %d\n", sum [0] ); printf("[2] = %d\n", sum [1] ); printf("[3] = %d\n", sum [2] ); printf("[4] = %d\n", sum [3] ); printf("[5] = %d\n", sum [4] ); printf("Total sum = %d\n", sum[0] + sum[1] + sum[2] + sum[3] + sum[4]); }How to run it?
$gcc file.c
$./a.out
[C-CODE]How to fork process in unix?
/*Code open-sourced by http://codejar-lab.in This is only for study purpose only and if you found any error use own logic to correct it so dont comment error. */ #include<stdio.h>How to run it?int main() { int PId; PId = fork(); if ( PId == 0 ) { printf("Child Here.....\n"); sleep(20); printf(" Parent Id : %d\n",getppid()); printf(" My Id : %d\n",getpid()); } else { printf("Parent Here.....\n"); printf(" My Child : %d\n",PId); printf(" My Id : %d\n",getpid()); printf(" My Parent : %d\n",getppid()); } }
$gcc file.c
$./a.out
Subscribe to:
Posts (Atom)