dis2 - CMPSC 160 Translation of Programming Languages...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
CMPSC 160 Translation of Programming Languages Project 2: Simple Parser
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Plan for today st project Kick off the 2 nd project
Background image of page 2
Project 1?
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Projects 2-5: Warning These projects are incremental This is a problem as you will not be given correct solutions after each one Try to keep up Lexer Parser Proj 2 Proj 3 Abstract Syntax Tree Type Checking Proj 4 Code Generation Proj 5
Background image of page 4
Project 2 Projects: Calculator – 10% Lexical and Syntax Analysis – 20% Abstract Syntax Tree – 20% Type Checking and Semantic Analysis – 30% Code Generation – 20% Environment: Linux C/C++ Lex and Yacc
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Project 2 Input: Simple code Simple is the name of our language! Cmple? Process: Lexical Analysis Syntax Analysis Output: Success message Error (line #)
Background image of page 6
Project 2 tarball: Makefile – no changes there main.cpp – no changes there lexer.l – edit this file parser.ypp – edit this file test.good.calc – make your own tests
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Okay. . so what now? We need to cover: How to use Lex (Flex) How to use Yacc (Bison) What is Simple anyway? Language manual at ../~cs160/projects/language.html
Background image of page 8
Lex! Lex / Flex Lex is our scanner! Or is it? Lex generates c/cpp code that can scan any input, following all the rules we provide .l source file Flex Usable Scanner Stuff to scan Tokens
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lex - Examples %{ #include <stdio.h> #include "global.h" %} digit [0-9] %% {digit} {return DIGIT;} %% int yywrap() { return 1; } %{ #include <stdio.h> #include "global.h" %} %% [0-9] {return DIGIT;} %% int yywrap() { return 1; } %{ #include <stdio.h> #include "global.h" %} Definition RegExp %% {Defintion} {Action} RegExp {Action} %% // User Subroutines int yywrap() { return 1; }
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 35

dis2 - CMPSC 160 Translation of Programming Languages...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online