• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Antlr Conexaojava
 

Antlr Conexaojava

on

  • 1,319 views

 

Statistics

Views

Total Views
1,319
Views on SlideShare
1,210
Embed Views
109

Actions

Likes
2
Downloads
0
Comments
0

5 Embeds 109

http://fernandomeyer.com 65
http://localhost 29
http://www.linkedin.com 9
http://slop.cc 5
http://10.0.1.5 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Antlr Conexaojava Antlr Conexaojava Presentation Transcript

  • Playing on DSLs With ANTLR
    • Fernando Meyer
    • [email_address]
  • TECHNICAL CONTENT BRAIN SAFETY
  • Who am I
    • Software Engineer at JBoss
    • JBoss Drools Core Developer - Working on BRMS design and implementation.
    • Language and Compilers researcher
    • fmeyer @ GUJ || #drools irc.codehaus.org
  • DSL DSLs are generally very high level languages tailored to specific tasks. They are designed to make their users particularly effective in a specific domain. DSLs include a wide range of applications, many of which you might not consider languages. DSLs include data for mats, configuration file for mats, network protocols, text processing languages, protein patter ns, gene sequences, space probe control languages, and domain-specific programming languages.
  • Enterprise Usages ?
    • insurance policy DSL developed internally in large insurance enterprise
    • combat simulation DSL (**)
    • salary calculation DSL
    • billing DSL
  • Rules DSL? try Drools labs.jboss.org/drools
  • Advantages?
    • DSLs allow solutions to be expressed in the idiom and at the level of abstraction of the problem domain. Consequently, domain experts themselves can understand, validate, modify, and often even develop DSL programs.
    • Self-documenting code.
    • DSLs enhance quality, productivity, reliability, maintainability, portability and reusability.
    • DSLs allow validation at the domain level. As long as the language constructs are safe any sentence written with them can be considered safe.
    • prefer Ruby, Python ... [*flexible languages]
  • Disadvantages
    • Cost of designing, implementing, and maintaining a DSL.
    • Finding, setting, and maintaining proper scope.
    • Difficulty of balancing trade-offs between domain-specificity and general-purpose programming language constructs.
    • Potential loss of processor efficiency compared with hand-coded software.
    • Hard or impossible to debug. (*)
  • Antlr A sophisticated parser generator you can use to implement language interpreters, compilers, and other translators.
  • Low Complexity? recipe "PBJ Sandwich" ingredients "two slices of bread", "one heaping tablespoon of peanut butter", "one teaspoon of jam" instructions "spread peanut butter...", "spread jam...", "place other slice..." servings 1 prep_time "2 minutes"
    • don’t use ANTLR
    • prefer Ruby , Python ... [*flexible languages]
  • Overall Translation Data Flow
  • Compilation Process
  • Lexical analysis
    • The specification of a programming language will include a set of rules, often expressed syntactically, specifying the set of possible character sequences that can form a token or lexeme.
  • ***A lexeme is an abstract unit of morphological analysis in linguistics, A token is a categorized block of text, usually consisting of indivisible characters known as lexemes. A lexical analyser processes lexemes to categorize them according to function, giving them meaning. This assignment of meaning is known as tokenization . A token can look like anything: English, gibberish symbols, anything; it just needs to be a useful part of the structured text.
  • Java programming language: sum=3+2; lexeme token type sum IDENT = ASSIGN_OP 3 NUMBER + ADD_OP 2 NUMBER ; SEMICOLON
  • Parsing parsing (more formally syntactic analysis) is the process of analyzing a sequence of tokens to determine its grammatical structure with respect to a given formal grammar.
  • Parsing transforms input text into a data structure (AST) x = y - z * 3
  • Parser is the component of a compiler that carries out this task.
  • Relationship Between Characters, Tokens, and ASTs
  • A State Machine That Generates Blues Lyrics
  • Understanding ANTLR Grammar Files
    • Believe it or not but Antlr grammar files are built to be as close to your java source files as possible
  • The Grammar File
  • The rule section
  • ANTLRWorks Grammar Development Environment
  • Now ... Hands on Macs ! http://fmeyer.org/antlr/antlr-cj-lab.tar.gz Download the sample app from
  • Questions?
    • [email_address]
    • http://fmeyer.org
    • http://labs.jboss.org/drools
    • http://antlr.org