- Notifications
You must be signed in to change notification settings - Fork0
nichitaa/formal-languages-and-compiler-design
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Pasecinic Nichita
NodeJS-TypeScript CLI to convert a regular grammar to Finite Automaton (FA)
Check if some input string is accepted by generated FA
Demo
Program to convert input NFA to DFA, respecting all transitions and rules.
sample input NFA:
constnfa_sample:I_FA={'q0':{'a':['q1'],'b':['q0'],},'q1':{'a':[],'b':['q1','q2'],},'q2':{'a':['q2'],'b':['q3'],},'q3':{'a':[],'b':[]}}constnfa_a:string[]=['a','b']constnfa_start:string='q0';constnfa_terminal:string='q3';
sample console output DFA:
correspondingdfa:{'->q0':{'a':['q1'],'b':['q0']},'q1':{'a':[],'b':['q1','q2']},'q1q2':{'a':['q2'],'b':['q1','q2','q3']},'q2':{'a':['q2'],'b':['q3']},'*q3':{'a':[],'b':[]},'*q1q2q3':{'a':['q2'],'b':['q1','q2','q3']}}
More NFA examples can be seen in NFA_test.ts
- was used same structure (as in previous labs) to represent the grammar
- each step is a separate function which works independently and returns a new, updated grammar
- utils - set of simple and useful utils to check if the grammar meets a certain condition (mostly)
- ACTUAL PERFORMED STEPS:
- Check if S in RHA, if so update grammar with S0
- Remove null (ε) transitions and any remaining
- Remove unit transitions and any duplicates
- Substitute terminals in transitions with multiple variables to correspond to CNF
- Substitute the transitions with more then 2 non terminals and non reachable or useless transitions to correspond to CNF
- at each step is shown the current grammar in form of a table, then it is easy to follow the steps and check for correctitude (at least, I think so)
To run the programs:
clone repositorycd into specific lab workrun npm install or yarn installrun npm start or yarn start
the console app is in4.LL1
To run it:clone repositorycd 4LL1 folderrun npm irun npm startyou can change the productions to be parsed by changing the arguments of main function in index.tsfind and modify the test cases from tests/index.ts directoryParse tree works fine too, though is not that easy to follow as on web version of the applicationHere is a quick demo
the web application with reach UI to visualize the ll1 steps is inll1-react-app and the same logic from4.LL1 was used for express api fromll1-expressjs-api
To run the aplication:clone repositorycd into ll1-expressjs-api folderrun npm irun npm run devcd into ll1-react-apprun npm irun npm run startwill be opened default http://localhost:3000/Now you can load predifined productions and parse any word or add your own productions and try to parse itParse tree works fine tooHere is a quick demo
Note: most of the edge-cases were covered for each step, but there can still appear some recursion errors for ambiguous productions.
About
Formal Languages and Compiler Design 1. RE to FA 2. NFA to DFA 3. CFG to CNF
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.









