Author: bernhard
Date: Tue Jan 31 10:10:28 2006
New Revision: 11392

Modified:
   trunk/languages/bc/Bc.java
   trunk/languages/bc/docs/antlr_3.pod
   trunk/languages/bc/grammar/antlr_3/bc.g
Log:
Parrot bc: Let Java classes, created by ANTLR3 and bc.g,
create a dummy AST, but do not use it yet.


Modified: trunk/languages/bc/Bc.java
==============================================================================
--- trunk/languages/bc/Bc.java  (original)
+++ trunk/languages/bc/Bc.java  Tue Jan 31 10:10:28 2006
@@ -1,6 +1,7 @@
 // $Id$
 
 import org.antlr.runtime.*;
+import org.antlr.runtime.tree.*;
 
 public class Bc 
 {
@@ -8,10 +9,11 @@ public class Bc 
   {
     CharStream input = new ANTLRFileStream(args[0]);
     System.out.println( "1" );
-    // BcLexer lex = new BcLexer(input);
-    // CommonTokenStream tokens = new CommonTokenStream(lex);
+    BcParserLexer lex = new BcParserLexer(input);
+    CommonTokenStream tokens = new CommonTokenStream(lex);
     // System.out.println("tokens="+tokens);
-    // BcParser parser = new BcParser(tokens);
-    // parser.program();
+    BcParser parser = new BcParser(tokens);
+    BcParser.program_return r = parser.program();
+    // System.out.println("tree: "+((Tree)r.tree).toStringTree());
   }
 }

Modified: trunk/languages/bc/docs/antlr_3.pod
==============================================================================
--- trunk/languages/bc/docs/antlr_3.pod (original)
+++ trunk/languages/bc/docs/antlr_3.pod Tue Jan 31 10:10:28 2006
@@ -18,6 +18,29 @@ And see Makefile.
 
 Lexer, Parser and TreeParser are in the same file, speak grammar.
 C-comments serve as comments. C++ style as well ?
+
+'+' is one or many
+
+'(  )' is for grouping
+'|'    as for alternation 
+"''"   Sring delimeter, honoring '\t', '\n', '\r'
+
+'{   }' are actions
+';'     delimits rules
+'grammar <name>', set name of Parser, Name of autogenerated Lexer is generated 
from it
+
+Tell to generate an AST
+options 
+{
+    output=AST;
+    ASTLabelType=CommonTree;
+}
+
+'Sigil $' is for referencing alternations in actions, Lexer items only ???, 
also for setting returns
+
+'->' Is for tree construction
+'^' Is for definition and matching of tree nodes
+
  
 =head2 Lexer
 

Modified: trunk/languages/bc/grammar/antlr_3/bc.g
==============================================================================
--- trunk/languages/bc/grammar/antlr_3/bc.g     (original)
+++ trunk/languages/bc/grammar/antlr_3/bc.g     Tue Jan 31 10:10:28 2006
@@ -3,9 +3,32 @@
  */
 grammar BcParser;
 
-program
-    :   INT 
-    ;
+options 
+{
+  output=AST;
+  ASTLabelType=CommonTree;
+}
 
-INT :  ('0'..'9')+
-    ;
+  /* PROGRAM; */
+
+
+
+program 
+  : INT WS quit WS
+  ;
+
+INT
+ : ('0'..'9')+
+ ;
+
+quit
+ : 'quit'
+ ;    
+
+WS
+ : (   ' '
+     |   '\t'
+     |   '\r'
+     |   '\n'
+   )+
+ ;    

Reply via email to