Presentation is loading. Please wait.

Presentation is loading. Please wait.

Simple Language (SL) Start version 00. Atze Dijkstra, 2000IPT - SL2 Content SL, the language AG, attribute grammar system First version of SL compiler.

Similar presentations


Presentation on theme: "Simple Language (SL) Start version 00. Atze Dijkstra, 2000IPT - SL2 Content SL, the language AG, attribute grammar system First version of SL compiler."— Presentation transcript:

1 Simple Language (SL) Start version 00

2 Atze Dijkstra, 2000IPT - SL2 Content SL, the language AG, attribute grammar system First version of SL compiler written in AG

3 Atze Dijkstra, 2000IPT - SL3 SL examples let fac :: Int -> Int = \n -> if n > 0 then n * fac (n-1) else 1 fi in fac 6 ni let fac :: Int -> Int = \n -> let cnt :: Ref Int = new 2 ; res :: Ref Int = new 1 in while ( cnt <= n ) do res := res * cnt ; cnt := cnt + 1 od ; res ni in fac 6 ni

4 Atze Dijkstra, 2000IPT - SL4 SL features Expression evaluation Int, Bool, Array, Product, Data, Ref Assignment Let (blocks), Lambda (functions) If, While, Case Typechecking

5 Atze Dijkstra, 2000IPT - SL5 SL first version Integer constant Generating: listing + code 55 LDC 55 TRAP 0 HALT.sl.ssmstdout

6 Atze Dijkstra, 2000IPT - SL6 AG: SL parser Parser combinators + scanner pRoot = sem_Root_Root pExpr pExpr = (sem_Expr_Intexpr. string2int) pInteger string2int = foldl (\val dig -> (10*val + ord dig - ord '0')) 0 Semantic functions?

7 Atze Dijkstra, 2000IPT - SL7 AG: SL abstract syntax Abstract tree representation DATA Root | Root Expr DATA Expr | Intexpr Int Root Intexpr 55 Root Expr tree node tree node type tree node variant

8 Atze Dijkstra, 2000IPT - SL8 AG: SL aspects (attributes) Pretty printed output & stack code Root Intexpr 55 Root Expr pp copied synthesized attribute text.show $ int Described by ATTR Root [ || ppexpr: PP_Doc ] SEM Root | Root LHS. ppexpr = "expr_pp" SEM Expr [ || pp: PP_Doc ] | Intexpr LHS. pp = "text.show $ int"

9 Atze Dijkstra, 2000IPT - SL9 AG notation ATTR Root [ | | ppexpr: PP_Doc ] SEM Root | Root LHS. ppexpr = "expr_pp" SEM Expr [ | | pp: PP_Doc ] | Intexpr LHS. pp = "text.show $ int" Attribution (Hugs) text for definition, specific for: Node type, Node variant, Attribute, Direction Attribute name Attribute type (Hugs or Node) synthesized  inh+synth  inherited 

10 Atze Dijkstra, 2000IPT - SL10 AG compilation Generates Haskell – Generate SL.hs from SL.ag compile "SL" allc Datastructures, semantics,... data Expr = Expr_Intexpr Int deriving Show -- semantic domains type T_Expr = (SCode,PP_Doc) -- catas sem_Expr (Expr_Intexpr int) = sem_Expr_Intexpr int -- funcs sem_Expr_Intexpr ::Int -> T_Expr sem_Expr_Intexpr int = ( ((S_LDC int:)), (text.show $ int) )

11 Atze Dijkstra, 2000IPT - SL11 Scanner Transforms character sequences to tokens data TokenType = TkSymbol | TkVarid | TkConid | TkKeyword | TkOp | TkString | TkCharb| TkInteger8 | TkInteger10 | TkInteger16 | TkTextnm | TkTextln | TkError deriving (Eq, Ord) type Linenumber = Int type Filename = String newtype Token = Tok (TokenType, String, String, Linenumber, Filename)

12 Atze Dijkstra, 2000IPT - SL12 Code Generation For a Simple Stack Machine SEM Root [ || ppscode: PP_Doc ] | Root LHS. ppscode = "( vlist. map (text.textOfS)" ". expr_scode" ". (S_TRAP 0:)" ". (S_HALT:)" "$ []" ")" SEM Expr [ || scode: SCode ] | Intexpr LHS. scode = "(S_LDC int:)" DATA S | HALT | TRAP Int | LDC Int

13 Atze Dijkstra, 2000IPT - SL13 Simple Stack Machine Memory (Code, Stack) + Registers + Stack manipulating instructions


Download ppt "Simple Language (SL) Start version 00. Atze Dijkstra, 2000IPT - SL2 Content SL, the language AG, attribute grammar system First version of SL compiler."

Similar presentations


Ads by Google