An AST (Abstract Syntax Tree) is exactly what the common output of a parser 
is, and you can see an example of it in the Go source code. But not always 
- the output of a parser can also be function calls, as in a streaming XML 
(SAX) style parser. 

The important elements of a parser is that it knows or implements a 
grammar, and can report grammatical and syntactical errors, and in the 
absence of them, provides information to some subsequent activity that is 
known to be grammatically and syntactically correct. 

When the input can be described by a formal grammar such as EBNF, then yes, 
there exist tools that can take an EBNF grammar and write a parser for it, 
which returns an AST that can then be operated over. 

The project that stephan linked you to actually already contains a CSS3 
parser; however, to answer your other 
question: https://github.com/goccmack/gocc is a package that allows you to 
generate a lexer/parser pair from a BNF 
definition. https://github.com/goccmack/gogll works on a subset of valid 
grammars (context-free grammars) to produce lexers and parsers.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/2fed3839-cb18-4635-be4f-b452fd7a97f2n%40googlegroups.com.

Reply via email to