Coder Social home page Coder Social logo

flex-and-bison's Introduction

Flex And Bison

Lexer

Various types of token this lexer can recognize.

  1. Data types:

    • Int. e.g. 234,3445,2234
    • Float. e.g. 234.34,345.5,1.00
    • String. e.g. "sdf", "a", "Ads"
    • Character. e.g. 's', 'A'
  2. It also can seperate Binary Operations like:
    • '-'(Minus)
    • '+'(Addition)
    • '*'(Multiplication)
    • '/'(Divide)
    • '%'(MOD)
    • ':='(Assignment)
    • '==', '<', '<=', '>', '>=' (Binary Condition)
  3. We Skip space (' '), tab (\t), and new line (\n)
  4. End of statement recognized by semicolon (';').
  5. 'exit' token terminate the program.

Parser

In our parser we have tried to replicate the grammer below.

PROG   → STMTS
STMTS  → STMT STMTS | ɛ
STMT   → DTYPE id IDLIST SEMI
STMT   → id := EXPR SEMI
IDLIST → , id IDLIST | ɛ
EXPR   → EXPR OPTR TERM | TERM
EXPR   → ( EXPR ) | neg EXPR
TERM   → id | CONST
DTYPE  → int | float | char
CONST  → ilit | rlit | clit | slit
OPTR   → + | - | * | / | % | '==' | '<' | '<=' | '>' | '>='
SAY    → id | id, IDLIST

Compile Process

flex gxx.l
bison -dyv gxx.y
gcc lex.yy.c y.tab.c -o gxx.exe

Sample Program

Input:
int a,b;
a := 2;
b := 3;
SAY: a,b;
a := a * a;
a := a + b;
SAY: a;
exit;

Output:

a: 2
b: 3
a: 7
Program End

Limitation

1. Still, we can't store value and operate arithmetic operation. Arithmetic operations only allowed for integer.

flex-and-bison's People

Contributors

kimbbakar avatar

Stargazers

 avatar

Watchers

 avatar

flex-and-bison's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.