Click here to Skip to main content
16,007,163 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to know whether a double value is valid or not?? Pin
ashxly15-Dec-04 16:07
ashxly15-Dec-04 16:07 
AnswerRe: How to know whether a double value is valid or not?? Pin
Maximilien15-Dec-04 16:42
Maximilien15-Dec-04 16:42 
GeneralRe: How to know whether a double value is valid or not?? Pin
ashxly15-Dec-04 22:17
ashxly15-Dec-04 22:17 
GeneralRe: How to know whether a double value is valid or not?? Pin
RChin15-Dec-04 22:31
RChin15-Dec-04 22:31 
AnswerRe: How to know whether a double value is valid or not?? Pin
RChin15-Dec-04 22:21
RChin15-Dec-04 22:21 
AnswerRe: How to know whether a double value is valid or not?? Pin
toxcct16-Dec-04 2:09
toxcct16-Dec-04 2:09 
AnswerRe: How to know whether a double value is valid or not?? Pin
David Crow16-Dec-04 4:28
David Crow16-Dec-04 4:28 
Questionwhy these Lex and Yacc programm can't run correctly? Pin
chenbuaa15-Dec-04 13:52
chenbuaa15-Dec-04 13:52 
yacc file:
%{
#include <stdio.h>
#include <ctype.h>

#define YYSTYPE double /* stack data type */
%}
%start list
%token NUMBER

%left '+' '-' /*left associative */
%left '*' '/' /*left associative */
%left UNARYMINUS

%%

list : /*empty*/
| list expr '\n'
{printf("%f\n",$2);}
| list error '\n'
{ yyerrok; }
;

expr : NUMBER
{ $$ = $1; }
| '-' expr %prec UNARYMINUS
{ $$ = -$2; }
| '+' expr %prec UNARYMINUS
{ $$ = $2; }
| expr '+' expr
{ $$ = $1 + $3; }
| expr '-' expr
{ $$ = $1 - $3; }
| expr '*' expr
{ $$ = $1 * $3; }
| expr '/' expr
{
if ($3)
$$ = $1 / $3;
else
{
$$ = 1;
printf (stderr, "%d.%d-%d.%d: division by zero",
@3.first_line, @3.first_column,
@3.last_line, @3.last_column);
}
}
| '(' expr ')'
{ $$ = $2; }
| '(' expr error
{ $$ = $2; yyerror("missing ')'"); yyerrok;}
;
%%
void main()
{
yyparse();
}

int yyerror(char* msg)
{
printf("Error: %s encountered \n", msg);
}

lex file:

%{

#include "cal.tab.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/*extern double yylval;
extern atof();*/

%}
digit [0-9]
integer {digit}+
exponant [eE][-+]?{integer}?

num {integer}("."{integer}?)?{exponant}?

%%

/*here! yylval can't get the right value */
{num} { yylval = atof(yytext);
printf("yylval is %f\n", yylval);
printf("yytext is %s\n",yytext);
return (NUMBER);
}

%%

int yywrap()
{
return 1;
}

Smile | :) Smile | :) Confused | :confused: Confused | :confused: Confused | :confused:
AnswerRe: why these Lex and Yacc programm can't run correctly? Pin
ThatsAlok15-Dec-04 17:41
ThatsAlok15-Dec-04 17:41 
GeneralRe: why these Lex and Yacc programm can't run correctly? Pin
markkuk15-Dec-04 23:55
markkuk15-Dec-04 23:55 
GeneralRe: why these Lex and Yacc programm can't run correctly? Pin
toxcct16-Dec-04 2:14
toxcct16-Dec-04 2:14 
AnswerRe: why these Lex and Yacc programm can't run correctly? Pin
markkuk15-Dec-04 23:57
markkuk15-Dec-04 23:57 
GeneralSetting line low in Serial Comm Pin
CNewbie15-Dec-04 13:37
CNewbie15-Dec-04 13:37 
GeneralVariables and functions in user defined functions Pin
SeanSheehan15-Dec-04 13:33
SeanSheehan15-Dec-04 13:33 
GeneralRe: Variables and functions in user defined functions Pin
mirex16-Dec-04 1:12
mirex16-Dec-04 1:12 
GeneralRe: Variables and functions in user defined functions Pin
SeanSheehan18-Dec-04 11:51
SeanSheehan18-Dec-04 11:51 
GeneralRe: Variables and functions in user defined functions Pin
mirex20-Dec-04 2:57
mirex20-Dec-04 2:57 
GeneralRe: Variables and functions in user defined functions Pin
toxcct16-Dec-04 2:44
toxcct16-Dec-04 2:44 
GeneralCMDIFrameWnd background Pin
JayMorrison15-Dec-04 11:15
JayMorrison15-Dec-04 11:15 
GeneralRe: CMDIFrameWnd background Pin
*Dreamz15-Dec-04 17:46
*Dreamz15-Dec-04 17:46 
GeneralRe: CMDIFrameWnd background Pin
JayMorrison16-Dec-04 6:21
JayMorrison16-Dec-04 6:21 
GeneralUploaded files are one long line Pin
Jack_pt15-Dec-04 10:38
Jack_pt15-Dec-04 10:38 
Generalresizing tab Pin
act_x15-Dec-04 9:13
act_x15-Dec-04 9:13 
Generalvariables Pin
Timothy Grabrian15-Dec-04 7:55
professionalTimothy Grabrian15-Dec-04 7:55 
GeneralRe: variables Pin
toxcct15-Dec-04 7:58
toxcct15-Dec-04 7:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.