Skip to main content

2. Lex program that detects statement type i.e. Simple or Compound

Lex program that detects statement type i.e. Simple or Compound 
Note: Only AND | OR | BUT conjunctions are supported.
Program:
%option noyywrap
%{ 
char test='s';
%}
%%
(""[aA][nN][dD]"")|(""[oO][rR]"")|(""[bB][uU][tT]"") {test='c';}
. {;}
\n return 0;
%%
main()
{
yylex();
if(test=='s')
    printf("\n Its a simple sentence");
else if(test=='c')
    printf("\n This is compound sentence");
}

Comments

Post a Comment

Popular posts from this blog

Selenium + Python + UnexpectedAlertPresentException: Dealing with annoying alerts

Handling  UnexpectedAlertPresentException   Alerts who hates them? I Do!  Who doesn't hate an annoying alert causing your tests / scraping job to fail? I must say they are pretty much on point on the Unexpected part!  Fortunately, there are easy ways to mitigate the issue. 1. Disable alerts completely: driver . execute_script( 'window.alert = function(){};' ); execute this script just before where you anticipate the alert and you're golden. 2. You want to see the alert text but not disturb the execution flow. driver . execute_script( 'window.alert = console.info;' ); Now the alerts have been redirected to the console and you don't have to worry about them. (Unless you have to - then you'd have to monitor the console) 3. You know exactly when it comes and want to accept the alert and move on. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 from selenium import webdriver from selenium.webdriver.s

Python Program for Soundex Algorithm

This is a python implementation for Soundex Algorithm. This Program builds a JSON document as a dictionary and is kept on building at every execution. Its constantly appended and referenced while the program  is executed. Program: from re import sub def remove_symbols (input_string): #Convert the characters to lower case and then use #Regular expressions to remove non a-z chars return sub( '[^A-Z]+' , '' , input_string) def clean (input_string): #Convert the characters to lower case and then use #Regular expressions to remove non a-z chars return sub( '[^a-z]+' , '' , input_string . lower()) word = "Input" def soundex (word): #Step 1: Capitalize all letters in the word and drop all punctuation marks. word = remove_symbols(word . upper()) #Step 2: Retain the first letter of the word. first_letter = word[ 0 ] word = word[ 1 :] #Step 3 & 4: Change ( 'A&#

weather report

/* Problem Statement: Create a class named weather report that holds a daily weather report with data members day_of_month,hightemp,lowtemp,amount_rain and amount_snow. The constructor initializes the fields with default values: 99 for day_of_month, 999 for hightemp,-999 for low temp and 0 for amount_rain and amount_snow. Include a function that prompts the user and sets values for each field so that you can override the default values. Write a program that creates a monthly report. */ #include #include class weather { public: int day_of_month[50]; int high_temp[50]; int low_temp[50]; int amount_rain[50]; int amount_snow[50]; weather() //defination { day_of_month[0]=99; high_temp[0]=999; low_temp[0]=-999; amount_rain[0]=amount_snow[0]=0; } void get_data(int n); void put_data(int n); void average(int n); }; void weather:: average(int n) { int min ,max,total_rainfall,total_snowfall; total_rainfall=0; tot