Skip to content

Instantly share code, notes, and snippets.

@3ap
Last active May 26, 2021 16:12
Show Gist options
  • Save 3ap/4cb72690b3404cb95b1376507c83ffbf to your computer and use it in GitHub Desktop.
Save 3ap/4cb72690b3404cb95b1376507c83ffbf to your computer and use it in GitHub Desktop.
%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;
%%
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
%{
#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