项目作者: akcgjc007

项目描述 :
A simple bison based parser to detect and solve a strange if-else sequence.
高级语言: Lex
项目地址: git://github.com/akcgjc007/strange-if-else.git
创建时间: 2021-02-05T10:16:43Z
项目社区:https://github.com/akcgjc007/strange-if-else

开源协议:

下载


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

  1. digit [0-9]+
  2. if "if"
  3. else "else"
  4. cleft "{"
  5. cright "}"
  6. rleft "("
  7. rright ")"

Grammar used

  • rL = round left = (
  • cL = curly left = {
    1. prog:
    2. prog atom
    3. | prog SEMICOLON
    4. |
    5. atom:
    6. IF rL atom rR cL atom cR ELSE cL atom cR
    7. | IF rL atom rR cL atom cR
    8. | DIGIT

Sample inputs

  1. if(1){33}
  2. else{55};
  1. if(1){
  2. if(1){33}
  3. else{55}
  4. }
  5. else{
  6. if(1){33}
  7. else{55}
  8. };

How to run?

  • make
  • Enter inputs as mentioned above.