Simple lexical analyser and syntax parser made using Cygwin
- go to Cygwin download and install it
- while installtion select following libraries to install bison, flex, gcc-core, and make.
- Go to Cygwin bash and type
cd /cygdrive
- then give the path (ex:
cd c/users/maneesha/desktop/lexical-analyser
) - run
make
command to make necessary files - then in terminal run
compiler < test.c
-
program -> declaration-list
-
declaration-list -> declaration-list declaration | declaration
-
declaration -> var-declaration | fun-declaration
-
var-declaration-> type-specifier ID ; | type-specifier ID [ NUM ] ;
-
type-specifier-> int | void
-
fun-declaration-> type-specifier ID ( params ) compound-stmt
-
params-> param-list | VOID
-
param-list-> param-list , param| param
-
param-> type-specifier ID | type-specifier ID [ ]
-
compound-stmt-> { local-declarations statement-list }
-
local-declarations-> local-declarations var-declaration | empty
-
statement-list-> statement-list statement | empty
-
statement-> expression-stmt | compound-stmt | selection-stmt | iteration-stmt | return-stmt
-
expression-stmt-> expression ; | ;
-
selection-stmt-> if( expression ) statement | if( expression ) statement else statement
-
iteration-stmt-> while ( expression ) statement
-
return-stmt-> return ; | return expression ;
-
expression-> var = expression | simple-expression
-
var-> ID | ID [ expression ]
-
simple-expression -> additive-expression relop additive-expression| additive-expression
-
relop-> < | <= | > | >= | == | !=
-
additive-expression-> additive-expression addop term | term
-
addop-> + | -
-
term-> term mulop factor | factor
-
mulop-> * | /
-
factor-> ( expression ) | var | call | NUM
-
call-> ID ( args )
-
args-> arg-list | empty
-
arg-list-> arg-list , expression | expression