dis3 - CMPSC 160 Translation of Programming Languages...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CMPSC 160 Translation of Programming Languages Project 2: Lex and Yacc Introduction • Projects – Calculator (10%) – Lexical and Syntax Analysis (20%) – Abstract Syntax Tree (20%) – Type Checking and Semantic Analysis (30%) – Code Generation (20%) • Enviornment – Linux – C/C++ – Lex and Yacc Lexical an Syntax Analysis • Input – CSimple files • Process – Lexical Analysis – Syntax Analysis • Output – “Success” – Error (line no) Makefile main.cpp parser.y - The yacc file lexer.l - The lex test.good.calc CSimple the Language • CSimple – C-like language – Scanner – Parser • Scanner – Lex / Flex – Regular Expression – State Machine • Parser – Yacc / Bison – Grammar-based – LALR CSimple - Tokens Keyword Operator Literal Other boolean && boolean true false ; char / : interger = char „a‟ , string == | if > integers 100 0x01 011b { else >= } while < string “a string \n” ( var <= ) procedure - identifier [a-zA-Z][a-zA-Z0-9]* [ return ! ] != || \n \r white space <<EOF>>…. + comment (%..........%) * Lex the scanner • Lex – Lexical Analyzer Generator – Program generator – Flex – Regular Expression -> Statemachine Lex Input • Lex source file:“*.l” or “*.lex” – Pair of RegExp and Action – RegExp {Action} • Regular expression – Describe the lexical rule • Action – What to do when a certain token is recognized – Using a high level language, C or others Lex An Example %{ #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} RegEcp {Actio} %% // User Subroutines int yywrap() { return 1; }...
View Full Document

This note was uploaded on 11/23/2010 for the course MATH 104b taught by Professor Ceniceros,h during the Spring '08 term at UCSB.

Page1 / 31

dis3 - CMPSC 160 Translation of Programming Languages...

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

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