compiler development cmpsc 401
play

Compiler Development (CMPSC 401) Lexical Analysis: JFlex Janyl - PowerPoint PPT Presentation

Compiler Development (CMPSC 401) Lexical Analysis: JFlex Janyl Jumadinova February 5, 2019 Janyl Jumadinova Compiler Development (CMPSC 401) February 5, 2019 1 / 9 Getting jFlex jFlex package and documentation can be obtained from


  1. Compiler Development (CMPSC 401) Lexical Analysis: JFlex Janyl Jumadinova February 5, 2019 Janyl Jumadinova Compiler Development (CMPSC 401) February 5, 2019 1 / 9

  2. Getting jFlex jFlex package and documentation can be obtained from www.jflex.de Janyl Jumadinova Compiler Development (CMPSC 401) February 5, 2019 2 / 9

  3. jFlex Program Format /* User code */ %% /* Options and declarations */ %% /* Lexical Rules */ 1 User Code (e.g. import statements), included top of generated Java; often empty. 2 Options “Marcos” (named REs); code to be spliced into generated Java class. 3 Rule = Pattern + Action. 4 Pattern = Regular Expression. 5 Action = Snippet of Java code (Actions triggered whenever pattern matched). Janyl Jumadinova Compiler Development (CMPSC 401) February 5, 2019 3 / 9

  4. jFlex RE Syntax Janyl Jumadinova Compiler Development (CMPSC 401) February 5, 2019 4 / 9

  5. jFlex Example Pattern: ("+"|"-")?[0-9]+("."[0-9]+)? Meaning? Janyl Jumadinova Compiler Development (CMPSC 401) February 5, 2019 5 / 9

  6. jFlex Example Pattern: ("+"|"-")?[0-9]+("."[0-9]+)? Meaning? Optional sign One or more digits Optional decimal point one or more digits Janyl Jumadinova Compiler Development (CMPSC 401) February 5, 2019 5 / 9

  7. jFlex Notes RE . (dot): matches any character except newline. %standalone option: generated code includes a main method. Special characters, such as ( ) - + ˆ [ ] — *, must be quoted if they appear as themselves. Use backslash to quote a single symbol (example: ). Can attach names (example: { Digit } ) to REs for brevity/clarity. When multiple rules apply: take longest match (maximum munch), and use order of rule appearance to break ties. Material enclosed in % { and } % is included directly in the generated java program. Janyl Jumadinova Compiler Development (CMPSC 401) February 5, 2019 6 / 9

  8. TINY Programming Language { Example program in TINY language} read num; if num > 0 then factorial := 1; repeat factorial := factorial num; num := num-1 until num = 0; write factorial end TINY is a simple toy language. Uses Pascal-like syntax. if-then-end , if-then-else-end , repeat-until , assignment , read and write . Janyl Jumadinova Compiler Development (CMPSC 401) February 5, 2019 7 / 9

  9. TINY Programming Language Semicolons are separators, not terminators. No declarations. Integer variables only. Arithmetic expressions : variables, constants, + , − , ∗ , /, () Boolean expressions : arithmetic expressions, < , = read, write operations, perform simple input/output. Comments enclosed in { } Janyl Jumadinova Compiler Development (CMPSC 401) February 5, 2019 8 / 9

  10. TINY Programming Language Reserved Words : if, then, else, end, repeat, until, read, write Special Symbols : + − / = < (); := Numbers : One or more digits Identifiers : One or more letters Comments : Any sequence of symbols (other than } ) enclosed in { ... } Janyl Jumadinova Compiler Development (CMPSC 401) February 5, 2019 9 / 9

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend