From: | "idknow@gmail.com" <idknow@gmail.com> |
Newsgroups: | comp.compilers |
Date: | 15 Nov 2006 15:23:19 -0500 |
Organization: | Compilers Central |
References: | 06-11-052 |
Keywords: | parse |
Posted-Date: | 15 Nov 2006 15:23:19 EST |
PAolo wrote:
> I am writing a piece of software that accept in input the definition
> of a mathematical function and a list of points in which evaluate the
> function and puts the result in output.
[snip]
> ... The gramar is:
>
> %token <val> NUM /*float representation*/
> %token <name> ID /*name starting with [a-zA-Z_] */
> %left '-' '+'
> %left '*' '/'
> %left NEG /* negation--unary minus */
> %right '^' /* exponentiation */
>
> exp: NUM {printf(" %g",$1);}
> | ID {printf(" #%s",$1);}
> | ID '(' exp ')' {printf(" @%s",$1);}
> | exp '+' exp {printf(" +");}
> | exp '-' exp {printf(" -");}
> | exp '*' exp {printf(" *");}
> | exp '/' exp {printf(" /");}
> | '-' exp %prec NEG {printf(" neg");}
> | exp '^' exp {printf(" ^");}
> | '(' exp ')'
> ;
>
> -John]
Exp: Unaryop Mul.
Unaryop: '-'|'!'
Mul: Mulop Add.
Mulop: '*'|'/'|'%'|'^'
Add: Addop Primary.
Addop: '+'|'-'
Primary: '(' Exp ')' | ID.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.