/interpreter

Simple interpreter for Pascal language using various studies on compilers and interpreter.

Primary LanguagePython

pascal interpreter && python debugger - 
https://docs.python.org/2/library/pdb.html

Arithmetic
"3+5"
Token: type & value (3 INT, 5 INT, + PLUS)
lexical analysis: breaking string into tokens.

lexemes: sequence of characters to form a token. (34, 17, 67 : INTEGER)
parsing/parser: process of structuring diff phrases in a stream of token. (INT -> PLUS -> INT -> MINUS -> INT -> PLUS -> INT)

Syntax-directed interpreters.
evaluate an expression as soon as the parser recognized a certain language construct like addition, subtraction, multiplication, or division. Such interpreters are called syntax-directed interpreters.

abstract-syntax tree (AST)
2 * 7  + 3

      + (root node )
  *       3

2    7
Solve -> term -> factor

AST tree vs Parse tree
- AST smaller then Parse Tree
- AST better for intermediate representation (IR) than Parse Tree


AST
>>> x = Parser("2+3+4+5")
>>> node = x.solve()
>>>
>>> print(node.left.token)
Token Value + Type PLUS
>>> print(node.left.left.token)
Token Value + Type PLUS
>>> print(node.left.left.left.token)
Token Value 2 Type INTEGER
>>> print(node.left.left.right.token)
Token Value 3 Type INTEGER
>>>
>>>
>>>
>>> print(node.left.left.token)
Token Value + Type PLUS

    (+)
  (+)  5
 (+) 4 
2   3

git
- git blame <file_name> (who wrote code in this file?)