Lab3: Parser

Introduction

This assignment requires you to write a parser for our C programming language.

Instruction

To Run Lab3
  1. Download this package, and extract somewhere
  2. In command-line, enter the path and run:
  3. ml-yacc c.grm
  4. ml-lex c.lex
  5. MLton: mlton lab3.mlb and Run lab3 like "lab3 test.c".
  6. SML/NJ: sml sources.cm and Run lab3 like Main.parse_file "test.c".
File Description
c.lexml-lex file*
c.grmml-yacc file**
main.smlcall the parser
sources.cmfor SML/NJ
lab3.mlbfor MLton
test.ca test file
LICENSELicense of our code
To Do Lab3
  1. Read ML Yacc Manual
  2. Refer to specification of our C language
  3. You need to finish "c.lex" and "c.grm"
  4. You can copy a lot of code in "c.lex" from Lab2.
  5. Finish "c.grm". In Lab3, you don't need to add semantic rules. If your "c.grm" is correct, parser will return "Success!"
program : function_protos struct_decls functions ()
function_protos : type id LPAREN var_decls RPAREN SEMICOLON ()
....

Note

Lab4 will be quite easy if you do Lab3 well!