typed ag alexey rodriquez y faridah liduan type systems project 26 jun 2003
Post on 19-Dec-2015
218 views
TRANSCRIPT
Goals
Produce a well-typed AG fileDetect type errors of semantic functions early in the AG stageDo type checking and type inferencing using:
AG type annotationsTypes of haskell source fragmentLocal attributes definitions
Why Typed AG?
Well typed AG => well typed haskell program Typed errors are given in terms of the AG source
Embedding AG to UHC (Attribute Haskell)
Advantages:Haskell is extended with attribute grammarMake use features of haskell interpreter and haskell compilerAG will have a module system if it is properly done
Disadvantages:Utterly Complex
Proper language design vs gluing
Embedding UHC to AG (Typed AG)
Advantages:Easier to implement
Disadvantages:Still a two-step processImprovements in the UHC do not apply to Typed AG
AG Data Flow Diagram
Parse
input
Concretesyntax
HS blocks
Abstractsyntax
err_dos
sem_AG
sem_Grammar(copy rules)
err_trans
transformedAST
Gen.sem_Grammar(generate code)
HS ASTerr_gen
Generate HSHS source
file
ReportErrors Errors
Implementation Choice
Parse
input
Concretesyntax
HS blocks
Abstractsyntax
err_dos
sem_AG
sem_Grammar(copy rules)
err_trans
transformedAST
Gen.sem_Grammar(generate code)
HS ASTerr_gen
Generate HSHS source
file
ReportErrors Errors
Parse
sem_UHC
Type inference
Environment+AG types
Type errors 1
Environment +haskell definitions
Type errors 2
Other implementation choice?
Parse
input
Concretesyntax
HS blocks
Abstractsyntax
err_dos
sem_AG
sem_Grammar(copy rules)
err_trans
transformedAST
Gen.sem_Grammar(generate code)
HS ASTerr_gen
Generate HSHS source
file
ReportErrors Errors
Implementation Options
Simple Dependency AnalysisType inference over local variables in the order determined by the analysis
Constraint: no cycles (cycle = incorrect result)
Use bindgroupPut all local attributes in a bindgroup and do type inferencing.
Disadvantages: no polymorphic local attributes
Implementation Options (cont~)
Use HC ConstructorsUse semantic functions to type check local, synthesized, and inherited attributes.
Disadvantages:Error messages are not given in terms of original AG source.
Current State of Affairs
Our implementation can detect type errors in the embedded Haskell source fragments.It can also detect type errors related to misuse of semantic functions.Type errors are also detected in the RHS of the attribute rules.
Missing features from UHC and our implementation
Type synonyms are not supported.Types are not parsed.Omission of local attributes (& patterns).Typing of attribute expressions as a whole.
Final Remarks
Typed AG guarantees well-typedness of generated Haskell source file.A really useful implementation of Typed AG will need modules and full Haskell.