File: expr.gram

package info (click to toggle)
python-pegen 0.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,980 kB
  • sloc: python: 15,064; makefile: 89
file content (15 lines) | stat: -rw-r--r-- 587 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
start: expr NEWLINE? ENDMARKER { ast.Expression(expr, lineno=1, col_offset=0) }
expr: ( expr '+' term { ast.BinOp(expr, ast.Add(), term) }
      | expr '-' term { ast.BinOp(expr, ast.Sub(), term) }
      | term { term }
      )
term: ( l=term '*' r=factor { ast.BinOp(l, ast.Mult(), r) }
      | term '/' factor { ast.BinOp(term, ast.Div(), factor) }
      | factor { factor }
      )
factor: ('(' expr ')' { expr }
        | atom { atom }
        )
atom: ( NAME { ast.Name(id=name.string, ctx=ast.Load()) }
      | NUMBER { ast.Constant(value=ast.literal_eval(number.string)) }
      )