This Repository contains C, LEX and YACC files made during our couse of Compiler Design (CS601).
Documentation site at : Compiler Design
Following package are needed for running the c, lex and yacc files. Please run the following commands:
Run the update command (just in case)
sudo apt-get update
then:
sudo apt-get install gcc
sudo apt-get install lex
sudo apt-get install bison
or instead of lex you can install flex using
sudo apt-get install flex
For compiling the C files:
gcc <filename.c>
./a.out
For compiling the lex files:
lex <lexfile.l> or flex <lexfile.l>
gcc lex.yy.c
./a.out
For compiling the yacc files (Along with the lex files):
yacc -d <yaccfile.y>
lex <lexfile.l>
gcc lex.yy.c y.tab.c
./a.out
A finite automata is implemented using C programming language which can detect:
- Lex program that copies a file, replacing each nonempty sequence of white space by a single blank.
- Lex program that copies a C program, replacing each instance of the keyword float with double.
- Lex program which will modify the words in the following way:
- Lex program to identify identifiers from a given input source file.
- Lex program to count the number of vowels and consonants from an input file and write the results to a file.
- Lex program to count the number of lines in a given input source file.
- Lex program to count the number of comment lines in a c program. Also eliminate that comment line. (input read from file).
- Lex program to identify correctly an inputted 8 bit binary number.
- Lex program to find out all the tokens from input C program.(input read from file)
- Lex program to count the number of tokens and find out all the tokens from input C program. (input read from file)
- Lex program to identify all the numbers in an input text and then perform the sum of the numbers.
- Lex program to count the number of the word “the” in an input text.
- Lex program to count the number of stopwords and remove all of them.
- Lex program to design a simple calculator.
- Lex program to count the number of palindromes present in a input text and write them to a separate text file.
- Lex program to check valid arithmetic expressions.
- Lex program to find the length of an input text.
- Lex program to reverse all the words in an input text.
- Lex program to find the smallest word in an input text.
- Lex program to convert lowercase characters to uppercase.
- Lex program to sort all the words in an input text as per their length.
- YACC program to recognize strings of { anbb | n≥5 }.
- YACC program for Binary to Decimal Conversion.
- YACC program to recognize string with grammar { bnan | n≥0 }.
- Yacc Program to evaluate a given arithmetic expression.
- YACC program to check whether given string is Palindrome or not.
- YACC program for Conversion of Infix to Postfix expression.
- YACC program for Conversion of Infix to Prefix expression.
- YACC program which accept strings that starts with 0 and ends with 1.
- YACC program to implement a Calculator and recognize a valid Arithmetic expression.
- YACC program to recognize a valid variable, which starts with a letter, followed by any number of letters or digits.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D