Last active
May 26, 2021 16:12
-
-
Save 3ap/4cb72690b3404cb95b1376507c83ffbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%option nounput | |
%option noinput | |
%{ | |
#include <stdio.h> | |
#include "parser.h" | |
%} | |
%% | |
[_A-Za-z][_A-Za-z0-9]+ return(ID); | |
"["|"]" return yytext[0]; | |
\n | |
. return -1; | |
%% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TARGET = project | |
SOURCES = lexer.y parser.l | |
OBJECTS = lexer.o parser.o | |
CFLAGS = -Wall -Wpedantic -Werror | |
all: $(TARGET) | |
$(TARGET): $(OBJECTS) | |
$(CC) $^ -o $(TARGET) | |
tests: $(TESTS_S) $(TESTS_F) | |
parser.c: parser.y | |
bison -dy $^ -o $@ | |
lexer.c: lexer.l parser.c | |
flex -t $< > $@ | |
clean: | |
rm -f $(TARGET) $(OBJECTS) parser.c lexer.c parser.h | |
.PHONY: all clean tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%{ | |
#include <stdio.h> | |
#include <string.h> | |
int yyerror(); | |
int yylex(void); | |
extern char *yytext; | |
%} | |
%token ID | |
%% | |
s: id | arrid; | |
arrid: ID '[' ']' { printf("arrid: %s\n", yytext); } | |
id: ID { printf("id: %s\n", yytext); } | |
%% | |
int main() { return yyparse(); } | |
int yywrap() { return 1; } | |
int yyerror() { return 0; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment