LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-19-2012, 09:47 AM   #1
ashlin
LQ Newbie
 
Registered: Sep 2012
Posts: 2

Rep: Reputation: Disabled
Exclamation Im getting following errors while compiling my LEX program


There are the errors I'm getting:
Quote:
editted.l: In function ‘main’:
editted.l:39:4: warning: passing argument 1 of ‘fprintf’ from incompatible pointer type [enabled by default]/usr/include/stdio.h:355:12: note: expected ‘struct FILE * __restrict__’ but argument is of type ‘char *’
editted.l: In function ‘yywrap’:
editted.l:65:12: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token
editted.l:65:12: error: expected expression before ‘:’ token

My code is as follows:

Code:
%{
	unsigned long charCount = 0, wordCount = 0, lineCount = 0;
	#undef yywrap
%}

word [^ \t\n]+
eol \n

%%
{word} { wordCount++; charCount += yyleng; }
{eol} { charCount++; lineCount++; }
.	charCount++;
%%


char **fileList;
unsigned currentFile = 0;
unsigned nFiles;
unsigned long totalCC = 0;
unsigned long totalWC = 0;
unsigned long totalLC = 0;

main(argc, argv)
int argc;
char **argv;
{
	FILE *file;

	fileList= argv+1;
	nFiles=argc-1;

	if (argc == 2) 
	{
		currentFile = 1;
		file = fopen(argv[1], "r") ;
		if (!file) 
		{
			fprintf ("stderr,*could not open %s\n",argv[1]);
			exit(1);
		}
		yyin=file;
	}

	if (argc > 2)
		yywrap(); /* open first file */

	yylex();
	
	if (argc > 2) 
	{
		printf("%8lu %8lu %8lu %s\n", lineCount, wordCount, charCount, fileList [currentFile-1]);
		totalCC += charCount;
		totalWC += wordCount;
		totalLC += lineCount;
		printf("%8lu %8lu %8lu total\n",totalLC, totalWC, totalCC);
	}
	 else
		printf("%8lu %8lu %8lu\n",lineCount,wordCount, charCount );
	return 0;
}

yywrap()
{
	FILE *file:
	if ( (currentFile ! = 0) && (nFiles > 1) && (currentFile < nFiles) )
	{
		printf("%8lu %8lu %8lu %s\n", lineCount, wordCount, charCount, fileList[CurrentFile-1]);
		totalCC += charCount;
		totalWC += wordCount;
		totalLC += lineCount;
		charCount = wordcount = lineCount = 0;
		fclose (yyin) ; /* done with that file */
	}

	while (fileList[currentFile] != (char *)0) 
	{
		file = fopen(fileList[currentFile++], "r");
		if (file != NULL) 
		{
			yyin = file;
			break;
		}
		fprintf ( stderr ,"could open %s\n", fileList[currentFile-1]);
	}
	return (file ? 0 : 1);
}

Last edited by ashlin; 09-19-2012 at 09:59 AM.
 
Old 09-20-2012, 05:54 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
I don't know lex, but from C++ I'm guessing you need to write
Code:
fprintf (file,"stderr,*could not open %s\n",argv[1]);
and in the first line of yywrap change the ':' at the end of the line to a ';'
 
1 members found this post helpful.
Old 09-22-2012, 01:41 AM   #3
Ztcoracat
LQ Guru
 
Registered: Dec 2011
Distribution: Slackware
Posts: 7,556
Blog Entries: 10

Rep: Reputation: Disabled
I've never compiled from source before but I did find some good instructions to learn how to.

If you ever need to re-compile a program you should do a <make clean> or (make dist clean)
This will delete files created during the previous compile and give you a clean tree.

The instructions also said:
If you encounter problems from source the error should clearly state what you are missing or why it is failing.

I found the instructions under "Tutorials" at the main page of linuxquestions written by Jeremy titled
Compiling Programs From Source
http://www.linuxquestions.org/linux/...ms_from_Source

Hope this helps
 
Old 09-24-2012, 12:48 PM   #4
ashlin
LQ Newbie
 
Registered: Sep 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Wink Thank you! :)

Quote:
Originally Posted by Snark1994 View Post
I don't know lex, but from C++ I'm guessing you need to write
Code:
fprintf (file,"stderr,*could not open %s\n",argv[1]);
and in the first line of yywrap change the ':' at the end of the line to a ';'

Thank you very much for your help. I have successfully edited my code.
 
Old 09-25-2012, 06:24 AM   #5
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Well done please mark the thread as 'SOLVED' (there should be a link at the top of the page)

Thanks,
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Compilation errors with compiling a program with boost libraries 1.39 Metal_Koola Programming 5 12-04-2009 07:13 PM
gcc errors while compiling my server.c program using MySQL linuxfan84 Programming 3 06-18-2008 02:26 AM
problem while compiling a lex program sam_cit Linux - Software 1 02-21-2006 03:59 AM
my first C++ program, errors while compiling lu543285 Programming 11 09-26-2004 03:42 AM
cryptic errors compiling simplest C program code_noc Slackware 4 10-06-2003 08:38 PM


All times are GMT -5. The time now is 07:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration