summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2013-03-16 11:55:10 -0400
committerAdrian Thurston <thurston@complang.org>2013-03-16 11:55:10 -0400
commit74a1f8f770efe39e86cb21dbd4e0db5e027aaf98 (patch)
treecc57589cdb81f7a8c995949608070cdd74bb002b
parentbc0459c84fcb3a98a7caac2ecf75b3ee531ec3d0 (diff)
downloadcolm-74a1f8f770efe39e86cb21dbd4e0db5e027aaf98.tar.gz
rudimentary implementation in the code_expr, can now print lit strings
-rw-r--r--colm/bootstrap2.cc64
-rw-r--r--colm/bootstrap2.h12
-rw-r--r--colm/colm.lm5
3 files changed, 69 insertions, 12 deletions
diff --git a/colm/bootstrap2.cc b/colm/bootstrap2.cc
index 2da2e668..038d8942 100644
--- a/colm/bootstrap2.cc
+++ b/colm/bootstrap2.cc
@@ -239,26 +239,75 @@ void Bootstrap2::walkCflDef( cfl_def &cflDef )
BaseParser::cflDef( ntDef, objectDef, defList );
}
-void Bootstrap2::walkPrintStmt( print_stmt &printStmt )
+ExprVect *Bootstrap2::walkCodeExprList( _repeat_code_expr &codeExprList )
+{
+ ExprVect *exprVect = new ExprVect;
+ while ( !codeExprList.end() ) {
+ code_expr codeExpr = codeExprList.value();
+ LangExpr *expr = walkCodeExpr( codeExpr );
+ exprVect->append( expr );
+ codeExprList = codeExprList.next();
+ }
+ return exprVect;
+}
+
+LangStmt *Bootstrap2::walkPrintStmt( print_stmt &printStmt )
{
std::cerr << "print statement: " << printStmt.text() << std::endl;
+
+ _repeat_code_expr codeExprList = printStmt.CodeExprList();
+ ExprVect *exprVect = walkCodeExprList( codeExprList );
+ return LangStmt::cons( internal, LangStmt::PrintType, exprVect );
+}
+
+LangVarRef *Bootstrap2::walkVarRef( var_ref &varRef )
+{
+ QualItemVect *qual = new QualItemVect;
+ String id = varRef.Id().text().c_str();
+ LangVarRef *langVarRef = LangVarRef::cons( internal, qual, id );
+ return langVarRef;
}
-void Bootstrap2::walkExprStmt( expr_stmt &exprStmt )
+LangExpr *Bootstrap2::walkCodeExpr( code_expr &codeExpr )
{
- std::cerr << "expr statement: " << exprStmt.text() << std::endl;
+ LangExpr *expr = 0;
+ if ( codeExpr.VarRef() != 0 ) {
+ var_ref varRef = codeExpr.VarRef();
+ LangVarRef *langVarRef = walkVarRef( varRef );
+ LangTerm *term = LangTerm::cons( internal, LangTerm::VarRefType, langVarRef );
+ expr = LangExpr::cons( term );
+ }
+ else if ( codeExpr.Lit() != 0 ) {
+ String lit = codeExpr.Lit().text().c_str();
+ LangTerm *term = LangTerm::cons( internal, LangTerm::StringType, lit );
+ expr = LangExpr::cons( term );
+ }
+ return expr;
+}
+
+LangStmt *Bootstrap2::walkExprStmt( expr_stmt &exprStmt )
+{
+ LangStmt *stmt;
+ if ( exprStmt.CodeExpr() != 0 ) {
+ code_expr codeExpr = exprStmt.CodeExpr();
+ LangExpr *expr = walkCodeExpr( codeExpr );
+ stmt = LangStmt::cons( internal, LangStmt::ExprType, expr );
+ }
+ return stmt;
}
-void Bootstrap2::walkStatement( statement &Statement )
+LangStmt *Bootstrap2::walkStatement( statement &Statement )
{
+ LangStmt *stmt;
if ( Statement.Print() != 0 ) {
print_stmt printStmt = Statement.Print();
- walkPrintStmt( printStmt );
+ stmt = walkPrintStmt( printStmt );
}
else if ( Statement.Expr() != 0 ) {
expr_stmt exprStmt = Statement.Expr();
- walkExprStmt( exprStmt );
+ stmt = walkExprStmt( exprStmt );
}
+ return stmt;
}
void Bootstrap2::go()
@@ -293,7 +342,8 @@ void Bootstrap2::go()
}
else if ( rootItem.Statement() != 0 ) {
statement Statement = rootItem.Statement();
- walkStatement( Statement );
+ LangStmt *stmt = walkStatement( Statement );
+ stmtList->append( stmt );
}
rootItemList = rootItemList.next();
diff --git a/colm/bootstrap2.h b/colm/bootstrap2.h
index 3621c43a..07bb65b8 100644
--- a/colm/bootstrap2.h
+++ b/colm/bootstrap2.h
@@ -38,6 +38,9 @@ struct cfl_def;
struct statement;
struct print_stmt;
struct expr_stmt;
+struct var_ref;
+struct code_expr;
+struct _repeat_code_expr;
struct Bootstrap2
:
@@ -55,13 +58,16 @@ struct Bootstrap2
LexFactorAug *walkLexFactorAug( lex_factor_rep &LexFactorRepTree );
LexTerm *walkLexTerm( lex_term &LexTerm );
LexExpression *walkLexExpr( lex_expr &LexExpr );
+ ExprVect *walkCodeExprList( _repeat_code_expr &codeExprList );
+ LangExpr *walkCodeExpr( code_expr &codeExpr );
void walkTokenList( token_list &TokenList );
void walkLexRegion( region_def &regionDef );
void walkProdElList( ProdElList *list, prod_el_list &ProdElList );
void walkProdList( LelDefList *lelDefList, prod_list &ProdList );
void walkCflDef( cfl_def &cflDef );
- void walkStatement( statement &Statement );
- void walkPrintStmt( print_stmt &PrintStmt );
- void walkExprStmt( expr_stmt &ExprStmt );
+ LangStmt *walkStatement( statement &Statement );
+ LangStmt *walkPrintStmt( print_stmt &PrintStmt );
+ LangStmt *walkExprStmt( expr_stmt &ExprStmt );
+ LangVarRef *walkVarRef( var_ref &varRef );
void go();
};
diff --git a/colm/colm.lm b/colm/colm.lm
index 2f75099a..2a992c6d 100644
--- a/colm/colm.lm
+++ b/colm/colm.lm
@@ -107,10 +107,11 @@ def expr_stmt
[CodeExpr: code_expr]
def code_expr
- [var_ref]
+ [VarRef: var_ref]
+| [Lit: lit]
def var_ref
- [id]
+ [Id: id]
def lex_expr
[Expr: lex_expr BAR Term: lex_term]