It’s pretty easy to walk expression trees, typing :(x^2+1) |> dump etc. will let you see how they are structured. Here’s a rough solution, but there are expressions which will trip this up:
julia> walk!(list) = ex -> begin
ex isa Symbol && push!(list, ex)
ex isa Expr && ex.head == :call && map(walk!(list), ex.args[2:end])
list
end
walk! (generic function with 1 method)
julia> :(x^2+sum(x,y-3,z)) |> walk!([])
4-element Array{Any,1}:
:x
:x
:y
:z