I brought for you yecc, leex modules, also concept of alphabet and formal grammatic, lexical analysing and syntactic sense.

Alphabet

Atoms [a-z][0-9a-zA-Z_]*

Variables [A-Z_][0-9a-zA-Z_]*

Floats (\+|-)?[0-9]+\.[0-9]+((E|e)(\+|-)?[0-9]+)?
{.,-}
{0,1}

Word

01011001
− − · ·
module, fun , 10, Var, '='
defp, :int, :ok, string

Precedence, associativity, arity 

 

Lex yacc (leex & yecc)

Example 

AST

[
  {:assign, {:atom, 1, :a}, {:int, 1, 7}},
  {:assign, {:atom, 2, :b}, {:int, 2, 4}},
  {:assign, {:atom, 3, :result},
   {:add_op, {:atom, 3, :a},
    {:div_op, {:mul_op, {:atom, 3, :b}, {:int, 3, 10}}, {:int, 3, 2}}}},
  {:assign, {:atom, 5, :x}, {:int, 5, 20}},
  {:assign, {:atom, 6, :y}, {:int, 6, 3}},
  {:assign, {:atom, 7, :z}, {:int, 7, 6}},
  {:assign, {:atom, 8, :value},
   {:add_op, {:int, 8, 10},
    {:div_op,
     {:mul_op, {:div_op, {:atom, 8, :z}, {:atom, 8, :y}}, {:atom, 8, :x}},
     {:int, 8, 4}}}}
]

Surprise!

Good job Bro!

Lexical and syntactic analysis tools in erlang

By sojourner

Lexical and syntactic analysis tools in erlang

  • 1,006