Compare commits
2 Commits
4054fc4b27
...
3acbb7e1e6
| Author | SHA1 | Date | |
|---|---|---|---|
| 3acbb7e1e6 | |||
| b790a4faa0 |
@@ -117,4 +117,7 @@ main() {
|
|||||||
### Handwork
|
### Handwork
|
||||||
|
|
||||||
* Thompson's construction (RE -> NFA)
|
* Thompson's construction (RE -> NFA)
|
||||||
* Subset Construction(NFA -> DFA)
|
* Subset Construction(NFA -> DFA)
|
||||||
|
|
||||||
|
|
||||||
|
DFA Optimization
|
||||||
41
notes/3.md
Normal file
41
notes/3.md
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# Syntax Analysis
|
||||||
|
|
||||||
|
|
||||||
|
## Context-Free Grammars (CFG)
|
||||||
|
|
||||||
|
## Parse Tree
|
||||||
|
|
||||||
|
A tree representation of the derivation
|
||||||
|
|
||||||
|
parse tree has `terminals` at the leaves, `non-terminals` at the interior.
|
||||||
|
|
||||||
|
An in-order traversal of the leaves is the original input.
|
||||||
|
|
||||||
|
* leftmost derivation
|
||||||
|
* rightmost derivation
|
||||||
|
|
||||||
|
### Ambiguity
|
||||||
|
|
||||||
|
should be removed
|
||||||
|
|
||||||
|
for example: `A + B * C` should be resolved
|
||||||
|
|
||||||
|
**removing ambiguity**
|
||||||
|
|
||||||
|
|
||||||
|
### AST (Abstract Syntax Tree)
|
||||||
|
|
||||||
|
|
||||||
|
### Error Handling
|
||||||
|
|
||||||
|
One of the purposes of the compiler is error handling.
|
||||||
|
- to detect non-valid programs
|
||||||
|
- and to translate the non-valid to the valid
|
||||||
|
|
||||||
|
## Parsing
|
||||||
|
|
||||||
|
### Top-down Parsing
|
||||||
|
|
||||||
|
**Recursive Descent Parsing**
|
||||||
|
|
||||||
|
### Predictive Parsing
|
||||||
BIN
pdf/L3.pdf
Normal file
BIN
pdf/L3.pdf
Normal file
Binary file not shown.
BIN
pdf/P2.pdf
Normal file
BIN
pdf/P2.pdf
Normal file
Binary file not shown.
37
src/Makefile
Normal file
37
src/Makefile
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# Makefile for C-Minus Scanner
|
||||||
|
# ./lex/tiny.l --> ./cminus.l
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
CFLAGS = -W -Wall
|
||||||
|
|
||||||
|
OBJS = main.o util.o scan.o
|
||||||
|
OBJS_LEX = main.o util.o lex.yy.o
|
||||||
|
|
||||||
|
.PHONY: all clean
|
||||||
|
all: cminus_cimpl cminus_lex
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-rm -vf cminus_cimpl cminus_lex *.o lex.yy.c
|
||||||
|
|
||||||
|
cminus_cimpl: $(OBJS)
|
||||||
|
$(CC) $(CFLAGS) -o $@ $(OBJS)
|
||||||
|
|
||||||
|
cminus_lex: $(OBJS_LEX)
|
||||||
|
$(CC) $(CFLAGS) -o $@ $(OBJS_LEX) -lfl
|
||||||
|
|
||||||
|
main.o: main.c globals.h util.h scan.h
|
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
scan.o: scan.c globals.h util.h scan.h
|
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
util.o: util.c globals.h util.h
|
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
lex.yy.o: lex.yy.c globals.h util.h scan.h
|
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
lex.yy.c: cminus.l
|
||||||
|
flex -o $@ $<
|
||||||
|
|
||||||
Reference in New Issue
Block a user