This document is written in GitHub flavoured markdown syntax. You may view this document here.
-
Selected C syntax subset
- variable declaration/variable initialization
- int
- float
- char
- simple statements
- branches
- if / if-else
- supports binary operation as condition
- loop
- supports only
while
loop
- supports only
- if / if-else
- functions
- basic arithmetics
+
,-
,*
,/
- variable declaration/variable initialization
-
Defined tokens and output format
- Defined tokens
%token <_symbol> ID
%token <_doubleVal> DOUBLE
%token <_intVal> INT
%token <_type> TYPE
%token <_string> STRING
%type <_doubleVal> stmt_list
%type <_doubleVal> stmt
%type <_doubleVal> element
%type <_doubleVal> term
%type <_doubleVal> factor
%type <_doubleVal> declaration
%type <_doubleVal> arg_list
%type <_doubleVal> arg
%type <_type> branch_list
%type <_type> branch_condition
%type <_type> func_args
%token IF WHILE FOR
%left <_intVal> GT
%left <_intVal> LT
%left <_intVal> GEQ
%left <_intVal> LEQ
%left <_intVal> EQ
%left <_intVal> NEQ
%left <_intVal> OR
%left <_intVal> AND
%nonassoc IFX
%nonassoc ELSE
- Output format
- this parser follows the output format shown on the p.41 of the assignment explanation slides. The Lex part will also check if a symbol exists or not and perform the corresponding actions such as insert a new key into the
symbol table
.
- this parser follows the output format shown on the p.41 of the assignment explanation slides. The Lex part will also check if a symbol exists or not and perform the corresponding actions such as insert a new key into the
- Defined tokens
-
Implementation obstacles
- This assignment is much harder than the previous one. It takes me for about few weeks to finish it.
- Designing a proper grammar is a challenging task for me, which is also the main task of this assignment.
- The co-working between
YACC
andLEX
also took me a lot of time.
-
Known Bugs
- Does NOT support
for
loop.- the condition part of for loop is way complicated than I've ever imagined, so I gave up eventually.
- Does NOT support
-
Anything worth to be mentioned
- I'm still thinking...XD