Demo entry 6197451

ㅇㅇㅇ

   

Submitted by anonymous on Oct 11, 2016 at 18:47
Language: C++. Code size: 743 Bytes.

%{
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
%}

%token NUMBER

%%
command	: exp	{
			if($1 == 0)
			{
				printf("false\n");
			}
			else
			{
				printf("true\n");
			}
		}

exp	: exp '+' term {$$ = $1 + $3; }
	| exp '-' term {$$ = $1 - $3; }
	| term	       {$$ = $1; }
	| exp '>' term {
				if($1 > $2)
				{
					$$ = 1;
				}
				else
				{
					$$ = 0;
				}
			}
	| exp '<' term {
				if($1 < $2)
				{
					$$ = 1;
				}
				else
				{
					$$ = 0;
				}
			}
	;

term	: term '*' factor	{$$ = $1 * $3; }
	| factor		{$$ = $1; }
	;

factor	: NUMBER		{$$ = $1; }
	| '(' exp ')'		{$$ = $2; }
	;

%%
int yyerror(char* s)
{
	fprintf(stderr, "%s\n", s);
	return 0;
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).