写README
练习英文
逼格√
Python3
git clone https://github.com/kabu1204/compilation.git
cd compilation/Exp1
python3 Scanner.py test2
- In function
__init__()
, modifyself.ReservedWords
,self.DoubleBoundaryWords
,self.SingleBoundaryWords
to fit your own reserved word set and delimiter set. - continue to modify other
self.something
to fit your own grammar definition
If you prefer to build your own DFA to match identifier
, integer
, string constants
(I've already implemented these three :) ) or something else:
- derive your own DFA, get your transform matrix and fill it in
self.transform_matrix
. modify functionAnalysis()
if necessary. GOTO STEP 7.
if you'd like to make full use of python package re
:
-
modify or add your own regular expression in function
__init__()
-
follow the format in function
Analysis_NO_DFA()
to modify it. -
change
self.Analysis(word)
toself.Analysis_NO_DFA(word)
in function__call__()
-
test your code
cd compilation/Exp2
python3 LR1.py test4 # test5
- copy your brand new
Scanner.py
to compilation/Exp2, and comment yourprint
sentences. - follow the format to modify
VT
,VN
,G
to fit your own grammar. - In function
init() (not __init__())
,I0
is the starting LR(1) item of a extended grammar, please modify it to yours. NO NEED TO modify it to CLOSURE(I0). - accordingly, modify the default value of the function
BuildLR1Table(termination = ...)
‘s parametertermination
PAY ATTENTION to the format - modify or add semantical functions in class
SemanticActions
, follow the format to modifyself.switch
in the meantime. - test your code
The DrawLR1Table
will generate a .MD
file LR1Table.MD
, witch draw's your grammar's LR(1) item set and ACTION&GOTO table.
ATTENTION: whenever you modify your grammar in G, don't forget to add new symbols to VT
or VN
if you have any issues, find the contacts in 记一次编译原理实验