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