home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR9
/
SYACC131.ZIP
/
YACC.259
< prev
next >
Wrap
Text File
|
1993-11-11
|
919b
|
59 lines
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <string.h>
#define PA_STACK_TYPE int
#define LEXER lexer
char* lexer ();
%%
// this is the precedences and associativity declarations area
%%
//
// A simple calculator
//
line : expr '\n'
{ printf ( "\nTHE RESULT: %d\n", *$1 ); }
;
expr : expr '+' term
{ *$$ = *$1 + *$3; }
| term
;
term : term '*' factor
{ *$$ = *$1 * *$3; }
| factor
;
factor : '(' expr ')'
{ *$$ = *$2; }
| DIGIT
;
%%
char token[128];
char* lexer()
{
int c;
int value;
c = getche ();
/* using Renter key to signify the end of input */
if ( c == '\r' )
return "";
else if ( isdigit (c) )
{
*token_value = c - '0';
return "DIGIT";
};
token[0] = c;
token[1] = '\0';
return token;
};