7
十二月

Lex/YACC作業二的YACC (hw2.y)

   Posted by: admin   in 98(上)編譯器

%union{
    int ival;
    char* sval;
}
 
%token <sval> NAME
%token <ival> NUMBER
%type <ival> expression
%start statements
 
%%
statements: statements ',' statement
          | statement
          ;
 
statement: NAME '(' expression ')' { printf("%s=%d\n", $1, $3); free($1);}
	;
 
expression:	expression '+' NUMBER	{ $$ = $1 + $3; }
	|	expression '-' NUMBER	{ $$ = $1 - $3; }
	|	NUMBER			{ $$ = $1; }
	;
%%
main()
{
	yyparse();
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: ,

This entry was posted on 星期一, 十二月 7th, 2009 at 10:41:25 and is filed under 98(上)編譯器. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

4 Trackbacks/Pings

  1. Dwayne    十一月 26 2014 / 8下午:

    deaths@rationalizations.carletons” rel=”nofollow”>.…

    ñïñ çà èíôó!!…

  2. Francis    十二月 24 2014 / 5下午:

    moraines@orbit.staircase” rel=”nofollow”>.…

    good….

  3. Hubert    一月 14 2015 / 5下午:

    readjustment@bullish.dabbed” rel=”nofollow”>.…

    ñïñ çà èíôó!…

  4. sean    一月 18 2015 / 8下午:

    greenwood@mommor.subordinator” rel=”nofollow”>.…

    ñïàñèáî çà èíôó!…

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment