Поправљени багови у лексеру
This commit is contained in:
parent
1bdbcdb020
commit
d2f18f2339
8
Makefile
8
Makefile
|
@ -1,7 +1,7 @@
|
|||
# cirilisp - компајлер за ћирилични дијалекат лиспа
|
||||
|
||||
# ћирилисп верзија
|
||||
VERSION = 0.0
|
||||
VERSION = 0.1
|
||||
|
||||
# локација за инсталацију
|
||||
PREFIX = /usr/local
|
||||
|
@ -13,7 +13,7 @@ LDFLAGS = -lm -lc
|
|||
|
||||
CC = cc
|
||||
|
||||
SRC = cirilisp.c util.c lexer.c
|
||||
SRC = cirilisp.c readline.c lexer.c
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
all: cirilisp
|
||||
|
@ -21,7 +21,7 @@ all: cirilisp
|
|||
.c.o:
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
|
||||
$(OBJ): util.h lexer.h
|
||||
$(OBJ): readline.h lexer.h
|
||||
|
||||
cirilisp: $(OBJ)
|
||||
$(CC) -o $@ $(OBJ) $(LDFLAGS)
|
||||
|
@ -31,7 +31,7 @@ clean:
|
|||
|
||||
dist: clean
|
||||
mkdir -p cirilisp-$(VERSION)
|
||||
cp -r Makefile util.h $(SRC) cirilisp-$(VERSION)
|
||||
cp -r Makefile readline.h $(SRC) cirilisp-$(VERSION)
|
||||
tar -cf cirilisp-$(VERSION).tar cirilisp-$(VERSION)
|
||||
gzip cirilisp-$(VERSION).tar
|
||||
rm -rf cirilisp-$(VERSION)
|
||||
|
|
|
@ -32,7 +32,7 @@ int main(int argc, char **argv)
|
|||
int i = 0;
|
||||
while (current != NULL)
|
||||
{
|
||||
printf("Токен бр. %d: \"%s\", тип:%s\n", i, current->lexeme, current->type == number ? "number" : (current->type == symbol ? "symbol" : "parenthesis"));
|
||||
printf("Токен бр. %d: \"%s\", тип:%s\n", i, current->lexeme, current->type == numberToken ? "number" : (current->type == symbolToken ? "symbol" : "parenthesis"));
|
||||
current = current->next;
|
||||
++i;
|
||||
}
|
||||
|
|
14
lexer.c
14
lexer.c
|
@ -19,7 +19,7 @@ token *lexLine(char *input)
|
|||
while (i < n)
|
||||
{
|
||||
*new = lex1Token(input, &i);
|
||||
if ((*new)->type == undefined)
|
||||
if ((*new)->type == undefinedToken)
|
||||
{
|
||||
/* уколико се у реду нађе токен који је лексички погрешан, штампа се место тог
|
||||
токена у реду и брише се цела листа, функција враћа NULL*/
|
||||
|
@ -59,21 +59,21 @@ token *lex1Token(char *input, int *i)
|
|||
*i += a[0].rm_eo;
|
||||
/* помера индекс да би се игнорисали почетни "вајт-спејс" карактери */
|
||||
|
||||
if (!regexec(®Symbol, input + *i, nmatches, a, 0))
|
||||
if (!regexec(®Number, input + *i, nmatches, a, 0))
|
||||
{
|
||||
result->type = symbol;
|
||||
result->type = numberToken;
|
||||
}
|
||||
else if (!regexec(®Number, input + *i, nmatches, a, 0))
|
||||
else if (!regexec(®Symbol, input + *i, nmatches, a, 0))
|
||||
{
|
||||
result->type = number;
|
||||
result->type = symbolToken;
|
||||
}
|
||||
else if (!regexec(®Parenthesis, input + *i, nmatches, a, 0))
|
||||
{
|
||||
result->type = parenthesis;
|
||||
result->type = parenthesisToken;
|
||||
}
|
||||
else
|
||||
{
|
||||
result->type = undefined;
|
||||
result->type = undefinedToken;
|
||||
result->lexeme = NULL;
|
||||
goto skipStringCopy;
|
||||
}
|
||||
|
|
8
lexer.h
8
lexer.h
|
@ -2,10 +2,10 @@
|
|||
|
||||
typedef enum
|
||||
{
|
||||
undefined,
|
||||
number,
|
||||
symbol,
|
||||
parenthesis
|
||||
undefinedToken,
|
||||
numberToken,
|
||||
symbolToken,
|
||||
parenthesisToken
|
||||
} tokenType;
|
||||
|
||||
typedef struct _Token
|
||||
|
|
Loading…
Reference in a new issue