Giter Club home page Giter Club logo

parser's Introduction

References

Hierarchy or steps

  • Lexical analysis (lex, flex, ...)
    • Reads the source code, and generates tokens
    • Each token may have attributes - property like int
    • Regular expression will be converted to NFA then DFA
  • Syntax analysis (yacc, bison, ...)
    • Or parsing
    • Build structure using tokens
    • Report errors encoding structures
    • Top down vs Bottom up
  • Semantic analysis
  • IR generation
  • IR optimization
  • Code generation
  • Optimization

Parsing

  • TOP Down (LL)
    • Begins with just the start symbol
    • Need to guess
  • Bottom-up (LR)

lex or flex file

  • Has an extension of *.l (elle), as from lex
%{
/* Defintion section
- Variable declaration
- header file here 
*/
%}
%%
/* Rules section
Pattern action
*/
%%
/*
User code may be here
*/

yacc or bison file

  • Has an extension of *.y, as from yacc
%{
/* C declaration
- Variable declaration
- header file here 
*/
%}
// Bison declaration
%%
/* Bison grammar
Pattern action
*/
%%
/*
User code may be here
*/

Sample flex

  • flex is for Lexical analysis
  • Ex: Number or word
    • Save as ex2.l
%{
#include <stdio.h>
%}

%%
[0123456789]+           printf("NUMBER\n");
[a-zA-Z][a-zA-Z0-9]*    printf("WORD\n");
%%
- Compile as `flex ex2.l; gcc lex.yy.c -o ex2 -lfl`
$ ./ex2
abc
WORD

123
NUMBER

abc 123
WORD
 NUMBER

ctr+D

parser's People

Contributors

hpjeongit avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.