Skip to content

Instantly share code, notes, and snippets.

@hanjae-jea
Created April 19, 2014 11:38
Show Gist options
  • Save hanjae-jea/11081879 to your computer and use it in GitHub Desktop.
Save hanjae-jea/11081879 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int index = 0;
int main(void)
{
scanf("%s", parser);
expr();
return 0;
}
void match(char t)
{
index ++;
}
void expr()
{
term();
while( true ){
if( parser[index + 1] == '+' ){
match('+'); term(); printf("+");
}
else if( parser[index + 1] == '-' ){
match('-'); term(); printf("-");
}
else break;
}
}
void term()
{
char t = parser[index];
if( '0' <= t && t <= '9' ){
printf("%c",t);
match(t);
}
else{
exit(-1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment