Add Pos Info

XT -- A Bundle of Program Transformation Tools

Summary

addPosInfo adds position information to an AsFix2ME parse tree.

Example

The following syntax definition defines a tiny language of assignments and expressions.

  definition
  module Main
  exports
    context-free start-symbols Stm*

    sorts Id IntConst
    lexical syntax
      [\ \t\n]  -> LAYOUT
      [a-zA-Z]+ -> Id
      [0-9]+    -> IntConst

    sorts Stm
    context-free syntax
      Id ":=" Exp -> Stm {cons("Assign")}

    sorts Exp
    context-free syntax
      Id        -> Exp {cons("Var")}
      IntConst  -> Exp {cons("Int")}

      Exp "+"  Exp -> Exp  {left, cons("Plus")}

Generate a parse table:

  > sdf2table -i Foo.def -o Foo.tbl

Input file:

  x := 5
  y := x + 4
  z := x + y

Parse the input and have a look at the result in abstract syntax:

  > sglr -i foo.txt -p Foo.tbl | addPosInfo -p ./foo.txt -m | implodePT | pp-aterm

Notes:

  • you must specify the path (-p) of the input file.
  • sglr must produce Asfix2ME. This happens if you pass no -2 argument.