Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anupam-io/strange-if-else
A simple bison based parser to detect and solve a strange if-else sequence.
https://github.com/anupam-io/strange-if-else
bison compiler flex grammar lex lexical-analyzer yacc
Last synced: 10 days ago
JSON representation
A simple bison based parser to detect and solve a strange if-else sequence.
- Host: GitHub
- URL: https://github.com/anupam-io/strange-if-else
- Owner: anupam-io
- Created: 2021-02-05T10:16:43.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-05T18:47:28.000Z (almost 4 years ago)
- Last Synced: 2024-09-11T12:59:06.905Z (about 2 months ago)
- Topics: bison, compiler, flex, grammar, lex, lexical-analyzer, yacc
- Language: Lex
- Homepage:
- Size: 1.95 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# strange `if-else` parser using Flex & Bison
This is a simple parser which can parse expressions in a strange way. The syntax for this language is very similar to `if-else` of C++. Inside curly braces or round braces, you can enter numbers or similar expressions and it will evaluate the final result.
## Tokens used
```
digit [0-9]+
if "if"
else "else"
cleft "{"
cright "}"
rleft "("
rright ")"
```
## Grammar used
- rL = round left = `(`
- cL = curly left = `{`
```
prog:
prog atom
| prog SEMICOLON
|
atom:
IF rL atom rR cL atom cR ELSE cL atom cR
| IF rL atom rR cL atom cR
| DIGIT
```## Sample inputs
```
if(1){33}
else{55};
```
```
if(1){
if(1){33}
else{55}
}
else{
if(1){33}
else{55}
};
```## How to run?
- `make`
- Enter inputs as mentioned above.