Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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.