写README
练习英文
逼格√
Python3
git clone https://github.com/kabu1204/compilation.gitcd compilation/Exp1
python3 Scanner.py test2- In function
__init__(), modifyself.ReservedWords,self.DoubleBoundaryWords,self.SingleBoundaryWordsto fit your own reserved word set and delimiter set. - continue to modify other
self.somethingto 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.pyto compilation/Exp2, and comment yourprintsentences. - follow the format to modify
VT,VN,Gto fit your own grammar. - In function
init() (not __init__()),I0is 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 parameterterminationPAY ATTENTION to the format - modify or add semantical functions in class
SemanticActions, follow the format to modifyself.switchin 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 记一次编译原理实验


