-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscanner.c
56 lines (49 loc) · 1.04 KB
/
scanner.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <ctype.h>
#include "input.h"
#include "errors.h"
#include "scanner.h"
/* Reconhece um operador aditivo */
int IsAddOp(char c)
{
return (c == '+' || c == '-' || c == '|' || c == '~');
}
/* Reconhece um operador multiplicativo */
int IsMulOp(char c)
{
return (c == '*' || c == '/' || c == '&');
}
/* Verifica se caractere combina com o esperado */
void Match(char c)
{
if (Look != c)
Expected("'%c'", c);
NextChar();
}
/* Retorna um identificador */
void GetName(char *name)
{
int i;
if (!isalpha(Look))
Expected("Name");
for (i = 0; isalnum(Look); i++) {
if (i >= MAXNAME)
Error("Identifier too long.");
name[i] = toupper(Look);
NextChar();
}
name[i] = '\0';
}
/* Retorna um número */
void GetNum(char *num)
{
int i;
if (!isdigit(Look))
Expected("Integer");
for (i = 0; isdigit(Look); i++) {
if (i >= MAXNUM)
Error("Integer too large.");
num[i] = Look;
NextChar();
}
num[i] = '\0';
}