title: Two basic ANTLR questions
body: <p>I'm trying to use ANTLR to take a simple grammar and produce assembly output. My language of choice in ANTLR is Python.</p>
  
  <p>Many tutorials seem very complicated or elaborate on things that aren't relevant to me; I only really need some very simple functionality. So I have two questions:</p>
  
  <p><strong>'Returning' values from one rule to another.</strong></p>
  
  <p>So let's say I have a rule like:</p>
  
  <p>assignment: name=IDENTIFIER ASSIGNMENT expression;</p>
  
  <p>I can run Python code in {}s when this rule is recognised, and I can pass args to the Python code for expression by doing something like:</p>
  
  <p>assignment: name=IDENTIFIER ASSIGNMENT expression[variablesList];</p>
  
  <p>and then</p>
  
  <p>expression[variablesList]: blah blah</p>
  
  <p>But how do I 'return' a value to my original rule? E.g. how do I calculate the value of the expression and then send it back to my assignment rule to use in Python there?</p>
  
  <p><strong>How do I write out my target language code?</strong></p>
  
  <p>So I have some Python which runs when the rules are recognised, then I calculate the assembly I want that statement to produce. But how do I say "write out this string of assembly instructions to my target file"?</p>
  
  <p>Any good tutorials that are relevant to this kind of stuff (attribute grammars, compiling to something other than an AST, etc.) would be helpful too. If my questions don't make too much sense, please ask me to clarify; I'm having a hard time wrapping my head around ANTLR.</p>