I am by no means a YACC/Lex expert. When I started writing this document, I had exactly two days of experience. All I want to accomplish is to make those two days easier for you. In no way expect the HOWTO to show proper YACC and Lex style. Examples have been kept very simple and there may be better ways to write them.
![]()
A simple calculator using lex and yacc . A grammer that allows calculation with a new Lex specification that recognizes english words:Such that you can now do : Example 5 MINUS 22 PLUS 24 TIMES 54 MULTIPLY 515 DIVIDE 3
pas.l - is the lex filepas.y - i the yacc file
CAVEAT: Operator precedence yot yet handled! (keeping it simple for those new to LEX AND YACC) warning: 16 shift/reduce conflicts
Requirements : compatible versions of the cygwin distributions lex/yacc or Flex or Bison
Usage:Commands to create our compiler, pas.exe, are listed below:lex pas.l # create lex.yy.cyacc –d pas.y # create y.tab.h, y.tab.ccc lex.yy.c y.tab.c –o pas.exe # compile/link
Acceptable tokens:[0-9]+ { yylval = atoi(yytext);return INTEGER;}[-+/n] return yytext;PLUS return '+';MINUS return '-';TIMES return '';MULTIPLY return '';DIVIDE return '/';[ t] ; /* skip whitespace */
This Interpreter includes 2 files to run a flex file and a yacc file.
Scientific calculator using lex and yaccFunctions and Instructions :-
![]()
All the values in trigonometric functions which are inserted or returned are in radians .If the user wants to calculate other than this and if it gives input in the manner other than above specified it will give syntax error . In case of input given is out of range in inverse functions it will print out “nan” i.e. it is out of range .In case of bin_dec function if u give integer other than 0 and 1 it will return the same value.
![]() Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |