Skip to content

Commit f39297f

Browse files
committed
Add a LALR grammar for Rust with testing support
1 parent 29bd9a0 commit f39297f

File tree

7 files changed

+2663
-0
lines changed

7 files changed

+2663
-0
lines changed

configure

+2
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,8 @@ probe CFG_ISCC iscc
647647
probe CFG_JAVAC javac
648648
probe CFG_ANTLR4 antlr4
649649
probe CFG_GRUN grun
650+
probe CFG_FLEX flex
651+
probe CFG_BISON bison
650652
probe CFG_PANDOC pandoc
651653
probe CFG_PDFLATEX pdflatex
652654
probe CFG_XELATEX xelatex

mk/grammar.mk

+48
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ B = $(CFG_BUILD_DIR)/$(CFG_BUILD)/stage2/
1414
L = $(B)lib/rustlib/$(CFG_BUILD)/lib
1515
LD = $(CFG_BUILD)/stage2/lib/rustlib/$(CFG_BUILD)/lib/
1616
RUSTC = $(STAGE2_T_$(CFG_BUILD)_H_$(CFG_BUILD))
17+
ifeq ($(CFG_OSTYPE),apple-darwin)
18+
FLEX_LDFLAGS=-ll
19+
else
20+
FLEX_LDFLAGS=-lfl
21+
endif
1722

1823
# Run the reference lexer against libsyntax and compare the tokens and spans.
1924
# If "// ignore-lexer-test" is present in the file, it will be ignored.
@@ -67,3 +72,46 @@ $(info cfg: javac not available, skipping lexer test...)
6772
check-lexer:
6873

6974
endif
75+
76+
$(BG)lex.yy.c: $(SG)lexer.l $(BG)
77+
@$(call E, flex: $@)
78+
$(Q)$(CFG_FLEX) -o $@ $<
79+
80+
$(BG)lexer-lalr.o: $(BG)lex.yy.c $(BG)parser-lalr.tab.h
81+
@$(call E, cc: $@)
82+
$(Q)$(CFG_CC) -include $(BG)parser-lalr.tab.h -c -o $@ $<
83+
84+
$(BG)parser-lalr.tab.c $(BG)parser-lalr.tab.h: $(SG)parser-lalr.y
85+
@$(call E, bison: $@)
86+
$(Q)$(CFG_BISON) $< --output=$(BG)parser-lalr.tab.c --defines=$(BG)parser-lalr.tab.h \
87+
--name-prefix=rs --warnings=error=all
88+
89+
$(BG)parser-lalr.o: $(BG)parser-lalr.tab.c
90+
@$(call E, cc: $@)
91+
$(Q)$(CFG_CC) -c -o $@ $<
92+
93+
$(BG)parser-lalr-main.o: $(SG)parser-lalr-main.c
94+
@$(call E, cc: $@)
95+
$(Q)$(CFG_CC) -std=c99 -c -o $@ $<
96+
97+
$(BG)parser-lalr: $(BG)parser-lalr.o $(BG)parser-lalr-main.o $(BG)lexer-lalr.o
98+
@$(call E, cc: $@)
99+
$(Q)$(CFG_CC) -o $@ $^ $(FLEX_LDFLAGS)
100+
101+
102+
ifdef CFG_FLEX
103+
ifdef CFG_BISON
104+
check-grammar: $(BG) $(BG)parser-lalr
105+
$(info Verifying grammar ...)
106+
$(SG)testparser.py -p $(BG)parser-lalr -s $(S)src
107+
108+
else
109+
$(info cfg: bison not available, skipping parser test...)
110+
check-grammar:
111+
112+
endif
113+
else
114+
$(info cfg: flex not available, skipping parser test...)
115+
check-grammar:
116+
117+
endif

0 commit comments

Comments
 (0)