Mass reformat
This commit is contained in:
parent
4d27def35e
commit
df11e34235
27 changed files with 121 additions and 136 deletions
35
calc.c
35
calc.c
|
|
@ -2,24 +2,16 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef enum {
|
||||
TOKEN_INT,
|
||||
TOKEN_PLUS,
|
||||
TOKEN_MUL,
|
||||
TOKEN_DIV,
|
||||
TOKEN_LPAREN,
|
||||
TOKEN_RPAREN,
|
||||
TOKEN_EOF
|
||||
} TokenType;
|
||||
typedef enum { TOKEN_INT, TOKEN_PLUS, TOKEN_MUL, TOKEN_DIV, TOKEN_LPAREN, TOKEN_RPAREN, TOKEN_EOF } TokenType;
|
||||
|
||||
typedef struct {
|
||||
TokenType type;
|
||||
int value;
|
||||
int value;
|
||||
} Token;
|
||||
|
||||
const char *input;
|
||||
size_t pos;
|
||||
Token current_token;
|
||||
size_t pos;
|
||||
Token current_token;
|
||||
|
||||
void skip_whitespace() {
|
||||
while (isspace(input[pos])) pos++;
|
||||
|
|
@ -43,19 +35,12 @@ Token get_next_token() {
|
|||
|
||||
pos++;
|
||||
switch (ch) {
|
||||
case '+':
|
||||
return (Token){TOKEN_PLUS, 0};
|
||||
case '*':
|
||||
return (Token){TOKEN_MUL, 0};
|
||||
case '/':
|
||||
return (Token){TOKEN_DIV, 0};
|
||||
case '(':
|
||||
return (Token){TOKEN_LPAREN, 0};
|
||||
case ')':
|
||||
return (Token){TOKEN_RPAREN, 0};
|
||||
default:
|
||||
fprintf(stderr, "Unexpected character: %c\n", ch);
|
||||
exit(1);
|
||||
case '+': return (Token){TOKEN_PLUS, 0};
|
||||
case '*': return (Token){TOKEN_MUL, 0};
|
||||
case '/': return (Token){TOKEN_DIV, 0};
|
||||
case '(': return (Token){TOKEN_LPAREN, 0};
|
||||
case ')': return (Token){TOKEN_RPAREN, 0};
|
||||
default: fprintf(stderr, "Unexpected character: %c\n", ch); exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue